We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

obtain data from COM port- RS232 port -SERIAL port

Hi I want to read data from a COM port - SERIAL - RS232. I thought externally with javascript or jquery to tell me not to but it is with PHP. There is a library in Phalcon Php that allows me to do this or need to find an external library



1.9k

PHP don't have access to hardware. Maybe something could be done with Zephir and make extension for PHP. Or writing extension in plain C

Your best shot is to run some daemonized program on that machine where you need to access serial port data, and then to read it from your web app via web service (json).

So you need intermediate (helper) with direct access to port data.

For instance, I'm reading APC UPS data that way from /dev/ttyS0. PHP issues system call to read and parse data from it, and then presents json formatted data to the external apps (consumers).



81.1k

Thank you very much I'll try. Or try to read from php and upload the form with Json. Very Thanks

Your best shot is to run some daemonized program on that machine where you need to access serial port data, and then to read it from your web app via web service (json).

So you need intermediate (helper) with direct access to port data.

For instance, I'm reading APC UPS data that way from /dev/ttyS0. PHP issues system call to read and parse data from it, and then presents json formatted data to the external apps (consumers).

edited Sep '18

Hello, right now, i'm on same project, read data from a COM port - RS232, but still not working.

i used php_serial.class.php (i get from php-serial-master) did not get any data from hyper terminal

i try to this code (forgot where i get it from internet) below too, but it still not working at all, would you mind to share the code that you use? FYI, data that we want to get is from scaling devices which has a modification cable that cross between cable number 3 and 5 if i'm not mistaken

<?php

$cmd_str = "MODE COM3: BAUD=9600 PARITY=N DATA=8 STOP=1 XON=OFF TO=OFF OCTS=OFF ODSR=OFF IDSR=OFF RTS=OFF DTR=OFF";
$output = array();
exec($cmd_str, $output, $result);

set_time_limit(0);

$serial_port = fopen("COM3","rn");
$hasil = fgets($serial_port,9600);
fflush($serial_port);
fclose($serial_port);
  print("<pre>");
print_r($cmd_str);
print("\n");
print_r($output);
print("\n");
print_r($hasil);
print("\n");
print("</pre>");
exit;

$serial_port = fopen("COM4","wb");
$a = chr(1);
$hasil = fwrite($serial_port,$a);
fclose($serial_port);