ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
I have been trying to communicate with device trhough /dev/ttyS0.
The device sends out data as soon as it powers up but the read just gets stuck and I cant proceed any further. After the initial startup data from the device, commands can be sent to it to control it. I can send one command to it successfully but after that I cant control the device.
Could the serial port be blocked by the kernel for some reason or is my code itself wrong. I have posted the code below and I would be grateful for any help regarding this.
printf("%s","error in setting up device\n\n");
printf("%s","trying to read");
bytes=fcntl(fd,F_SETFL,FNDELAY); //to avoid serial port blocking
res=read(fd,buff,100); //trying to read initial setup data-not working
n=write(fd,"debug d 35 5 0\r",1000); //writing command to WSS
The state of your new struct termios, nw, is indeterminate. Try zeroing it before setting bits and bytes.
You probably want to set VMIN & VTIME in the termios, since you are using raw mode. See the Serial Programming Howto, especially the section named 'Non-Canonical Input Processing'. It is hard to predict the right settings for your application without knowing more about the data. The essential problem, as I see it, is that you are going to have to read iteratively, and accumulate and/or parse data as it arrives, since raw mode input cannot know how to break up the input stream in a way that is suitable for your application.