In Linux usb-serial converters usually show up as a node in the /dev directory: /dev/ttyUSBx.
To use the serial converter the first step it to open the port, then configure it and so on.
port = open("/dev/ttyUSB0", O_RDWR);
If you want to use a serial device (I2C or SPI), ftdi offers devices (like FT4232 or FT232h) which can be used either as a normal UART port or i2c/spi.
For i2c/spi operation you have to use a separate driver - I use the open source libmpsse. This is a library you have to install so it will work in parallel with the standard FTDI driver since it's build on top of that.
So now, if I want o open a port as UART I use the normal open function (mentioned above). And if I want to connect a i2c/spi device I use the libmpsse open function which opens the port based on VID/PID:
struct mpsse_context *Open(int vid, int pid, enum modes mode, int freq, int endianess, int interface, const char *description, const char *serial)
Now for the question - can I open the port as UART by using the device vid/pid instead of the path to it's dev mode? It all comes down to ftdi function calls but I can't seem to find an example.
Why I need to do it this way? I don't want to have to know the node path. I should be able to use just the VID/PID and interface number - it's a lot more flexible.
Any help is appreciated!
/dev/serial/by-id
you will find links, named after your device, pointing to virtual file on/dev
. There is no vid/pid there, but the manufacturer and product name, but this is likely to be enough in most cases. – Gustavo VargasHKLM\SYSTEM\CurrentControlSet\Enum\USB
. CDC/ACM devices are likely to have afriendlyName
entrie that will be theCOMx
port associated to this device. – Gustavo Vargas