Hi, after some "tries and errors" i used the following components to have a working USB-communication between a PIC18F4550 and my PC:
- MikroC for the PIC
- HIDLIBRARY.DLL from Mike Obrian
- Visual Studio 2005
i had to fight a little bit with the documentation... but in the end the following code did the trick:
- Exchange data with my USB device:
Private Sub ReadInternalADC()
Dim InputData As HIDLibrary.HidDeviceData
Dim i As Integer
Dim OutputText As String
Dim uInput As Integer
'--> Enumerate the devices with the Vendor Id
'--> and Product Id of the DDS Stuff
HidDeviceList = HIDLibrary.HidDevices.Enumerate(&H1235, &H1)
If HidDeviceList.Length > 0 Then
HidDevice = HidDeviceList(0)
'--> Check if connected...
HidDevice.OpenDevice()
Dim OutData As Byte()
ReDim OutData(HidDevice.Capabilities.OutputReportByteLength - 1)
'--> Send a report to Device (8888888 is command to PIC to answer with data..)
OutData(1) = Asc("8")
OutData(2) = Asc("8")
OutData(3) = Asc("8")
OutData(4) = Asc("8")
OutData(5) = Asc("8")
OutData(6) = Asc("8")
OutData(7) = Asc("8")
OutData(
= Asc("8")
HidDevice.Write(OutData)
InputData = HidDevice.Read
OutputText = ""
For i = 1 To 5
OutputText = OutputText + Chr(InputData.Data(i))
Next
uInput = Int((Val(OutputText) * 4.7 / 1.024) + 0.5) ' convert Text answer (ADC) to Voltage
End If
End Sub
have fun!