Sending bytes to serial port from UNIX command lin

2019-05-04 11:44发布

问题:

i would like to send a stream of bytes to a serial port using the command line. is this possible? my serial port is at /dev/cu.usbserial-A700dYoR on my Mac. for example, if i wanted to send the integer 50 or the string "data" to that serial port, how can i do that?

my knowledge of UNIX is very limited.

回答1:

#!/bin/bash

# Port setting
stty -F /dev/cu.usbserial-A700dYoR raw speed 9600

echo 'Hello' > /dev/cu.usbserial-A700dYoR

or something like that if I remember correctly... Been a few years. You will probably have to be sudo for it to work...

This is sending text... not binary.. to send the number 50 as text

echo '50' > /dev/cu.usbserial-A700dYoR

to send it as a binary integer would be more difficult.