Serial Communication Arduino to PHP

旧城冷巷雨未停 提交于 2019-12-11 05:19:42

问题


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

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.

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!

Greets Fab


回答1:


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));
                    }

i used just this

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


     return str_split($content);

then reconstruct the byte string in php



来源:https://stackoverflow.com/questions/16786672/serial-communication-arduino-to-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!