PHP Classes

PHP-serial - mac osx

Recommend this page to a friend!

      PHP Serial  >  All threads  >  PHP-serial - mac osx  >  (Un) Subscribe thread alerts  
Subject:PHP-serial - mac osx
Summary:sending/receiving/testing values from PHP on OS-X to a PLC
Messages:2
Author:Paul Godard
Date:2009-03-31 16:33:23
Update:2009-05-08 15:49:06
 

  1. PHP-serial - mac osx   Reply   Report abuse  
Picture of Paul Godard Paul Godard - 2009-03-31 16:33:23
Hi

First of all, I know nothing about serial communication. However I know enough about php to write a small programme in PHP to upload a series of values (high and low words) into 10000 registers available in a PLC.

I want to ask about the very basics of communication.

I have downloaded the Mac version of PHP-serial and I connect the PLC to my Mac Book Pro via a Sunix serial-USB. This works fine.

Where I am lost is in the communication process. Ideally I would like to send a serial string and then test if it was received correctly (compare with what I have sent) before sending the other serial strings. How do I do that? Is this necessary?

With the following programme, this is what I get when the PLC is powered and when it is not (only the read values are missing but the write function does not even return an error???).

Can anybody help?

Results when PLC on
----------------

/dev/tty.usbserial is set-up
baud rate set to 9600 [OK]
parity set to none [OK]
character length set to 8 [OK]
stop bits set to 1 [OK]
flow control set to rts/cts [OK]
port is open
send serial command :651043:0 [OK]
read serial string :=2FF000:00FFB1
send serial command :651043:1 [OK]
read serial string :
send serial command :203201:3 [OK]
read serial string :
send serial command :20E002:000D2F0D [OK]
read serial string :=2FF000:00FFB1
send serial command :604000:1F [OK]
read serial string :
send serial command :?606400 [OK]
read serial string :
read serial string :
port is close


Results when PLC off
----------------

/dev/tty.usbserial is set-up
baud rate set to 9600 [OK]
parity set to none [OK]
character length set to 8 [OK]
stop bits set to 1 [OK]
flow control set to rts/cts [OK]
port is open
send serial command :651043:0 [OK]
read serial string :
send serial command :651043:1 [OK]
read serial string :
send serial command :203201:3 [OK]
read serial string :
send serial command :20E002:000D2F0D [OK]
read serial string :
send serial command :604000:1F [OK]
read serial string :
send serial command :?606400 [OK]
read serial string :
port is close


Programme
---------

include "php_serial.class.php";

$BaudRate = 9600;
$Parity = "none";
$CharacterLength = 8;
$StopBits = 1;
$FlowControl = "rts/cts";
$SerialString = array("651043:0","651043:1","203201:3","20E002:000D2F0D","604000:1F","?606400");

// start the class
$serial = new phpSerial;

// set-up serial port
$serial->deviceSet("/dev/tty.usbserial");
echo "/dev/tty.usbserial is set-up";
echo "<br />";

// change the baud rate (device must be closed)
$Result = $serial->confBaudRate($BaudRate);
echo "baud rate set to ".$BaudRate.DisplayResult($Result);
echo "<br />";

// change the parity (device must be closed)
$Result = $serial->confParity($Parity);
echo "parity set to ".$Parity.DisplayResult($Result);
echo "<br />";

// change the character length (device must be closed)
$Result = $serial->confCharacterLength($CharacterLength);
echo "character length set to ".$CharacterLength.DisplayResult($Result);
echo "<br />";

// change the stop bits (device must be closed)
$Result = $serial->confStopBits($StopBits);
echo "stop bits set to ".$StopBits.DisplayResult($Result);
echo "<br />";

// change the flow control (device must be closed)
$Result = $serial->confFlowControl($FlowControl);
echo "flow control set to ".$FlowControl.DisplayResult($Result);
echo "<br />";

// open serial port
$serial->deviceOpen();
echo "port is open";
echo "<br />";

// write to serial port
for ($i=0;$i<count($SerialString);$i++) {
$Result = $serial->sendMessage($SerialString[$i]);
echo "send serial command :".$SerialString[$i]." [".$Result."]";
echo "<br />";
$ReadSerial = $serial->readPort();
echo "read serial string :".$ReadSerial;
echo "<br />";
}

// close serial port
$serial->deviceClose();
echo "port is close";
echo "<br />";

  2. Re: PHP-serial - mac osx   Reply   Report abuse  
Picture of johnnyoffline johnnyoffline - 2009-05-08 15:49:06 - In reply to message 1 from Paul Godard
I am having a similar problem, unable to read responses from my serial device via osx.

Were you ever able to figure this out?

Thanks!