Linux Serial Communication Program

/ Comments off

Communicate with Xilinx development boards via USB.

  1. Serial Communication Tutorial
  2. Linux Serial Communication Program For Kids

Serial Programming HOWTO Gary Frerking gary@frerking.org Peter Baumann Revision History Revision 1.01 2001−08−26 Revised by: glf New maintainer, converted to DocBook Revision 1.0 1998−01−22 Revised by: phb Initial document release This document describes how to program communications with devices over a serial port on a Linux box. Run stty again after using minicom, and you'll notice the settings are set to what the program was using. Minimal serial communication. Basically, two things are needed to have two-way communication through a serial port: 1) configuring the serial port, and 2) opening the pseudo-tty read-write.

Xilinx boards are equipped with Silabs devices as terminal communication, RS232, medium. To be able to talk to an application, such as a PicoBlaze 8-bit processor application, your Linux machine must have the appropriate Silabs drivers.Ubuntu 12.04LTS and later is default equipped with the Silabs drivers! No installation of drivers is necessary.The only thing necessary is to check whether the Ubuntu machine can communicate over USB with the attached Xilinx development board.

To do this:

Visit the download page to know more about changing advanced options.Once installed, you will see the Analyzed visualization entry under Visualizations (right-click on the WMP visualization area and then select visualizations).Analyzed is a free visualization plugin for x86 and x64 versions of Vista, Windows 7 and also Windows 8. Advanced users can change the background color, top color, bottom color, and peak color by editing the appropriate registry values. Windows media player visualizations install.

  • Connect the PC via an USB cable to the USB UART port of the Xilinx development board.
  • Turn the board on.

Open a terminal on you Ubuntu machine by pressing:

To find if the Silabs driver on the PC understood that a hardware device is connected, type:

The output text of this command in the terminal is something like this:

The last line, can be on your system another line, shows that the Silabs device on the Xilinx development board has been detected and that the drivers on the PC are running.

To find out what RS232 (UART) port is used by the USB driver, type:

The terminal return text looks like:

Again, on your machine the numbers might be different. The important line for us is that telling where the driver connects to a TTY port, in this case it is line three 'cp210x converter now attached to ttyUSB2'.


GTKterm

Setup the communication with a terminal window so that commands can be exchanged with the application running in the FPGA on the development board.

I'm using here GTKterm as an example but any other debug terminal program can be used.If GTKterm is not installed on you machine and you want to use it:

  • Open via the DASH (Unity) the Ubuntu Software Center.
  • Type in the search window (top right) GTKterm
  • While typing the screen will look as the figure below:


  • Install the Serial Port Terminal.
  • Now GTKterm is installed and available for use.Start it from the open terminal window as root.


  • Provide your sudo password and the serial terminal GUI will appear. Click 'Configuration' and select 'Port', as shown in the figure below.


  • In the pop-up window browse to the USB TTY port as shown in the figure below.
  • Set the speed, bits and party and start working/playing.
Retrieved from 'https://elinux.org/index.php?title=Communicate_with_hardware_using_USB_cable_for_Ubuntu&oldid=220442'
Active2 months ago

I am a little bit confused about reading and writing to a serial port. I have a USB device in Linux that uses the FTDI USB serial device converter driver. When I plug it in, it creates: /dev/ttyUSB1.

Serial Communication Tutorial

I thought itd be simple to open and read/write from it in C. I know the baud rate and parity information, but it seems like there is no standard for this?

Am I missing something, or can someone point me in the right direction?

gnychisgnychis
2,40013 gold badges60 silver badges93 bronze badges

2 Answers

I wrote this a long time ago (from years 1985-1992, with just a few tweaks since then), and just copy and paste the bits needed into each project.

Linux serial port communication

The values for speed are B115200, B230400, B9600, B19200, B38400, B57600, B1200, B2400, B4800, etc. The values for parity are 0 (meaning no parity), PARENB PARODD (enable parity and use odd), PARENB (enable parity and use even), PARENB PARODD CMSPAR (mark parity), and PARENB CMSPAR (space parity).

'Blocking' sets whether a read() on the port waits for the specified number of characters to arrive. Setting no blocking means that a read() returns however many characters are available without waiting for more, up to the buffer limit. Iso 9001 pdf.

Addendum:

CMSPAR is needed only for choosing mark and space parity, which is uncommon. For most applications, it can be omitted. My header file /usr/include/bits/termios.h enables definition of CMSPAR only if the preprocessor symbol __USE_MISC is defined. That definition occurs (in features.h) with

The introductory comments of <features.h> says:

Gabriel Staples
3,3553 gold badges21 silver badges49 bronze badges
wallykwallyk
50k10 gold badges68 silver badges125 bronze badges

For demo code that conforms to POSIX standard as described in Setting Terminal Modes Properlyand Serial Programming Guide for POSIX Operating Systems, the following is offered.
It's essentially derived from the other answer, but inaccurate and misleading comments have been corrected.

To make the program treat the received data as ASCII codes, compile the program with the symbol DISPLAY_STRING, e.g.

If the received data is ASCII text (rather than binary data) and you want to read it as lines terminated by the newline character, then see this answer for a sample program.

sawdustsawdust
11.3k1 gold badge27 silver badges40 bronze badges

protected by user405725 Jan 24 '13 at 20:53

Linux Serial Communication Program For Kids

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?

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