Hello
Im trying to read from ttyUSB0 on Ubuntu using the following code:
<?php
// Create the context
set_time_limit(0);
@ob_end_flush();
ob_implicit_flush(true);
$c = stream_context_create(array('dio' =>
array('data_rate' => 1200,
'data_bits' => 7,
'stop_bits' => 2,
'parity' => 0,
'flow_control' => 0,
'is_blocking' => 0,
'canonical' => 1)));
// You can change the properties above, matched with your device
$handle = fopen("dio.serial:///dev/ttyUSB0", "r+", false, $c); //format: dio.serial://[device-name]
if ($handle) {
echo "Initiate port";
while(!feof($handle)) {
$data = fgets($handle, 1024); // try to make long, so it will detect the newline automatically
echo $data;
sleep(1);
}
fclose($handle);
}
?>
It only echos $data sometimes and is not really reliable. Im not sure why it stops/starts working. Ive been using cutecom sometimes at the same time to compare the returned data.
Would cutecom interfere with the reading? Why would it only echo $data sometimes?
How can I make this reliable?
CAN ANYONE HELP ME!!