问题描述
我试图用 PHP_serial.class.PHP 发送十六进制但不能。 消息正确发送,没有错误,但组件没有反应。 我用 CoolTerm 对其进行了测试,它仍然有效。
我是不是忘记了一步?
<?PHP
include 'PHPSerial.PHP';
$serial = new PHPSerial;
// First we must specify the device. This works on both linux and windows (if
// your linux serial device is /dev/ttyS0 for COM1,etc)
$serial->deviceSet("/dev/tty.usbserial");
// We can change the baud rate,parity,length,stop bits,flow control
$serial->confBaudrate(19200);
$serial->confParity("none");
$serial->confCharacterLength(8);
$serial->confStopBits(1);
$serial->confFlowControl("none");
// Then we need to open it
$serial->deviceopen();
$message = "\x02\x00\x31\x03\x36";
$serial->sendMessage($message);
$serial->deviceClose();
解决方法
我也这样试过:
<?php
include 'PhpSerial.php';
$serial = new PhpSerial;
// First we must specify the device. This works on both linux and windows (if
// your linux serial device is /dev/ttyS0 for COM1,etc)
$serial->deviceSet("/dev/tty.usbserial");
// We can change the baud rate,parity,length,stop bits,flow control
$serial->confBaudRate(19200);
$serial->confParity("none");
$serial->confCharacterLength(8);
$serial->confStopBits(1);
$serial->confFlowControl("none");
// Then we need to open it
$serial->deviceOpen();
$message = chr(0x02) . chr(0x00) . chr(0x31) . chr(0x03) . chr(0x36);
$serial->sendMessage($message);
$serial->deviceClose();
使用 var_dump 我得到值 16,但我的控制器没有反应...... 我有点失落,我已经验证控制器收到了消息。使用 CoolTerm 应用程序一切正常。