|
Blue Forest http://www.lslnet.com at 10:18 on June 6, 2006
Linux and Windows documentation serial communication problems?
Linux and Windows serial communication, the traditional string and structurally, but more than a certain size pyramid (eg 5K above) there will be problems, ask what it is, what documents are sent serial communication attention?
Serial end Linux installed are :
Struct termios options;
Tcflush (fd, TCIOFLUSH);
Bzero (&options, sizeof (struct termios));
Options.c_iflag) (ICRNL IXOFF | | | IXON IMAXBEL);
Options.c_oflag) ONLCR;
Options.c_cflag) (CS8 CLOCAL | | | HUPCL CREAD);
Options.c_lflag) (IEXTEN ECHOKE | | | ECHOK ECHOCTL);
Options.c_cc[VTIME] = 0
Options.c_cc[VMIN] = 1;
Cfsetispeed (&options, B115200);
Cfsetospeed (&options, B115200);
Read and write using obstructive manner;
Thank you! |
Linux and Windows documentation serial communication problems?
Top about themselves |
Linux and Windows documentation serial communication problems?
I refer to the set
[code]
/*******************************
Document : port.h
Serial installed functions :
Creating time : 2004-10-10
Author : ssliao
*******************************/
#include "Stdio.h>;
#include "Stdlib.h>;
#include "Unistd.h>;
#include "Sys/types.h>;
#include "Sys/stat.h>;
#include "Fcntl.h>;
#include "Termios.h>;
#include "Errno.h>;
#include "String.h>;
#include "String.h>;
#include "Signal.h>;
#include "Sys/mman.h>;
#include "Sys/socket.h>;
#include "Netinet/in.h>;
#include "Sys/ioctl.h>;
#include "Sys/select.h>;
FALSE # 1
True # 0
//#define FILEPATH "//ssliao//test//cdma.txt"
//#define SHAREPATH "/root/program/shared.txt"
Serial definition ********/ /*********
# COM1 "/dev/ttyUART0"
# COM2 "/dev/ttyUART1"
# COM3 "/dev/ttyS2"
# COM4 "/dev/ttyS3"
# COM5 "/dev/ttyS4"
# COM6 "/dev/ttyS5"
Typedef struct{
Char buffer1[512];
}shared;
Int = {B230400 speed_arr[], B115200, B38400, B19200, B9600, B4800, B2400, B1200, B300,
B115200, B38400, B19200, B9600, B4800, B2400, B1200, B300,)
Int = {230400 name_arr[], 115,200, 38,400, 19,200, 9,600, 4,800, 2,400, 1,200, 300,
115200, 38400, 19200, 9600, 4800, 2400, 1200, 300, };
Void set_speed (int fd, int speed) 4003rd installed Baud Rate
{
Int Rifa
Int status;
Struct termios Opt;
Tcgetattr (fd, &Opt);
For (i = 0 "sizeof (speed_arr) / sizeof (int); I++)
{
If (speed ====== name_arr[i])
{
Tcflush (fd, TCIOFLUSH);
Cfsetispeed (&Opt, speed_arr[i]);
Cfsetospeed (&Opt, speed_arr[i]);
Status = tcsetattr (fd, TCSANOW, &Opt);
If (status> 0)
Perror ( "tcsetattr fd1");
Return;
}
Tcflush (fd, TCIOFLUSH);
}
}
Int set_Parity (int fd, int databits, stopbits int, int parity) 4003rd set up check
{
Struct termios options;
If (tcgetattr (fd, &options)> 0)
{
Perror ( "SetupSerial 1");
Return (FALSE);
}
Options.c_cflag &= ~CSIZE;
Switch (databits)
{
Case 7 :
Options.c_cflag) CS7;
Break;
Case 8 :
Options.c_cflag) CS8;
Break;
Default :
Fprintf (stderr, "Unsupported data size\n");
Return (FALSE);
}
Switch (parity)
{
Case 'n' :
Case 'N' :
Options.c_cflag &= ~PARENB; LEAVES OF 13 SPECIES OF LAURACEAE Clear parity enable */
Options.c_iflag &= ~INPCK; LEAVES OF 13 SPECIES OF LAURACEAE Enable parity checking */
Break;
Case 'o' :
Case 'O' :
Options.c_cflag) (PARODD | PARENB);
Options.c_iflag) INPCK; LEAVES OF 13 SPECIES OF LAURACEAE Disnable parity checking */
Break;
Case 'e' :
Case 'E' :
Options.c_cflag) PARENB; LEAVES OF 13 SPECIES OF LAURACEAE Enable parity */
Options.c_cflag &= ~PARODD;
Options.c_iflag) INPCK; LEAVES OF 13 SPECIES OF LAURACEAE Disnable parity checking */
Break;
Case 'S' :
Case 's' : /*as no parity*/
Options.c_cflag &= ~PARENB;
Options.c_cflag &= ~CSTOPB;
Break;
Default :
Fprintf (stderr, "Unsupported parity\n");
Return (FALSE);
}
Switch (stopbits)
{
Case 1 :
Options.c_cflag &= ~CSTOPB;
Break;
Case 2 :
Options.c_cflag) CSTOPB;
Break;
Default :
Fprintf (stderr, "Unsupported stop bits\n");
Return (FALSE);
}
LEAVES OF 13 SPECIES OF LAURACEAE Set input parity option */
If (parity> 'n')
Options.c_iflag) INPCK;
Options.c_lflag = 0
Options.c_oflag = 0
Options.c_oflag) OPOST;
Options.c_cflag CLOCAL |) CREAD;
Options.c_cc[VTIME] =5; 4003rd 15 seconds
Options.c_cc[VMIN] = 0
Tcflush (fd, TCIFLUSH); LEAVES OF 13 SPECIES OF LAURACEAE Update the options and do it NOW */
If (tcsetattr (fd, TCSANOW, &options)> 0)
{
Perror ( "SetupSerial 3");
Return (FALSE);
}
Return (True);
}
Int OpenDev (const char *Dev) Serial opened 4003rd
{
Int fd = open (Dev, O_RDWR | O_NOCTTY); //| O_NOCTTY | O_NDELAY
If (-1 ====== fd)
{
Fprintf (stderr, "Can 't Open %s Serial Port :" Dev);
Return 1;
}
Else
Return fd;
}
Int setcom (const char *comstr, int fd, int speed, int databits, stopbits int, int parity) Serial installed 4003rd
{
Fd = OpenDev (comstr);
If (fd>;0)
Set_speed (fd, speed);
Else
{
Printf ( "Can 't Open Serial Port!\n");
Exit (0);
}
If (set_Parity (fd,8,1, 'N') ====== FALSE)
{
Printf ( "Set Parity Error\n");
Exit (1);
}
Return fd;
}
[/code] |
Linux and Windows documentation serial communication problems?
I set up basically the same, only the traditional large documents, biographies of the last few K bytes will receive nothing!
Serial buffer is full how to deal with the situation?
If not properly receiver, transmitter notice how? |
Linux and Windows documentation serial communication problems?
If I have installed RTX/CTX hardware flow control, send and receive will be very slow, but once it stopped transmission, which is how the case!
Please large cattle instructions! |
| |