LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-19-2005, 06:19 AM   #1
yony
LQ Newbie
 
Registered: Dec 2005
Posts: 2

Rep: Reputation: 0
connecting com2 (c++)


hi
i have to connect com2 to send,recive commands from a machine i have.
i success to send commands but not to listen to commands.
it run under linux(with c++).
the Parameters should be:
port :RS232
baud rate : 19200
data bits 8
parity none
stop bits 1
flow control none

the way i did it is :

fd = open("/dev/ttyS1", O_RDWR | O_NOCTTY | O_NONBLOCK);
if (fd == -1) //Could not open the port.
return false;
fcntl(fd, F_SETFL, FASYNC);

struct termios options;
//Get the current options for the port...
tcgetattr(fd, &options);

//Set the baud rates to 19200...
cfsetispeed(&options, B19200);
cfsetospeed(&options, B19200);

//Enable the receiver and set local mode...

options.c_cflag |= (CLOCAL | CREAD);

//Set the new options for the port...
options.c_cflag &= ~CSIZE; /* Mask the character size bits */
options.c_cflag |= CS8; /* Select 8 data bits */

options.c_cflag &= ~PARENB;
options.c_cflag &= ~CSTOPB;

options.c_cflag &= ~CRTSCTS;
options.c_lflag |= (ICANON | ECHO | ECHOE);
options.c_iflag &= ~(IXON | IXOFF | IXANY);
tcsetattr(fd, TCSANOW, &options);

and to write something like
write(fd, "abcdefg\r", 8);
and it works
but to read i tried and cant do it
what the problem?
may be i gave wrong flags to the parameters i need ?
how should i read data.
thanks.
 
Old 12-19-2005, 10:36 AM   #2
FLLinux
Member
 
Registered: Jul 2004
Location: USA
Distribution: Fedora 9, LFS 6.3, Unbuntu 8.04, Slax 6.0.7
Posts: 145

Rep: Reputation: 15
What does the program do when you try and read from the port? Could you post the read code.
 
Old 12-20-2005, 05:55 AM   #3
yony
LQ Newbie
 
Registered: Dec 2005
Posts: 2

Original Poster
Rep: Reputation: 0
ok i did it.
i had in some place from some resion Cin.ignore
that called by a thread (onRun)every few micro seconds.
and it just change my input
i wrote the code on old code and didnt see it.
thanks any way
this "small" problem took me all day, but atleat i found it.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Digikam connecting as root/not connecting as regular user jayhel Slackware 5 09-29-2005 05:57 PM
About connecting myself to the n/w savimonty Linux - Networking 2 04-23-2005 05:36 AM
Help with connecting to AP farmerjoe Linux - Wireless Networking 10 01-24-2005 12:34 PM
Mysql is not connecting from servlet.But connecting from java, help pls Harish_f Linux - General 0 05-08-2002 03:21 AM
connecting chens_83 Linux - Newbie 1 12-29-2001 12:34 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:23 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration