I tried different versions of Ubuntu. Now I have installed the actual image from volkszaehler.org
It runs on a raspberry pi
The "cat /dev/ttyUSB0&" makes no difference if started before or after the stty settings.
The stty arguments are from a documentation, I tried your style and it seems to be running the same as before.
The meter system giving the commands "/?!" and "000" back, when I send it to him.
Every line ends with "\r\n".
I changed my code:
use Fcntl qw/:DEFAULT/;<br>
use IO::Termios ();<br>
use IO::Stty ();<br>
<br>
sysopen my $fh, '/dev/ttyUSB0', O_RDWR or die "sysopen: $!";<br>
my $handle = IO::Termios->new($fh) or die "IO::Termios->new: $!";<br>
$handle->set_mode('300,7,e,1');<br>
IO::Stty::stty($handle, qw/ cs7 parenb -parodd raw -echo /);<br>
<br>
my $raw = "\x2F\x3F\x21\x0D\x0A";<br>
$handle->syswrite($raw) == length($raw) or die "syswrite";<br>
my $raw = "\x06\x30\x30\x30\x0D\x0A";<br>
$handle->syswrite($raw) == length($raw) or die "syswrite";<br>
<br>
while(1) {<br>
my $toread = 1;<br>
$handle->sysread(my $in, $toread) == $toread or die "sysread";<br>
print $in;<br>
}<br>
<br>
$handle->close;<br>
<br>
<br>
And you see in strace my problem: (only last lines of output)
read(4, "/", 1) = 1<br>
read(4, "L", 1) = 1<br>
read(4, "O", 1) = 1<br>
read(4, "G", 1) = 1<br>
read(4, "4", 1) = 1<br>
read(4, "L", 1) = 1<br>
read(4, "K", 1) = 1<br>
read(4, "1", 1) = 1<br>
read(4, "3", 1) = 1<br>
read(4, "B", 1) = 1<br>
read(4, "D", 1) = 1<br>
read(4, "2", 1) = 1<br>
read(4, "0", 1) = 1<br>
read(4, "2", 1) = 1<br>
read(4, "0", 1) = 1<br>
read(4, "1", 1) = 1<br>
read(4, "5", 1) = 1<br>
read(4, "\r", 1) = 1<br>
read(4, "\n", 1) = 1<br>
write(1, "/LOG4LK13BD202015\r\n", 19/LOG4LK13BD202015) = 19<br>
read(4, <br>
After "read(4," the script waits endless
The only way it works, when I send the sequence (stty setting, then /?!\r\n, then 000\r\n) directly into a shell
So I can not understand what the problem could be.
|