Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I configure and communicate with a serial port? [closed]

I need to send and receive data over serial connections (RS-232 and RS-422).

How do I set up and communicate with such a connection? How do I figure out what the configuration settings (e.g. baud rate) should be and how do I set them?

In particular I am looking to do this in Java, C/C++, or one of the major Unix shells but I also have some interest in serial programming using Windows/Hyperterminal.

like image 891
Greg Case Avatar asked Aug 06 '08 03:08

Greg Case


People also ask

How do you configure serial communication?

To configure the Serial Port for your device, on your computer go to Control Panel - Device Manager, select “High-Speed USB Serial Port (Com X)”, right click and select Properties. Click the Features tab. This tab is used to change the COM port number and configure the port.

How do I connect to serial COM port?

Open a console sessionUsing PuTTY or other terminal emulator, select "Serial" as the connection type and change the "Serial line" to match the COM port noted earlier. The serial console speed is typically 9600. Click "Open" to connect to the console.

How do I fix a serial port problem?

Go to Device Manager > Ports (COM & LPT) > mbed Serial Port, then right-click and select "properties". Choose "Port Settings" Tab, and click "Advanced" Under "COM Port Number", try selecting a different COM port. Unplug and replug the mbed to reload the driver - if the problem persists, try another COM port.


1 Answers

Build a time machine and go back to 1987? Ho ho.

Ok, no more snarky comments.

How do I figure out what the configuration settings (e.g. baud rate) should be...

Read the datasheet? Ok, ok. Seriously, last one. If you don't know the baud rate of the device you are trying to communicate with, you have two choices. Start guessing, or possibly bust out an o-scope. If you need a good starting point, let me suggest 9600-8-N-1. My suspicion is you can get there with brute force relatively quickly. There's a third option of having an old-school ninja who can tell just by the LOOK of the garbled characters at some standard baud rate what actual baud rate is. An impressive party trick to be sure.

Hopefully though you have access to this information. In unix/linux, you can get ahold of minicom to play with the serial port directly. This should make it fairly quick to get the configuration figured out.

one of the major Unix shells

In Unix the serial port(s) is/are file-mapped into the /dev/ subdir. ttyS0, for example. If you setup the correct baud rate and whatnot using minicom, you can even cat stuff to that file to send stuff out there.

On to the meat of the question, you can access it programmatically through the POSIX headers. termios.h is the big one.

See: http://www.easysw.com/~mike/serial/serial.html#3_1 (NOT AVAILABLE ANYMORE)

but I also have some interest in serial programming using Windows/Hyperterminal.

Hyperterminal and minicom are basically the same program. As for how Windows let's you get access to the serial port, I'll leave that question for someone else. I haven't done that in Windows since the Win95 days.

like image 142
Louis Brandy Avatar answered Sep 19 '22 01:09

Louis Brandy