How to solve serial programming garbled characters in C ++ in linux

Source: Internet
Author: User
Linux C ++ serial programming garbled solution-general Linux technology-Linux programming and kernel information. The following is a detailed description. This is a module for serial communication. Garbled characters are found, but minicom is normal. At that time, the solution was to use termios to solve this problem, because the interface must be used for read and write operations, which is quite troublesome. At that time, I also implemented a serial operation class to facilitate operations.

After these steps are completed, we often find garbled characters. Then you can view the serial port support features of the device. This device is 9600bps, but can automatically identify the speed and increase the speed. It also supports many features. Therefore, garbled characters are irrelevant to the speed setting. In the program, no traffic control method is found. At that time, a hardware traffic control was unavailable. Finally, after some searches. The final method is exceptionally simple. Run "stty crtscts </dev/ttyS1" on the command line. I am using a USB to serial port device, so it is "stty crtscts </dev/ttyUSB0 ". You can control the hardware traffic ...... My devices support hardware traffic control. Then you can use the normal file read/write method. Very simple. Note: Two devices should be used. One is defined as tin using ifstream, and the other is defined as tout or similar names using ofstream. Then, use the corresponding function to perform the operation. You can use it as a standard input/output port. Another tool is setserial. This is said to be used to set the baud rate and verify something. If you are interested, try it. I cannot use it. In this case, you can set the serial port in linux and then operate it as a file. You do not need to use serial ports. However, advanced application estimation can still be used.

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.