I'm running a python code which is plugged with two serial ports, a huawei dongle and a zigbee. I understand that In order to find out which port the dongle is using I must use gammu. And the zigbee is always using dev/ttyUSB0. However, If I'm to auto run the Python script upon booting, how is the raspberry pi supposed to know which port is connected to which USB? And is there a way i could straight away run the code for sms without having to use gammu to find out the port?
1
votes
1 Answers
0
votes
If you are asking, "how can I tell if /dev/ttyUSB0 is the huawei dongle or the zigbee", then you can do the following for each device:
udevadm info --name /dev/ttyUSB0 --query property --export
For example, I have an ftdi serial port and the output for the command is:
DEVLINKS='/dev/serial/by-id/usb-FTDI_USB__-__Serial-if00-port0 /dev/serial/by-path/platform-bcm2708_usb-usb-0:1.2:1.0-port0'
DEVNAME='/dev/ttyUSB0'
DEVPATH='/devices/platform/bcm2708_usb/usb1/1-1/1-1.2/1-1.2:1.0/ttyUSB0/tty/ttyUSB0'
ID_BUS='usb'
ID_MODEL='USB__-__Serial'
ID_MODEL_ENC='USB\x20\x3c-\x3e\x20Serial'
ID_MODEL_FROM_DATABASE='FT232 USB-Serial (UART) IC'
ID_MODEL_ID='6001'
ID_PATH='platform-bcm2708_usb-usb-0:1.2:1.0'
ID_PATH_TAG='platform-bcm2708_usb-usb-0_1_2_1_0'
ID_REVISION='0400'
ID_SERIAL='FTDI_USB__-__Serial'
ID_TYPE='generic'
ID_USB_DRIVER='ftdi_sio'
ID_USB_INTERFACES=':ffffff:'
ID_USB_INTERFACE_NUM='00'
ID_VENDOR='FTDI'
ID_VENDOR_ENC='FTDI'
ID_VENDOR_FROM_DATABASE='Future Technology Devices International, Ltd'
ID_VENDOR_ID='0403'
MAJOR='188'
MINOR='0'
SUBSYSTEM='tty'
UDEV_LOG='3'
USEC_INITIALIZED='2247071814106'
There should be sufficient differences in the output for your two devices to be able to decide which is which, eg the ID_VENDOR of FTDI in this case. The ID_VENDOR_ID and ID_MODEL_ID of 0403 and 6001 correspond to what you can see in:
$ lsusb
...
Bus 001 Device 006: ID 0403:6001 Future Technology Devices International, Ltd FT232 USB-Serial (UART) IC
If your devices can be distinguished by ID_SERIAL you can find them in /dev/serial/by-id/
as a symbolic link to the appropriate ttyUSB*, eg for my ftdi:
/dev/serial/by-id/usb-FTDI_USB__-__Serial-if00-port0 -> ../../ttyUSB0
If you plug your device into the same usb port each time, you can find the appropriate ttyUSB as a symbolic link under /dev/serial/by-path/
, eg:
/dev/serial/by-path/platform-bcm2708_usb-usb-0:1.2:1.0-port0 -> ../../ttyUSB0