Arduino 到 PHP 的串行通信 [英] Serial Communication Arduino to PHP

查看:29
本文介绍了Arduino 到 PHP 的串行通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个项目,我想通过串行通信将传感器数据从 Arduino 发送到 PHP.

I´m working on a project in which I want to send sensor data from Arduino via Serial Communication to PHP.

不幸的是,我无法在 PHP 中读取串行端口.然而,另一个方向(PHP 到 Arduino)工作得很好.我正在使用 php_serial.class.php 来自 Rémy Sanchez,由 Rizwan Kassim 修改.我依赖于 readPort() - 函数.

Unfortunately I can not read the Serial Port in PHP. However the other direction (PHP to Arduino) works perfectly. I´m using the php_serial.class.php from Rémy Sanchez, modified by Rizwan Kassim. I´m dependant from the readPort() - function.

我正在 Mac OS X 上使用 Arduino UNO 和 Apache WAMP-Server.我应该实现没有以太网屏蔽的串行连接.在进一步的步骤中,我必须将从串行端口接收到的数据保存在 MySql 数据库中.我确实看到过一些涉及这个问题的条目,但它们并没有真正帮助我.我已经尝试了这么多.我敢肯定,有人有一些工作代码并且可以上传它们.我究竟做错了什么?希望有人能贴出代码或者给个提示!

I´m working with an Arduino UNO and Apache WAMP-Server on Mac OS X. I should realise the serial connection without Ethernet shield. In further steps I have to save the received data from the serial port in a MySql database. I have indeed seen a couple of entries covering this issue, but they don´t really help me. I have tried so much. I´m sure, someone has some working codes and can upload them. What am I doing wrong? I hope someone will post the code or has a tip!

顺便说一下,这里是一个人的视频成功了.但是我不能得到代码....提前感谢您的建议!

By the way, here is a video from a guy who succeeded. But I can´t get the codes.... Thanks in advance for your advice!

问候 Fab

推荐答案

php_serial.class.php 有点坏了,我不得不对其进行调整以从中读取,所以不要使用读者提供的以下内容方法:$content = "";$i = 0;

the php_serial.class.php is kind of broken, i had to adapt it to get a reading out of it, so instead of using the following from the reader method: $content = ""; $i = 0;

                    if ($count !== 0)
                    {
                            do {
                                    if ($i > $count) $content .= fread($this->_dHandle, ($count - $i));
                                    else $content .= fread($this->_dHandle, 128);
                            } while (($i += 128) === strlen($content));
                    }
                    else
                    {
                            do {
                                    $content .= fread($this->_dHandle, 128);
                            } while (($i += 128) === strlen($content));
                    }

我只用过这个

     //trigger_error("reading 0 ".$i, E_USER_WARNING);
     $content .= fread($this->_dHandle, $count);


     return str_split($content);

然后在php中重构字节串

then reconstruct the byte string in php

这篇关于Arduino 到 PHP 的串行通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆