Serial Communication PHP - linux

0

Hello, I made a php code for serial communication, this code worked on windows correctly, however I'm having problems with it in linux. To get the communication done, I need to use the -stty -F / dev / ttyS0 19200 -icanon command. If I do not use the -icanon does not work. Doing so, I can only perform serial communication once, then it seems that ubuntu is waiting for some feedback and I can no longer read the data I need. Here is my code:

$envio = fopen("/dev/ttyS0", "r+b");
fwrite($envio, "\x01\x04\x02\x3C\x00\x64\x30\x55");
$dadosHex = fread($envio, 75);
$run = substr($dadosHex, 113, 1);
fwrite($envio, "\x01\x04\x02\x3C\x00\x64\x30\x55");
$dadosHex1 = fread($envio, 75);
$run1 = substr($dadosHex1, 113, 1);
fclose($envio);

The $ run variable returns the correct value, but $ run1 does not return correctly. I noticed that if you close and open the communication the two work, but I can not do this because I need speed. Sorry for any non-formatting because I'm new here.

Thank you very much.

    
asked by anonymous 17.08.2017 / 16:38

0 answers