The command to set inter frame delimiter is ifd. While receiving data, PES-2407 distinguishes frames with the designated delimiter by this command. At this time, you can check the frame length with "get rxlen" command and receive data in frame units.
Separating frames from the end
Set the delimiter as follows to separate frames from the end.
"set ifd (del)"
If you set a delimiter in the del, data up to the delimiter is considered as one frame. The delimiter must be set in hexadecimal string form and can be set from 2 bytes to 64 bytes.
Separating frames from both ends
Set two delimiters as follows to separate frames from both ends.
"set ifd (start_del) (end_del)"
If you set two frame delimiters, the data from the first delimiter to the second delimiter becomes one frame. Both delimiters and the data between delimiters are valid but the rest of the data is ignored. The total length of two frame delimiters can not exceed 64 bytes.
How to unset inter frame delimiter is as follows:
"set ifd"
If you do not specify anything after the ifd command as above, the frame delimiter is unset.
<?php
include "lib/sd_spc.php";
$sid = 14;
spc_reset();
spc_sync_baud(115200);
spc_request_dev($sid, "set uart 115200");
spc_request_dev($sid, "set ifd 1b01");
echo spc_request_dev($sid, "get ifd"), "\r\n"; // output: 1b01
spc_request_dev($sid, "set ifd 1b02 1b03");
echo spc_request_dev($sid, "get ifd"), "\r\n"; // output: 1b02 1b03
spc_request_dev($sid, "set ifd");
echo spc_request_dev($sid, "get ifd"), "\r\n"; // output:
?>
an example of sending and receiving data with delimiter
This example uses 0x0d as a delimiter to receive data on a frame-by-frame basis and send the data back.
<?php
include "/lib/sd_spc.php";
$rwbuf = "";
$sid = 14;
spc_reset();
spc_sync_baud(115200);
spc_request_dev($sid, "set uart 115200N81");
spc_request_dev($sid, "set ifd 0d");
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);
}
?>
※ Note: The setting of inter frame delimiter ("set ifd") and the setting of inter frame gap ("set ifg") cannot be used at the same time.