PHP serial communication - linux

Asked

Viewed 227 times

0

Hello, I made a php code for serial communication, this code worked in windows correctly, but I’m having problems with it in linux. To be able to communicate, I need to use the command -stty -F /dev/ttyS0 19200 -icanon. If I don’t use -icanon it doesn’t work. In doing so, I can only perform serial communication once, then it seems that Ubuntu is waiting for some feedback and I can’t read the data I need anymore. Follows 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 realized that if I close and open the communication, both work, but I can’t do that because I need speed. Sorry any not formatting because I’m new around here.

Thank you very much.

  • What is connected to the serial port and what represents the sent commands?

  • It has a PLC connected to the port. The commands sent are requests for memories from it. In case it is returning voltage, current values, etc...

  • Are you sure the first command is complete? There is no symbol missing to send to signal the end of the command?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.