tbird20d / grabserial

Grabserial - python-based serial dump and timing program - good for embedded Linux development
GNU General Public License v2.0
195 stars 77 forks source link

Can't send command ending with \r\n #62

Closed huzeifa closed 2 years ago

huzeifa commented 2 years ago

Hi,

I am trying to send a command ending with \r\n , however it doesn't work.

my command: grabserial -d /dev/ttyUSB0 -b 2000000 -c adc\r

Some troubleshooting notes: I print the output of the command variable from line 681 of the grabserial code

if command:
            command += u"\n"
            print(command, end='')
            sd.write(command.encode("utf8"))
            sd.flush()

my output: adcr

It seems the \r character is not recognized

My temporary fix: add \r character together with \n character on line 681 to

if command:
            command += u"\r\n"
            sd.write(command.encode("utf8"))
            sd.flush()

Kindly advise if there are any other solutions for this

tbird20d commented 2 years ago

Very sorry about the very slow response. The problem is that the shell is not sending the \r as part of the argument.

You should be able to do this: grabserial -d /dev/ttyUSB0 -b 2000000 -c $'adc\r'

The extra $'...' should work in bash, and may work in other shells. It causes the shell to treat argument as a string to be literally printed. If you are calling this from a shell script, you can check which shell the script uses, and adjust that, if needed.

Or, this should work in most shell scripts: grabserial -d /dev/ttyUSB0 -b 2000000 -c $(printf 'adc\r')

Sorry again that this took me so long to get to. Ultimately, this is not an issue with grabserial, but with the calling environment, so I'm closing this.