What are the serial Programming Problems in linux ???
Source: Internet
Author: User
What are the serial Programming Problems in linux ??? -- Linux general technology-Linux programming and kernel information. The following is a detailed description. In recent days, I learned serial programming and wrote code according to the tutorial in the book. During the test, it was okay to send data to the serial port through the write function (I have two comports on my machine, the system is XP, and virtualora 10 is installed with VirtualBox, and the data sent by fedora is received through the XP Terminal Service). However, when I use the read function to receive data, only garbled characters are received, and there is no waiting. As long as a compiled document is executed, the code runs directly and a garbled string is returned. I really don't understand what is going on here. I posted the code. Please help me to see if I was wrong. Thank you.
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
Int fd;
Struct termio
{
Unsigned short c_iflag;
Unsigned short c_oflag;
Unsigned short c_cflag;
Unsigned short c_lflag;
Unsigned char c_line;
Unsigned char c_cc [NCCS];
};
Int open_port (int comport)
{
If (comport = 1)
{
Fd = open ("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY );
If (fd =-1)
{
Perror ("Can't Open Serial Port ");
Return (-1 );
}
}
Else if (comport = 2)
{
Fd = open ("/dev/ttyS1", O_RDWR | O_NOCTTY | O_NDELAY );
If (fd =-1)
{
Perror ("Can't Open Serial Port ");
Return (-1 );
}
}
Else if (comport = 3)
{
Fd = open ("/dev/ttyS2", O_RDWR | O_NOCTTY | O_NDELAY );
If (fd =-1)
{
Perror ("Can't Open Serial Port ");
Return (-1 );
}
}
If (fcntl (fd, F_SETFL, 0) <0)
Printf ("fcntl failed! \ N ");
Else
Printf ("fcntl = % d \ n", fcntl (fd, F_SETFL, 0 ));
If (isatty (STDIN_FILENO) = 0)
Printf ("standard input is not a terminal device \ n ");
Else
Printf ("isatty success! \ N ");
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.