dio_read question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
EddieDee
Forum Newbie
Posts: 2
Joined: Wed Jan 10, 2007 10:12 pm

dio_read question

Post 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]
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post 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?
EddieDee
Forum Newbie
Posts: 2
Joined: Wed Jan 10, 2007 10:12 pm

Post 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
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Interesting. Glad you sorted it.
Post Reply