ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have a small program which should be writing on to the serial port. I send a 'space' character and the device connected to the serial port returns '>' as an acknowledgement.
With the same setting(serial port settings of my program) if i try to send a space character with another readymade program i get an ackowledgement without any issue.
But somehow my writes are not reaching the device i believe. Is there anything that i need to flush?
I have put a sniffer(portmon) and watching whats happening and I see that it says 1 character written successfully, although this does not guarantee that it has reached the device properly because, even if the serial port cable is dangling without any connection to the extenral device, i get a message saying the write was successful.
Below is my program. Could anyone please let me know what am I doing wrong here?
#include<unistd.h>
#include<fcntl.h>
int main(void)
{
int fd=open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY);
fcntl(fd,F_SETFL,0);
unsigned char sim = 0x20;
write(fd,&sim,1);
char *bfr=new char[255];
read(fd,bfr,1);
}
As the write has not yet reached the device, the read continuosly blocks!!!
Any clue on whats hapening.
I am trying this on cygwin. But i tried this on red hat linux enterprise 4, with the same result. The strange part is, when i started out to write this program, it was working perfectly fine on cygwin, with data being sent and recvd, but when i started adding extra code to it(like setting serial attributes etc), at some point it broke down and its not recovering
can you not start commenting out you modifications until you get to the point where it starts working again,then go forward making small change at a time trying to pin point which line of new code breaks it.
Sorry only thing I can sugest
hey exvor..
thanks for the response...but this is c++, sorry i didnt tell u that before..
1) return statement is not necessary. cuz it compiled without issues.
2) dynamic allocation.
I felt the urge to respond back
There was nothing wrong with the program that I wrote to begin with. It seems the serial device that I am connecting to needs a wait period of 1.6milliseconds before it starts responding to my characters. I did not give a breathing 'space' to the poor guy.
Now things are fine. Thanks a lot for all your help.
hey exvor..
thanks for the response...but this is c++, sorry i didnt tell u that before..
1) return statement is not necessary. cuz it compiled without issues.
2) dynamic allocation.
slzckboy
i tried dat. no use. it still fails
randyding
i will take a peek at it.
Yea i figured it was some C++ crazyness :P but dident know if it was diffrent in that language.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.