Skip to content

Commit 134eb36

Browse files
committed
Switch to using Direct IO functions for serial access
1 parent 05a2b20 commit 134eb36

File tree

2 files changed

+20
-55
lines changed

2 files changed

+20
-55
lines changed

com2ip.php

+7-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
else throw new Exception("Invalid specified TCP port");
1414
}
1515

16+
system("mode COM{$com} BAUD=9600 PARITY=N DATA=8 STOP=1");
17+
1618
$comPath = "\\\\.\\COM{$com}";
1719

18-
$file = fopen($comPath, "r+b");
20+
$file = dio_open($comPath, O_RDWR);
1921
if (!$file) throw new Exception("Can't open COM$com port");
2022

2123
$fp = stream_socket_client("tcp://127.0.0.1:$tcp_port");
@@ -24,11 +26,12 @@
2426
print "All ports OPEN. Proxying data. Press CTRL-C to quit.\n";
2527

2628
while (true) {
27-
$data = fgets($file);
28-
$data = preg_replace('#\s#','',$data);
29-
if($data == '0') continue; // Filter out 0, since we aren't interested in those
29+
$data = dio_read($file,1);
3030
if ($data===false) break;
31+
$data = preg_replace('#\s#','',$data);
32+
if($data == '0' || $data == '') continue; // Filter out 0, since we aren't interested in those
3133
fwrite($fp, $data);
34+
print $data;
3235
}
3336

3437
fclose($file);

composer.lock

+13-51
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)