Receiving Data


To receive data, use the spc_request function. You must input 6 for the second argument.

$rbuf = spc_request($sid, 6, $rlen)

an example of receiving data

This example receives data from the serial port and send it back to the same port.

<?php
include "/lib/sd_spc.php";

$rwbuf = "";
$sid = 14;
spc_reset();
spc_sync_baud(115200);

spc_request_dev($sid, "set uart 115200N81");

while(1)
{
    $txfree = (int)spc_request_dev($sid, "get txfree");
    $rlen = (int)spc_request_dev($sid, "get rxlen");
    if($rlen > 0)
    {
        if($rlen <= $txfree)
        {
            // receive data
            $rwbuf = spc_request($sid, 6, "$rlen");

            // send data
            spc_request($sid, 7, $rwbuf);

            // print data
            echo $rwbuf;
        }
    }
    usleep(1000);
}
?>