
NUEVO BLOG YoReparo!
Nueva Base de Fallas - Videos!
Regístrate gratis para participar de los foros, o si ya estás registrado haz login.
| comentario del autor | Sab Abr 07, 2007 6:00 pm | |
|
Estoy realizando un programa que me adquiere data con el pic18f2550 y lo muestre en un picturebox en visual basic en el pc El programa funciona pero al momento de agregar código para salir del loop conversor (mediante un click en un boton de Pausa en visual), el pic me entrega un solo dato, es como si quedara esperando algo. Si alguien puede ayudarme desde ya le estoy eternamente agradecido. Aquí van los códigos en visual y pbp: -Código para visual: Dim res As Integer ' vendor and product IDs Private Const VendorID = 6017 Private Const ProductID = 2000 ' read and write buffers Private Const BufferInSize = 8 Private Const BufferOutSize = 8 Dim BufferIn(0 To BufferInSize) As Byte Dim BufferOut(0 To BufferOutSize) As Byte Dim x As Integer '-------------------------------------------------------- Private Sub cmd_Iniciar_Click() cmd_Iniciar.Enabled = False cmd_Pausa.Enabled = True BufferOut(5) = 2 'commando para adquirir hidWriteEx VendorID, ProductID, BufferOut(0) BufferOut(7) = Text3 'dato al puerto B hidWriteEx VendorID, ProductID, BufferOut(0) End Sub Private Sub cmd_Pausa_Click() cmd_Pausa.Enabled = False cmd_Iniciar.Enabled = True BufferOut(5) = 3 'commando para Pausa hidWriteEx VendorID, ProductID, BufferOut(0) End Sub Private Sub cmd_Salir_Click() 'botón para salir Unload Me 'End End Sub ' **************************************************************** ' when the form loads, connect to the HID controller - pass ' the form window handle so that you can receive notification ' events... '***************************************************************** Private Sub Form_Load() ' do not remove! ConnectToHID (Me.hwnd) cmd_Pausa.Enabled = False End Sub '***************************************************************** ' disconnect from the HID controller... '***************************************************************** Private Sub Form_Unload(Cancel As Integer) DisconnectFromHID End Sub '***************************************************************** ' a HID device has been plugged in... '***************************************************************** Public Sub OnPlugged(ByVal pHandle As Long) If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID Then ' ** YOUR CODE HERE ** End If End Sub '***************************************************************** ' a HID device has been unplugged... '***************************************************************** Public Sub OnUnplugged(ByVal pHandle As Long) If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID Then ' ** YOUR CODE HERE ** End If End Sub '***************************************************************** ' controller changed notification - called ' after ALL HID devices are plugged or unplugged '***************************************************************** Public Sub OnChanged() Dim DeviceHandle As Long ' get the handle of the device we are interested in, then set ' its read notify flag to true - this ensures you get a read ' notification message when there is some data to read... DeviceHandle = hidGetHandle(VendorID, ProductID) hidSetReadNotify DeviceHandle, True End Sub '***************************************************************** ' on read event... '***************************************************************** Public Sub OnRead(ByVal pHandle As Long) Dim y As Integer Dim j As Integer Dim k As Integer ' read the data (don't forget, pass the whole array)... If hidRead(pHandle, BufferIn(0)) Then ' ** YOUR CODE HERE ** Text1 = BufferIn(6) Text2 = x y = 3900 - (BufferIn(6) * 13) ' first byte is the report ID, e.g. BufferIn(0) ' the other bytes are the data from the microcontrolller... Picture1.Line -(x, y), RGB(0, 255, 0) If x < 10000 Then x = x + 5 'variando el incremento de x la señal se expande Else x = 0 Picture1.Cls End If End If End Sub '***************************************************************** ' this is how you write some data... '***************************************************************** Public Sub WriteSomeData() BufferOut(0) = 0 ' first by is always the report ID BufferOut(1) = 10 ' first data item, etc etc ' write the data (don't forget, pass the whole array)... hidWriteEx VendorID, ProductID, BufferOut(0) End Sub -Código para el PIC en pbp: '************************************************************************** '* Name : ADUISIDOR.BAS * '* Author : JUAN MENDOZA * '* Notice : Copyright (c) 2007 [select VIEW...EDITOR OPTIONS] * '* : All Rights Reserved * '* Date : 27-03-2007 * '* Version : * '* Notes :ESTE PROGRAMA ADQUIERE DATA DESDE EL PUERTO A DEL PIC * '* Y ENTREGA UN DATO AL PUERTO B ENVIADO POR EL PC AL MOMENTO * '* DE PRESIONAR EL BOTON INICIAR, PERO AL AGREGAR CÓDIGO PARA * '* SALIR DEL LOOP, ADQUIERE DATA SÓLO UNA VEZ PERO SALE DEL * '* LOOP AL HACER CLICK EN EL BOTÓN PAUSA DEL PROGRAMA EN VISUAL.* * '************************************************************************ * DEFINE OSC 48 USBBufferSizeMax con 8 ' maximum buffer size USBBufferSizeTX con 8 ' input USBBufferSizeRX con 8 ' output ' the USB buffer... USBBuffer Var Byte[USBBufferSizeMax] USBBufferCount Var Byte adval VAR BYTE TRISA = %11111111 ' Set PORTA to all input TRISB= 0 usbinit ' initialise USB... ProgramStart: gosub DoUSBIn 'subrutina de entrada de datos IF USBBUFFER[4]=2 THEN gosub DoUSBIn PORTB = USBBuffer[6] ADCON1 = %00000010 ' Set PORTA analog Pauseus 500 ' Wait .5 second usbservice 'mantiene conección viva LOOP: ADCIN 0, adval ' Read channel 0 to adval Pauseus 100 ' Wait .1 second USBBUFFER[5]= adval gosub DoUSBOut 'subrutina salida de dato ' código para detener o salir del loop '------------------------------------------------------------------------ gosub DoUSBIn 'OJO,ésta instrucción me causa problemas. 'si la quito logicamente con las dos 'que siguen, el programa funciona (en ese 'caso hay que habilitar el GOTO loop, 'pero queda en conversión infinita y necesito ' detenerla a voluntad. IF USBBUFFER[4]!=3 THEN LOOP goto programstart '------------------------------------------------------------------------ 'goto loop endif goto ProgramStart ' ************************************************************ ' * receive data from the USB bus * ' ************************************************************ DoUSBIn: USBBufferCount = USBBufferSizeRX ' RX buffer size USBService ' keep connection alive USBIn 1, USBBuffer, USBBufferCount, DoUSBIn ' read data, if available return ' ************************************************************ ' * wait for USB interface to attach * ' ************************************************************ DoUSBOut: USBBufferCount = USBBufferSizeTX ' TX buffer size USBService ' keep connection alive USBOut 1, USBBuffer, USBBufferCount, DoUSBOut ' if bus available, transmit data return Saludos y espero ayuda |
||
| sin valorar | Mar Abr 10, 2007 5:22 pm | |
|
Cualquier cosa pregunta, espero tu rta.- |
||
| comentario del autor | Mar Abr 17, 2007 2:28 pm | |
|
Lo del Text3 es simplemente unna caja de texto en visual en la que se introduce un dato entre 0 y 255 para que se transmita al PIC y se enciendan el o los leds(conectados al puerto B del PIC18F2550) correspondientes al dato transmitido ademàs del commando que se envìa al PIC para que empieze a transmitir datos al PC. Mi problema es que no puedo detener desde visual el envìo de data por parte del PIC. Con respecto a lo que quiero hacer principalmente es recibir data desde el PIC y visualizarla en el PC pero controlar adecuadamente el inicio y detenciòn de la tranamisiòn. Lo unico que tengo armado en una proto es el PIC y un 555 que me entrega pulsos que es la data que en estos momentos puedo graficar en el PC. Espero con estos datos ser mas claro y gracias por tu ayuda. Saludos |
||