Re: Serial Communication

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ulrik Witschass wrote:

Hello List,

I have managed to communicate with the serial device with the following
code:

'mode com1: BAUD=9600 PARITY=N data=8 stop=1 xon=n';		//the config the
device needs

$fp = fopen("COM1:", "rb+");		//also tried only "r+" here
if(!$fp) die();

$query = chr(59).chr(32)."0".chr(13).chr(10);

fputs($fp, $query);

$reply = fgets($fp, 32);

print($reply);


This works, the "0"-command requests the ID of the device and the reply I get in $reply is exactly what it should be. The problem:

it takes around 5 seconds until this reply is there, I tried different
lengths to buffer in fgets, tried fgetc, fread, everything, always the same.
It can't be the device blocking it, because if I send a couple of commands
(to position the devices measurement head) it reacts to all of these
commands in lightning speed, so I don't think it is the device slowing the
thing down, BUT what could it be? Does anybody have any experience with
this??? Basically, fread/fgets/fgetc just hangs the PHP core for several
seconds, with 0-1% CPU load...something just stalls PHP for this peroid of
time.

If this is an internal problem of PHP: does anybody know a source where I
can find some hints on how to communicate with the serial port over the COM
implementation of php-win? Googling for "com serial port php" is a bit
troublesom, since "com" in this case finds dozens of sites where com refers
to "com1" and not the COM system of Win32.

Any help is greatly appreciated!

best regards

Ulrik
You could try the same thing using windows' HyperTerminal. Connecting trough it and sending the same commands, and check if it takes as long aswell. That way you can rule out at least half of the possible problems (are they windows/COM related or PHP related). Basically, last time I tried something similair, I noticed my system "freezing" for a few secs on sending the first command. But this was with a faulty cable, so I'm not sure if that means anything...

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux