[fpc-pascal] USB Human Interface Devices

James Richters james at productionautomation.net
Wed Aug 21 14:30:07 CEST 2019


I FINALLY wrote some data to the LCD!!   YAY !!!   I was trying to get the python application to work.. without any luck.. but I ended up going ahead and trying Zadig changing the driver to libusb-win32...  After I gave up on Python, I went back to FPC and just ran my existing sample program, and I noticed where it used have an error sending to device, it now said 8 bytes sent!!  It's very strange I could read it just fine but not write to it without messing with the driver... but it's working now!

I tried suspending the read thread to write to it.. and well it must have ended up suspending in the middle of a read because the whole thing locked up.. so I just tried as suggested and let it keep reading in a tight loop in it's own thread and then just throw in a write every few seconds on the main program.. and that actually worked fine.. I guess libusb takes care of worry about finishing a read before writing.. I think I did see libusb had something to do with threads.

So now it's just a matter of small details.     The display is a little odd... in that instead of sending it just a real number, you send it an integer for the numbers before the decimal and another integer for the numbers after the decimal.. but it's 2 bytes for each (4 bytes total)  but they are in reverse order.. I need to send LowByte_Integer, High_Byte_Integer, LowByte_decimal, High_Byte_decimal  so the bits from a 16 bit integer end up being 76543210,FEDCBA98  I think this is that edian byte order thing that was mentioned.  I'm just curious if there is already a function available to reverse these like this.. or if I just need to write my own.  It's just some rotates and then split it, so I can do that, but I'm just wondering if there is something already there to do this.. I seem to recall that this kind of thing needs to happen quite a bit.

Also I need to stick a $06 in front of all my packets to send to the device.  I have my data all in arrays,  so I want to do something like this 
Device_Array[0]:=$06;
Device_Array[1..7] := LCD_Array[0..6] ; 

Ah.. but that doesn't work.. is there a way to do this with syntax or do I just need to make a loop to copy the array elements the way they need to be?

James


More information about the fpc-pascal mailing list