7

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 Answer 1

8
#!/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.

Sign up to request clarification or add additional context in comments.

7 Comments

echo '2' > /dev/cu.usbserial-A700dYoR will send 50 as a single byte. If you really need to send an "integer", you have to discover what is an "integer" for the receiver (e.g. big or little endian, 7 or 8 byte stream, encoding).
basically, i'm trying to send something like writeByte(50), or any integer ranging from 0-255, to the serial port. can i specify the endian on the command line?
@TDI1978: If you're sending bytes individually, you may not need to worry about byte order. To send a decimal 50 byte in Bash: printf '%c' $'\x32' > /dev/cu.usbserial-A700dYoR
...or printf '%b' '\x32' > /dev/cu.usbserial-A700dYoR
what's the translation? i will be sending bytes whos value ranges from 0 to 255, so if 50 is equivalent to x32, how do i get that equivalency?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.