十六进制转换:
PHP 操作串口或socket时以16进制发送
"10 EE 2D 0F"
16进制字符串写法:
"\x10\xEE\x2D\x0F"
$sendStr = hex2bin(preg_replace('# #', '', "10 EE 2D 0F"))
socket发送:
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); // 创建Socket
if (socket_connect($socket, "127.0.0.1", 7002)) { //连接
socket_write($socket, $sendStr);
$receiveStr = "";
$receiveStr = socket_read($socket, 1024, PHP_BINARY_READ); // 采用2进制方式接收数据
$receiveStrHex = bin2hex($receiveStr); // 将2进制数据转换成16进制
echo "client:" . $receiveStrHex;
}
socket_close($socket); // 关闭Socket
————————————————
版权声明:本文为CSDN博主「lkj4565」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/lkj4565/article/details/79076763