1

I am trying to send a string to the Serial Comm Port /dev/ttyS0 . On a Windows machine I use Turbo Basic program which has been working for many years. I can send '*80' and it turns on a light on my remote Micro. I can send '*81' to turn it off and so on. How do I 'send' these strings in either 'C' or the 'bash' shell? I have added the user to the 'dialout' group so it can be run without having 'root' access.

The communication settings are 2400 N 8 1 and that has been set and flow control is off. That is what is required by the attached Micro.

  • 1
    Were any special settings required for the serial (bits, speed)? – thrig Feb 8 '17 at 22:42
3

If the serial port settings are correct, then it's as easy as

echo '*80' >/dev/ttyS0

provided that you have permission to write to the device file. If the device doesn't want a newline after the command, use echo -n '*80' >/dev/ttyS0.

If you need to change the serial port settings, you can use setserial. Or alternatively you can use one of the many programs that can interact with a serial port, for example

screen /dev/ttyS0 2400,cs8,-ixon,-ixoff

and then type *80, or use minicom or microcom or …

  • I tried echo '*80' > /dev/ttyS0 and nothing happened. Do I have to add something to the Kernel and how do I tell if the Comm port is setup in all ways to accept direct input such as '*80' > /dev/ttyS0 ? – robertdaleweir Feb 9 '17 at 19:03
  • @robertdaleweir Usually, if nothing happens, it's because the serial port settings are not the same on both ends. How did you set up the serial port on Linux? Try a program such as Screen that explicitly sets the serial port speed when it starts, or a program such as Minicom that has menus for this. – Gilles Feb 9 '17 at 19:18
0

Most Linux or BSD would have a minicom package available, which is the toolbox talking to serial devices.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.