Received Data Size


The command to get the size of received data is rxlen. In the case of setting inter frame gap("set ifg") or inter frame delimiter ("set ifd"), the return value is the length of received frame. If there are multiple frames received, the length of the first received frame is returned.

"get rxlen [del]"

The return value is a string in integer form.

If you specify a delimiter in del, it returns the length to the delimiter.

※ Refer to the "Separating frames from the end" in Inter Frame Delimiter page about how to set the delimiter.

<?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);
}
?>
<?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 0d");
    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);
}
?>