0
votes

I've got an USB card reader that I need to access from Lazarus / Delphi.

The SDK is written in VB6 and talks to the serial port, so in Windows it installs a driver to map the USB port to a serial port.

I'd like to skip that step (eg so that the same code works in Linux), but I'm not very familiar with the USB protocol, so I don't know how it maps to the serial one.

The VB6 code sends each character individually (serial, so to say), while the USB interface allows to send streams of data.

Should I still send byte by byte, or just concat the commands and send it in one go? Or is the concept completely different anyway?

2

2 Answers

1
votes

The USB protocol is completely different from a serial port. It sounds like the easiest approach for you might be to install a suitable USB-serial driver on Linux, and use the same serial protocol. Chances are there already exists such a driver that works with your device.

1
votes

If the USB device is a CDC then Linux will automagically detect it as a serial communications device.

In this case you can just open the /dev/ttyACM0 (or whatever) and read/write to it.

Either way: If the USB device is detected by Linux as a serial communications device, just open it (via /dev/) and treat it like you do your serial devices (except you don't have to worry about configuring baud rates).

And there is no reason why your Delphi code should send data to your serial device "character at a time" - you should be able to write entire packets in Delphi, too. That's what I used to do when I controlled PTZ (Pan-tilt-zoom) dome cameras via serial ports.

If the device is not detected as a serial port in Linux, you might be able to get away with just opening the installed /dev/ device and accessing it using standard file I/O (read()/write()). Again, write entire commands at a time.