Page 1 of 1

dio_read question

Posted: Wed Jan 10, 2007 10:20 pm
by EddieDee
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I'm building a web page that will access a serial port to read and write data to a commercial product. I need to send queries out to the unit and it will return status information. Here's the code snippet I've used:

Code: Select all

$fd = dio_open("/dev/ttyS1", O_RDWR | O_NOCTTY | O_NONBLOCK); // open the port
dio_write($fd, "Q00"); // query port 00
$val = dio_read($fd); // put the value into $var
Machine is running PHP 4.3 on an Apache server. I know the write request is working, as I monitored the serial data and saw it send controls to the device. However, the returned value ($val) is always an empty string. Running 'minicom' and sending the same string always returns a proper value. Also, just for testing, I ran minicom and tried the same code - without the 'dio_read' portion. I sent the data to the device and minicom showed the proper status on the return.

Any ideas as to why dio_read is always blank? I tried removing the control and blocking options from the dio_open (just keeping the O_RDWR option) and that didn't change anything.

Eddie


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Fri Jan 12, 2007 10:11 am
by Ollie Saunders
Code wise this is so simple that the only place you could have gone wrong is the connection flags and you've already tried changing those so are you sure the device is actually sending the data?

Posted: Fri Jan 12, 2007 12:20 pm
by EddieDee
The device is working properly. And I found the problem. The code simply executed too fast! I put a "sleep(200000)" line between the write and the read and it's working perfectly now!

It's always something simple!

Eddie

Posted: Fri Jan 12, 2007 12:43 pm
by Ollie Saunders
Interesting. Glad you sorted it.