php串口通信

本文介绍了在PHP中进行串口通信的解决方法,由于MSComm控件在Win10系统的兼容性问题,作者转向使用php.serial.class.php类库来实现。通过在https://www.phpclasses.org/package/3679-PHP-Communicate-with-a-serial-port.html下载所需文件,即可开始使用。

最近一直在跟其他学院的同学在弄串口通信这一块,因为这不是我擅长的,所以花费了很多时间,在这中间我用过mscomm这个控件,但是它似乎不稳定,好像win10的系统对这个控件不兼容,所以我只能另找方法,一个偶然的机会让我在一个外国网站上面找到了方法,特地跟你们分享一下。

在这之前你需要先下载一个名为php.serial.class.php文件,在https://www.phpclasses.org/package/3679-PHP-Communicate-with-a-serial-port.html里面下载。然后使用如下:

<?php
include 'PhpSerial.php';

// Let's start the class
$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("COM1");

// We can change the baud rate, parity, length, stop bits, flow control
$serial->confBaudRate(2400);
$serial->confParity("none");
$serial->confCharacterLength(8);
$serial->confStopBits(1);
$serial->confFlowControl("none");

// Then we need to open it
$serial->deviceOpen();

// T
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值