Read serial port data with PHP

0

My situation is as follows:

I have several scales connected to the server, each scale is connected through a serial port, I am currently using the COM5 port (I have already tried with other major and minor ones). These scales send a constant string through the serial port (containing the current weight shown on the display). I tested with java code it worked good, less with PHP.

Here are some codes I've already used:

$port = fopen('COM5', 'w'); //tente com r e r+ e nada
sleep(2);
echo fgets($port);
fclose($port);

Using the above code it locks the COM5 port and only returns after restarting the apache (PHP) service.

With the extension of com_dotnet.dll enabled in php too, I had the following error.

$serial = new DOTNET('System', 'System.IO.Ports.SerialPort');
$serial->PortName = 'COM5';
$serial->Open();
  

Fatal error: Uncaught com_exception: Failed to instantiate .Net object [CreateInstance] [0x80070002] The system can not find the specified file. in C: \ xampp \ htdocs \ index.php: 2 Stack trace: # 0 C: \ xampp \ htdocs \ index.php (2): dotnet-> dotnet ('System', 'System.IO.Ports .. # 1 {main} thrown in C: \ xampp \ htdocs \ index.php on line 2

I know that sending information through the serial port to an Arduino it sends good, I got to test too, the problem occurs in reading the same. any information and welcome: (

    
asked by anonymous 15.02.2016 / 21:12

1 answer

0

resolved with the code:

$port = fopen('COM5', 'r+b');
sleep(1);
echo fgets($port);
fclose($port);
    
15.02.2016 / 22:28