Andre_Pretorius
- 24th June 2010, 18:44
Can someone please assist me, i am trying to get a PIC18F4550 to talk to a VB application.
If i connect the pic the software detects the pic but no data comes through.
I have hard coded the data witch should be sended.
any advice on how to send data back to the PIC would also be appreciated
PIC Code
DEFINE OSC 48
DEFINE LOADER_USED 1
USBBufferSizeTX con 8 ' input
USBBufferSizeRX con 8 ' output
' the USB buffer...
USBBufferTX Var Byte[USBBufferSizeTX]
USBBufferRX Var Byte[USBBufferSizeRX]
USBBufferCount Var Byte
' ************************************************** **********
' * main program loop - remember, you must keep the USB *
' * connection alive with a call to USBService every couple *
' * of milliseconds or so... *
' ************************************************** **********
usbinit ' initialise USB...
ProgramStart:
USBBufferTX[0] = "1"
USBBufferTX[1] = "2"
USBBufferTX[2] = "3"
USBBufferTX[3] = "4"
USBBufferTX[4] = "5"
USBBufferTX[5] = "6"
USBBufferTX[6] = "7"
USBBufferTX[7] = "8"
gosub DoUSBIn
gosub DoUSBOut
goto ProgramStart
' ************************************************** **********
' * receive data from the USB bus *
' ************************************************** **********
DoUSBIn:
USBBufferCount = USBBufferSizeRX ' RX buffer size
USBService ' keep connection alive
USBIn 1, USBBufferRX, 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, USBBufferTX, USBBufferCount, DoUSBOut ' if bus available, transmit data
return
VB.NET code the form only contains textboxes and i use VB.NET2008
Option Strict Off
Option Explicit On
Friend Class MainForm
Inherits System.Windows.Forms.Form
' vendor and product IDs
Private Const VendorID As Short = 6017
Private Const ProductID As Short = 2000
' read and write buffers
Private Const BufferInSize As Short = 8
Private Const BufferOutSize As Short = 8
Dim BufferIn(BufferInSize) As Byte
Dim BufferOut(BufferOutSize) As Byte
' ************************************************** **************
' when the form loads, connect to the HID controller - pass
' the form window handle so that you can receive notification
' events...
'************************************************* ****************
Private Sub MainForm_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
' do not remove!
ConnectToHID(Me.Handle.ToInt32)
End Sub
'************************************************* ****************
' disconnect from the HID controller...
'************************************************* ****************
Private Sub MainForm_FormClosed(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
DisconnectFromHID()
End Sub
'************************************************* ****************
' a HID device has been plugged in...
'************************************************* ****************
Public Sub OnPlugged(ByVal pHandle As Integer)
If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID Then
' ** YOUR CODE HERE **
TextBox1.Text = "plugged"
End If
End Sub
'************************************************* ****************
' a HID device has been unplugged...
'************************************************* ****************
Public Sub OnUnplugged(ByVal pHandle As Integer)
If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID Then
hidSetReadNotify(hidGetHandle(VendorID, ProductID), False)
TextBox1.Text = "unplugged"
End If
End Sub
'************************************************* ****************
' controller changed notification - called
' after ALL HID devices are plugged or unplugged
'************************************************* ****************
Public Sub OnChanged()
' 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...
Dim pHandle As Integer
pHandle = hidGetHandle(VendorID, ProductID)
hidSetReadNotify(hidGetHandle(VendorID, ProductID), True)
End Sub
'************************************************* ****************
' on read event...
'************************************************* ****************
Public Sub OnRead(ByVal pHandle As Integer)
' read the data (don't forget, pass the whole array)...
If hidRead(pHandle, BufferIn(0)) Then
' ** YOUR CODE HERE **
' first byte is the report ID, e.g. BufferIn(0)
' the other bytes are the data from the microcontroller...
TextBox2.Text = BufferIn(0)
TextBox3.Text = BufferIn(1)
TextBox4.Text = BufferIn(2)
TextBox5.Text = BufferIn(3)
TextBox6.Text = BufferIn(4)
TextBox7.Text = BufferIn(5)
TextBox8.Text = BufferIn(6)
TextBox9.Text = BufferIn(7)
End If
End Sub
End Class
If i connect the pic the software detects the pic but no data comes through.
I have hard coded the data witch should be sended.
any advice on how to send data back to the PIC would also be appreciated
PIC Code
DEFINE OSC 48
DEFINE LOADER_USED 1
USBBufferSizeTX con 8 ' input
USBBufferSizeRX con 8 ' output
' the USB buffer...
USBBufferTX Var Byte[USBBufferSizeTX]
USBBufferRX Var Byte[USBBufferSizeRX]
USBBufferCount Var Byte
' ************************************************** **********
' * main program loop - remember, you must keep the USB *
' * connection alive with a call to USBService every couple *
' * of milliseconds or so... *
' ************************************************** **********
usbinit ' initialise USB...
ProgramStart:
USBBufferTX[0] = "1"
USBBufferTX[1] = "2"
USBBufferTX[2] = "3"
USBBufferTX[3] = "4"
USBBufferTX[4] = "5"
USBBufferTX[5] = "6"
USBBufferTX[6] = "7"
USBBufferTX[7] = "8"
gosub DoUSBIn
gosub DoUSBOut
goto ProgramStart
' ************************************************** **********
' * receive data from the USB bus *
' ************************************************** **********
DoUSBIn:
USBBufferCount = USBBufferSizeRX ' RX buffer size
USBService ' keep connection alive
USBIn 1, USBBufferRX, 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, USBBufferTX, USBBufferCount, DoUSBOut ' if bus available, transmit data
return
VB.NET code the form only contains textboxes and i use VB.NET2008
Option Strict Off
Option Explicit On
Friend Class MainForm
Inherits System.Windows.Forms.Form
' vendor and product IDs
Private Const VendorID As Short = 6017
Private Const ProductID As Short = 2000
' read and write buffers
Private Const BufferInSize As Short = 8
Private Const BufferOutSize As Short = 8
Dim BufferIn(BufferInSize) As Byte
Dim BufferOut(BufferOutSize) As Byte
' ************************************************** **************
' when the form loads, connect to the HID controller - pass
' the form window handle so that you can receive notification
' events...
'************************************************* ****************
Private Sub MainForm_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
' do not remove!
ConnectToHID(Me.Handle.ToInt32)
End Sub
'************************************************* ****************
' disconnect from the HID controller...
'************************************************* ****************
Private Sub MainForm_FormClosed(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
DisconnectFromHID()
End Sub
'************************************************* ****************
' a HID device has been plugged in...
'************************************************* ****************
Public Sub OnPlugged(ByVal pHandle As Integer)
If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID Then
' ** YOUR CODE HERE **
TextBox1.Text = "plugged"
End If
End Sub
'************************************************* ****************
' a HID device has been unplugged...
'************************************************* ****************
Public Sub OnUnplugged(ByVal pHandle As Integer)
If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID Then
hidSetReadNotify(hidGetHandle(VendorID, ProductID), False)
TextBox1.Text = "unplugged"
End If
End Sub
'************************************************* ****************
' controller changed notification - called
' after ALL HID devices are plugged or unplugged
'************************************************* ****************
Public Sub OnChanged()
' 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...
Dim pHandle As Integer
pHandle = hidGetHandle(VendorID, ProductID)
hidSetReadNotify(hidGetHandle(VendorID, ProductID), True)
End Sub
'************************************************* ****************
' on read event...
'************************************************* ****************
Public Sub OnRead(ByVal pHandle As Integer)
' read the data (don't forget, pass the whole array)...
If hidRead(pHandle, BufferIn(0)) Then
' ** YOUR CODE HERE **
' first byte is the report ID, e.g. BufferIn(0)
' the other bytes are the data from the microcontroller...
TextBox2.Text = BufferIn(0)
TextBox3.Text = BufferIn(1)
TextBox4.Text = BufferIn(2)
TextBox5.Text = BufferIn(3)
TextBox6.Text = BufferIn(4)
TextBox7.Text = BufferIn(5)
TextBox8.Text = BufferIn(6)
TextBox9.Text = BufferIn(7)
End If
End Sub
End Class