LINUX serial port debugging tips

Source: Internet
Author: User

Connect the two serial ports with crossover lines. Assume that the two serial ports are/dev/ttys0 and/dev/ttys1 respectively, you can directly execute Cat/dev/ttys0 in a shell, then execute echo "test. ">/dev/ttys1. If both serial ports are good, executing CAT/dev/ttys0 will output 'test. "If not, you can use CAT/proc/interrupts to check whether there is any interruption. You can also use setserial to check the serial port settings.

Summary of some methods for debugging the serial port Program

Recently, I am working on a program for sending data through serial ports. Sometimes I write data at home in the office. In the office, the serial port is used to connect two computers to debug the serial port program. Because there are many computers, we can connect them with a single line, and send and receive data from this side. In XP, we can use the serial port debugging Assistant, which is very convenient. It's not that easy to get home. I used to have only one notebook, but now I have one more desktop. Although there are too many machines, it is not convenient to forget to bring the string line back. My program is Linux qtembedded. I have used several other methods to debug serial data sending. Here is a brief summary.
1. Stand-alone. Use ln-s output/dev/ttysac2 to connect the serial port ttysac2 used in the program to a file. After writing the data, use xxd to open the file and check the hexadecimal output. The disadvantage is that the results are slow and the advantage is the simplest. Xxd is a hexadecimal tool for Linux Command Line viewing. It can be called in VI or directly in command line.
2. Two machines are connected, and the desktop sends data to the notebook. At that time, I did not know the qtserialport-terminal mentioned below. Open a terminal in the notebook and use CAT/dev/ttyusb0 | xxd to output the received data. You can also directly view the hexadecimal output. However, it seems that the cache is available by default, not the data sent every time can be displayed in a timely manner.
3. The method found today. Set enable SerialPort in XP installed in virtualbox and select host device,/dev/ttys0. However, the serial port cannot be found after startup. manually add one, irq4, 3f8, and com3. (Show that COM1 is used, do not know the original cause) then open the serial port debugging assistant, run the program in the host Linux, and send data to/dev/ttys0; in XP, you can use the serial port debugging assistant to receive the data. In this way, you do not need to connect to the server. One machine can debug and immediately see the accepted data. This is also a good method.
In addition, in the Aur of archlinux, there is a qtserialport-terminal implemented using QT and qextserialport and multithreading, which is similar to the serial assistant. However, it is not displayed in hexadecimal notation. ttyusb cannot be used by default, but many character encoding types can be selected. If you have time, you can change it by adding the hexadecimal mode and USB serial port. By looking at the source code of this program, you can easily write multi-threaded serial port programs.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.