By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,124 Members | 953 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,124 IT Pros & Developers. It's quick & easy.

setting port in linux and windows

P: 2
I code a program which two computer communicate each other with serial port in cross platform but my program dont run cross platform but run linux to linux or windows to windows . I think my serial port settings arent the same.My settings:

WINDOWS:
DCB properties;
GetCommState(serialPort, &properties);

properties.Parity = NOPARITY;
properties.BaudRate=9600;
properties.ByteSize = 8;
properties.StopBits = ONESTOPBIT;

SetCommState(serialPort, &properties);

LINUX:

struct termios properties;

tcgetattr(serialPort, &properties);

properties.c_cflag = CS8|CREAD|B9600|CLOCAL;
properties.c_iflag = IGNBRK;
properties.c_oflag = 0;
properties.c_lflag = 0;
properties.c_cc[VMIN] = 1;
properties.c_cc[VTIME]= 0;

tcsetattr(serialPort, TCSANOW, &properties);
Dec 19 '06 #1
Share this Question
Share on Google+
4 Replies


Expert 100+
P: 1,510
code looks OK, possibly one side is using hardware handshaking and the other not.

Have a look at my serial code for windows and linux
http://www.geocities.com/horacespider/Serial_IO/
Dec 19 '06 #2

P: 2
thank you...I dont use hardware handshaking.....
Dec 20 '06 #3

Banfa
Expert Mod 5K+
P: 8,916
This line correct ?

properties.c_cflag = CS8|CREAD|B9600|CLOCAL;

Looking at the documentation online is says that the baud rates must be set using the functions cfsetospeed and cfsetispeed
Dec 20 '06 #4

Expert 100+
P: 1,510
This line correct ?

properties.c_cflag = CS8|CREAD|B9600|CLOCAL;

Looking at the documentation online is says that the baud rates must be set using the functions cfsetospeed and cfsetispeed
I have used the following in one of my programs
Expand|Select|Wrap|Line Numbers
  1.      struct termios newtio;
  2.       newtio.c_cflag = BAUD | CRTSCTS | DATABITS | STOPBITS | PARITYON | PARITY | CLOCAL | CREAD;
  3.       newtio.c_iflag = IGNPAR;
  4.       newtio.c_oflag = 0;
  5.       newtio.c_lflag = 0;       //ICANON;
  6.       newtio.c_cc[VMIN]=1;
  7.       newtio.c_cc[VTIME]=0;
  8.       tcflush(fd, TCIFLUSH);
  9.       tcsetattr(fd,TCSANOW,&newtio);
  10.  
where BAUD is B9600, DATABITS is CS8, etc
Dec 20 '06 #5

Post your reply

Sign in to post your reply or Sign up for a free account.