简体   繁体   English

PhP READING从arduino发送的串口数据

[英]PhP READING Serial port data sent from arduino

Im trying to make something really simple, button counter, have a button on my html-php when i click it i sent data 'press' to my arduino and it makes a led flicker, so far so good, but then i want to sent the signal when i press a push button in arduino,i want to make my php read the serial port with the string "Number of clicks: N", N being the push count from arduio. 我正在尝试使事情变得非常简单,按钮计数器,当我单击它时在我的html-php上有一个按钮,我向arduino发送了数据``按'',这使得LED闪烁,到目前为止效果很好,但是我想发送当我在arduino中按下按钮时的信号,我想让我的php使用字符串“点击数:N”读取串行端口,N是来自arduio的推动计数。

Problem here is, in arduino serial i can see he string, everything fine, but in php i do 这里的问题是,在arduino串行中,我可以看到他的字符串,一切都很好,但是在php中,我可以

echo fread($fp); //fp being ttyACM0

and all i get are incomplete strings example: 我得到的都是不完整的字符串示例:

COMPLETE ARDUINO STRING: "Number of clicks: 15" 完整的ARDUINO STRING:“点击次数:15”

PHP STRING: "Ner of clic: 5" PHP STRING:“神经衰弱:5”

It's unclear from your question what you are trying to do, but it looks like you're losing some data during the transmission. 从您的问题尚不清楚您要做什么,但是看起来您在传输过程中丢失了一些数据。 Can you post more of your code (especially the code you're running on the Arduino)? 您是否可以发布更多代码(尤其是您在Arduino上运行的代码)?

I'd recommend sending only the value (ie, '15' rather than 'Number of clicks: 15'), and adding the additional text in your PHP instead. 我建议只发送该值(即“ 15”,而不是“点击数:15”),然后在您的PHP中添加其他文本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM