As usual, post your PC code and PIC code here, it will be easier to see what could be the problem
As usual, post your PC code and PIC code here, it will be easier to see what could be the problem
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Hi,
all the project files are attached,
This is the pic code:
define OSC 20 ' Osc is 20MHz
DEFINE LOADER_USED 1 ' Bootlader if used
DEFINE RESET_ORG 800h ' For Microchip USB Bootloader
DEFINE INTERRUPT_ORG 808h ' For Microchip USB Bootloader
USBBufferSizeMax con 8 ' maximum buffer size
USBBufferSizeTX con 8 ' input
USBBufferSizeRX con 8 ' output
' the USB buffer...
USBBuffer Var Byte[USBBufferSizeMax]
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...
usbbuffer[0] = $00
usbbuffer[1] = $01
usbbuffer[2] = $0f
usbbuffer[3] = $ff
ProgramStart:
gosub DoUSBIn
toggle portc.0
if usbbuffer[2] = 0 then
toggle portc.1
endif
gosub DoUSBOut
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
The portc.1 is changed no matter what I send ==> the buffer = 0, but why?
*********************************************
The Visual basic code:
' 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)
Dim BufferOut(0 To BufferOutSize)
Private Sub find_Click()
hidConnect (Me.hwnd)
DeviceHandle = hidGetHandle(VendorID, ProductID)
did = hidGetVendorID(DeviceHandle)
pid = hidGetProductID(DeviceHandle)
InLng = hidGetInputReportLength(DeviceHandle)
OutLng = hidGetOutputReportLength(DeviceHandle)
hidSetReadNotify DeviceHandle, True
If DeviceHandle = 0 Then
Text1.Text = "Not FOUND"
Else
Text1.Text = "FOUND" & vbCrLf 'display data of the pic
Text1.Text = Text1.Text & did & vbCrLf
Text1.Text = Text1.Text & pid & vbCrLf
Text1.Text = Text1.Text & InLng & vbCrLf
Text1.Text = Text1.Text & OutLng & vbCrLf
End If
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)
' DeviceHandle = hidGetHandle(VendorID, ProductID)
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)
' read the data (don't forget, pass the whole array)...
' ** YOUR CODE HERE **
' first byte is the report ID, e.g. BufferIn(0)
' the other bytes are the data from the microcontrolller...
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
Private Sub trans_Click()
'send data
DeviceHandle = hidGetHandle(VendorID, ProductID)
If Option1 = 0 Then
BufferOut(0) = 0 ' first by is always the report ID
BufferOut(1) = &HFF
BufferOut(2) = &HFF
BufferOut(3) = &HFF
BufferOut(4) = &HFF
BufferOut(5) = &HFF
BufferOut(6) = &HFF
BufferOut(7) = &HFF
BufferOut(8) = &HFF
Else
BufferOut(0) = 0 ' first by is always the report ID
BufferOut(1) = &H0
BufferOut(2) = &H0
BufferOut(3) = &H0
BufferOut(4) = &H0
BufferOut(5) = &H0
BufferOut(6) = &H0
BufferOut(7) = &H0
BufferOut(8) = &H0
End If
' write the data (don't forget, pass the whole array)...
sendsecc = hidWrite(DeviceHandle, BufferOut(0))
'sendsecc = hidWriteEx(VendorID, ProductID, BufferOut(0))
If sendsecc = 0 Then
Text2.Text = "no send" & vbCrLf
Else
Text2.Text = "send" & vbCrLf
Text2.Text = Text2.Text & BufferOut(0) & vbCrLf
Text2.Text = Text2.Text & BufferOut(1) & vbCrLf
Text2.Text = Text2.Text & BufferOut(2) & vbCrLf
Text2.Text = Text2.Text & BufferOut(3) & vbCrLf
Text2.Text = Text2.Text & BufferOut(4) & vbCrLf
Text2.Text = Text2.Text & BufferOut(5) & vbCrLf
Text2.Text = Text2.Text & BufferOut(6) & vbCrLf
Text2.Text = Text2.Text & BufferOut(7) & vbCrLf
Text2.Text = Text2.Text & BufferOut(8) & vbCrLf
End If
readseccs = 0
' read the data (don't forget, pass the whole array)...
readseccs = hidReadEx(VendorID, ProductID, BufferIn(0))
If readseccs = 0 Then
Text3.Text = "no read"
Else
Text3.Text = "read" & vbCrLf
Text3.Text = Text3.Text & "data" & vbCrLf
Text3.Text = Text3.Text & BufferIn(0) & vbCrLf
Text3.Text = Text3.Text & BufferIn(1) & vbCrLf
Text3.Text = Text3.Text & BufferIn(2) & vbCrLf
Text3.Text = Text3.Text & BufferIn(3) & vbCrLf
Text3.Text = Text3.Text & BufferIn(4) & vbCrLf
Text3.Text = Text3.Text & BufferIn(5) & vbCrLf
Text3.Text = Text3.Text & BufferIn(6) & vbCrLf
Text3.Text = Text3.Text & BufferIn(7) & vbCrLf
Text3.Text = Text3.Text & BufferIn(8) & vbCrLf
End If
End Sub
*****************************************
On the picture you can see the display, left to right:
1. the display as the program start.
2. the display after pressing "find f" - we see the P.id and Vid value and the size of the reports
3. What we send and what we get=0 after pressing "trans"
Thanks
Dose any one have a working HDI program using VB on the pc, so I can check my circute and lern from it ?
Thanks
Shamir
Shamir,
I see you have commented out the following line:
' ConnectToHID (Me.hwnd)
I assume you had the same error I have:
Sub or function not defined
I have copied MCHID.dll into the VB working folder and still get the same error (DLL copy suggested by Sean here):
http://www.picbasic.co.uk/forum/show...0&postcount=12
Robert
![]()
My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.
Not as dumb as yesterday, but stupider than tomorrow!
Uh, just pretend like I don't exist:
http://www.picbasic.co.uk/forum/show...19&postcount=4
Robert
![]()
My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.
Not as dumb as yesterday, but stupider than tomorrow!
Bookmarks