Jump to content


  • Posts

  • Joined

  • Last visited

Everything posted by KenHorse

  1. Ok thanks. Guess I'm too much of a noob. Sorry for wasting your time
  2. As my OP said, I'm using php_serial_class, which is loaded in global.php (hence the include): require_once("php_serial.class.php"); // Let's start the serial class $serial = new phpSerial; $comport = "/dev/ttyUSB0"; $serial->deviceSet($comport); // We can change the baud rate $serial->confBaudRate(19200); $serial->confParity("none"); $serial->confCharacterLength(8); $serial->confStopBits(1); $serial->confFlowControl("none"); // Then we need to open it $serial->deviceOpen(); //clear out crap $serial->sendMessage("\r"); $serial->sendMessage("\r"); sleep(0.1); // Or to read from //$read = $serial->readPort(); //to send to //$serial->sendMessage("data to send"); // If you want to change the configuration, the device must be closed //$serial->deviceClose(); //and then reopened Also, $stuff is not yet used but I plan on using it in the function after I get passed this issue As for $timediff, yes. I have not defined it yet. Again, I need to get passed this to clean other things up (I guess I should point out that this code was originally written by someone else long before PHP 7.0 was released. I'm trying to get it functional under 7.3xxx but I am certainly not overly fluent in PHP yet)
  3. function checkInput($stuff){ $starttime = microtime(true); while($read =="" && $timediff < '5'){ $read = $serial->readPort(); $substring = substr($read,0,1); //echo "SubString " . "$substring"; if($substring =="-"){ print"<CENTER><H2>We encountered an error when sending $read". "Please close window and try again</H2></CENTER>"; $noDataToSend ="False"; exit(); } $endtime = microtime(true); $timediff = $endtime - $starttime; if($substring =="+"){ //if ACK received, reset timer $starttime = microtime(true); }else{ if($substring !=""){echo "Substring " . "$substring\r\n";} } if($timediff > '4'){ print"<CENTER><H2>No response from the Station. Please close this window, check your serial connections and try again</H2></CENTER>"; $noDataToSend ="False"; exit(); } sleep(0.1); }//while } //end function And the line calling it: $senddata = "122222"; $serial->sendMessage("$senddata\r"); checkInput($senddata); Yes, I am not currently using the passed parameter ($stuff) but am planning to after I fix this problem
  4. It's the actual call to the class $read = $serial->readPort();
  5. BTW, PHP version is 7.3.29-1 So I changed the variable in the Function: function checkInput($stuff){ No change PHP Fatal error: Uncaught Error: Call to a member function readPort() on null in /var/www/controlserial.php:371
  6. outdated? How else do you include other files? (admittedly, I am not overly well versed in PHP but do a lot with VB)
  7. I have a file (global.php) that used by many different other files in a project I'm doing. This file contains many things including connecting to a MySQL database as well as loading a php_serial_class. So at the top of php file that needs these resources, I use include("global.php"); In one of those other php files, I also have a function that I'm using that calls the php_serial_class: $read = $serial->readPort(); This throws an error: Line 104 is the call to the function and Line 370 is the actual read call to the class I assume this error is thrown as the function doesn't know about that class? If so, can I simply also load the include within the function or is there a better way to do it?
  8. Craziest damn thing. The installer added the extension=dio.so at the beginning of php.ini, hence the bracketed term afterwards Thanks for opening my eyes
  9. Ok, finally figured out what I needed to do in order to install the dio.so extension and that succeeded. Updated both php.ini (web and cli) to load extension dio.so I created a test file with the following contents: $fd = dio_open('/dev/ttyUSB0', O_RDWR | O_NOCTTY | O_NONBLOCK); dio_close($fd); Now, when I run it, I receive the following error: PHP Warning: PHP Startup: Unable to load dynamic library 'dio.so[PHP]' (tried: /usr/lib/php/20180731/dio.so[PHP] (/usr/lib/php/20180731/dio.so[PHP]: cannot open shared object file: No such file or directory), /usr/lib/php/20180731/dio.so[PHP].so (/usr/lib/php/20180731/dio.so[PHP].so: cannot open shared object file: No such file or directory)) in Unknown on line 0 I have checked /usr/lib/php and it IS there: root@mypi:/var/www/html/WebRCP# ls /usr/lib/php/20180731/ build curl.so fileinfo.so iconv.so mysqlnd.so phar.so simplexml.so sysvshm.so xmlreader.so bz2.so dio.so ftp.so json.so opcache.so posix.so sockets.so tokenizer.so xmlwriter.so calendar.so dom.so gd.so mbstring.so pdo.so readline.so sysvmsg.so wddx.so xsl.so
  10. As the title says. I'm trying to install the dio-0.2.0 package (Raspian Buster) and first did a pecl list-all and the above was returned
  11. I didn't catch that change, no. As my device looks specifically for a CR (/r), that might be the issue. I'll give it a shot
  12. Kicken's script (above). I even quoted it
  13. I changed to /dev/ttyUSB0 and baud rate of 57600 to match my needs. I should receive "+1111" back from the external device. Script is named test root@mypi:~# php test 11111 string(0) "" root@mypi:~#
  14. As I said, this converter works just fine with minicom By the way, what prompted me to use this code for serial comm was that I tried using php_serial.class.php (which now appears to be https://packagist.org/packages/hyperthese/php-serial) but it never seemed to work right. I was unaware of the others listed at packagist so perhaps I should give THEM a try....
  15. /dev/snd/controlC1 - C-Media_Electronics_Inc._USB_PnP_Sound_Device /dev/ttyUSB0 - FTDI_FT232R_USB_UART_AH05WJ52
  16. USB > serial? https://www.amazon.com/Sabrent-Serial-Adapter-Chipset-CB-FTDI/dp/B006AA04K0/ref=sxts_sxwds-bia-wc-drs1_0?cv_ct_cx=usb+ftdi&dchild=1&keywords=usb+ftdi&pd_rd_i=B006AA04K0&pd_rd_r=ddec056b-609e-486c-b2d8-d38beba84201&pd_rd_w=0Ev9e&pd_rd_wg=sCNyr&pf_rd_p=ecbfa24d-f48c-4d5c-83aa-9549f4e7c925&pf_rd_r=ENNAVCF3SFBC582P3EJE&psc=1&qid=1602268074&sr=1-1-f6b8d51f-2c55-4dc3-89ad-0c3639671b2d Works very well with minicom
  17. I've had good luck using FTDI based converters with Raspbian. I've done a few searches about actually using stream_set_blocking function but not having any luck. As I've never worked with it before, are there some examples of its implementation (as in actual code examples)?
  18. This is running Raspian Buster (Debian 10). Sorry, I didn't think the script itself was an issue but here it is: <?php include("global.php"); $senddata = "SetClock" . date("His"); $serial = serial("$senddata"); echo $serial; sleep(1); $senddata = "SetCalendar" . date("mdy"); $serial = serial("$senddata"); echo $serial; exit() //<----recently added to try to force close but no difference ?> In global.php are my serial functions function serial($cmd){ $port = "/dev/ttyUSB0"; $c = exec('stty -F '.$port.' cs8 -parenb -cstopb -echo raw speed 57600'); if(!file_exists($port)) { echo "I am not blocked!"; } else { $f = fopen($port, "w+"); fwrite($f, $cmd."\r"); while(1) { $dataOut = fgets($f); if(strlen($dataOut) > 5) { // echo $dataOut; fclose($f); break; } else { fwrite($f, $cmd."\r"); } } } return $dataOut; }
  19. I have a script that is called from crontab. : 0,5,10,15,20,25,30,35,40,45,50,55 * * * * /usr/bin/php /var/www/settime.php I checked back later and notice many instances of php running: root@mypi:~# ps aux |grep settime root 1646 0.0 0.0 1856 380 ? Ss 10:20 0:00 /bin/sh -c /usr/bin/php /var/www/settime.php root 1647 0.0 2.0 75676 19860 ? S 10:20 0:00 /usr/bin/php /var/www/settime.php root 1777 0.0 0.0 1856 352 ? Ss 10:25 0:00 /bin/sh -c /usr/bin/php /var/www/settime.php root 1778 0.0 2.0 75676 19604 ? S 10:25 0:00 /usr/bin/php /var/www/settime.php root 1898 0.0 0.0 1856 340 ? Ss 10:30 0:00 /bin/sh -c /usr/bin/php /var/www/settime.php root 1899 0.1 2.0 75676 19672 ? S 10:30 0:00 /usr/bin/php /var/www/settime.php root 1943 0.0 0.0 4396 544 pts/0 S+ 10:31 0:00 grep settime settime.php is a script that sets an external clock via /dev/ttyUSB0 Obviously I'm doing something wrong as it should run and stop
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.