Linux, Raspbian 8. USB USB-CAN converter is plugged into USB. Appears on the system as / dev / ttyUSB0

The converter itself and the device behind it are exactly working.

It is required to send 4 bytes to the port, wait 200ms and get a response of 4 bytes.

I tried it like this:

#!/bin/bash PORT="/dev/ttyUSB0" stty -F $PORT 9600 printf '\x0b\x00\x06\x80' > $PORT sleep 0.2 read -rn 4 data < $PORT echo $data 

On the read line, everything hangs. Apparently not receiving any data in response. Tried to change to 1 incoming character. But it seems in response to complete silence.

Am I working correctly with the port at all? Which way to dig?

UPDATE 10.03

something nahimichil

  1. Now all that I send to the port comes back. Exactly what I sent but not what I expect from the equipment

  2. another strange thing

     $ stty -F /dev/ttyUSB0 stty: /dev/ttyUSB0: Неприменимый к данному устройству ioctl $ setserial /dev/ttyUSB0 Cannot get serial info: Inappropriate ioctl for device 
  • one
    try to read one byte (to understand that something is coming to the port at all). or instead of read, run sudo cat /dev/ttyUSB0 in the adjacent terminal. - aleksandr barakin
  • yes, just try cat /dev/ttyUSB0 in one console and echo "something" > /dev/ttyUSB0 in the next console. Accordingly, is the string considered? - approximatenumber
  • And why not read immediately without sleep? - sercxjo
  • on equipment documentation. It says that the end of data reception is a pause in the transmission of at least 200 ms and the response transmission begins. I tried without a pause and with different pauses, both large and small. The result is the same. I have the impression that everything that I send to the port does not reach. - Marconi
  • The question was in the correct settings stty picked up the right ones, now everything works. Thanks to all. - Marconi

1 answer 1

To transfer binary data, the following port setting works for me:

 stty raw -echo -onlcr -iexten 9600 -F /dev/ttyUSB0 

For a usb serial converter, the device name after the next reconnection can sometimes unpredictably change from ttyUSB0 to ttyUSB1, ttyUSB2, etc.