Garbled data on the read port! -- Linux general technology-Linux technology and application information. For details, refer to the following section. The following is my source program. During system debugging, we found that the first part of the characters we read was garbled, and the latter part was correct. Please give us some advice!
/*************************************** ****************************/
If (fd1 = open ("/dev/ttyS02", O_RDWR | O_NOCTTY | O_NDELAY) <0)/* open the serial port PortA */
Exit (0 );
/*************************************** ****************************/
/************************ Baud rate setting ************* *************/
Cfsetispeed (& option, B9600);/* set Port baud rate to 9600bps */
Cfsetospeed (& option, B9600 );
Tcsetattr (fd1, TCSANOW, & option );
/* Prevent serial port blocking */
MaxFd = fd1 + 1;
TV. TV _sec = 0;
TV. TV _usec = 500000;
/*********************** Enter the command/response loop ********* *******************/
While (1> 0)
{
/************************ Receive data from Port ********* ********************/
/* Communicate with the device */
Usleep (2000000 );
Retv1 = write (fd1, sbuf1, 4);/* Send Communication Request */
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