1
votes

I have this webpage running the following PHP script 1k0_base.php

It outputs the following: enter image description here

The code is as follows (excluding irrelevant or sensitive information):

include 'PhpSerial.php';

$serial = new PhpSerial;
    $serial->deviceSet("COM5");
    $serial->confBaudRate(9600);
    $serial->confParity("none");
    $serial->confCharacterLength(8);
    $serial->confStopBits(1);
    $serial->confFlowControl("none");

$serial->deviceOpen();
$readx = $serial->readPortLine(100,"\n");
echo nl2br("\n".$readx."\n\n");
$read0 = $serial->readPortLine(24,"");
echo nl2br("\n".$read0."\n\n");
//$read1 = $serial->readPortLine(24,"");
$serial -> deviceClose();
$readxx = explode(" ",$readx);
print_r($readxx);
echo nl2br("\n".$readxx[0]."\n"); //test
$read00 = explode(" ",$read0);
print_r($read00);
//$read11 = explode(" ",$read1);
$arrCount = count($read00);
for($x=0;$x<$arrCount;$x++){
    $m=1;
    if ($read00[$x]>0){
        $m=$read00[$x];
        break;
    }
}
$massCharNum = $x;
for($x=0;$x<$arrCount;$x++){
    $unit=1;
    if (ctype_alpha($read00[$x])){
        $unit=$read00[$x];
        break;
    }
}

date_default_timezone_set('America/Denver');
echo nl2br("\n\nDebug String: ".$read0."\n");
echo nl2br("Mass: ".$m."\n");
echo nl2br("Unit: ".$unit."\n");
echo nl2br("Time: ".date("n/j/y H:i:s",time())."\n\n");

I am connecting to a scale via R232 > RS232 extender to Prolific USB-to-Serial Comm Port (COM5) as identified in device manager.

The arduino IDE I am using is able to read and communicate with COM5 port, and I have confirmed that the data is being printed every 5 secs.

This code has been shown to work with other scale data monitoring serial to usb communications, only difference is using a pass through DB9 RS232 to this Prolific USB-to-Serial.

The following is the data sheet for serial comms for the scale I'm using (same as the other scales that are working with the code as intended).

enter image description here

The next image is a snippet of the PhpSerial.php I am using, and not sure why when reading the port line my code returns an empty string and array. Even though the serial monitor is showing its printing. The code also breaks when I force the COM5 port to be busy as well as disconnecting it. So The code knows it's connected, but still doesn't read values it's printing. enter image description here

Picture verifying the COM5 serial print statements on Arduino IDE

enter image description here

1
SOLVED: Turns out PHP is not robust in reading serial data (go figure), and after many attempts to get the code to work with the Prolific drivers on the serial-to-USB connection I gave up and bought a serial-to-USB cable with the more standard FTDI driver chipset. Turns out that was enough to get the Phpserial.php to read the incoming data. If someone knows a more articulate or detailed explanation as to why this is the case I'd love to hear feedback and thoughts.P.Lynch

1 Answers

0
votes

SOLVED: Turns out PHP is not robust in reading serial data (go figure), and after many attempts to get the code to work with the Prolific drivers on the serial-to-USB connection I gave up and bought a serial-to-USB cable with the more standard FTDI driver chipset. Turns out that was enough to get the Phpserial.php to read the incoming data. If someone knows a more articulate or detailed explanation as to why this is the case I'd love to hear feedback and thoughts.