1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/perl -w
use strict;
use Device::SerialPort;
my $rs485_port = Device::SerialPort->new("/dev/ttyUSB1",1);
$rs485_port->baudrate(256000);
$rs485_port->parity("none");
$rs485_port->databits(8);
$rs485_port->stopbits(1);
$rs485_port->handshake("xoff");
$rs485_port->write_settings;
$rs485_port->stty_echo("off");
$rs485_port->lookclear;
$rs485_port->purge_rx;
my $antwort = "";
my $zeichen = "";
my $count=0;
while ($count<10000) {
$count=$count+1;
$zeichen=$rs485_port->read(1);
$antwort=$antwort.$zeichen;
if ($zeichen eq ";") {
print "$antwort\n";
my $antwort = "";
my $zeichen = "";
}
}
QuoteIt is recommended to always use "read(255)" due to some unexpected behavior with the termios under some operating systems (Linux and Solaris at least).
Guest OliverCode (perl): (dl )1 2 3 4 5 6 7 8 9 10 11 12 13my $antwort = ""; my $zeichen = ""; my $count=0; while ($count<10000) { $count=$count+1; $zeichen=$rs485_port->read(1); $antwort=$antwort.$zeichen; if ($zeichen eq ";") { print "$antwort\n"; my $antwort = ""; my $zeichen = ""; } }
1 2 3 4 5 6 7 8 9 10 11
my $antwort = ""; my $count = 0; while ($count<10000) { $count++; my $zeichen = $rs485_port->read(1); $antwort .= $zeichen; if ($zeichen eq ";") { print "$antwort\n"; $antwort = ""; } }
1 2 3 4 5 6 7
if ($rs485_port->can_arbitrary_baud) { print "this port can set arbitrary baud rates\n"; $rs485_port->baudrate(256000); } else { print "Err: Only fixed baudrates can be set!!!\n" }
1
2
3
4
5
6
7
8
9
10
11
my $rs485_port = Device::SerialPort->new("/dev/ttyUSB1");
$rs485_port->baudrate(256000) or die "die Bautrate...";
$rs485_port->parity("none");
$rs485_port->databits(8);
$rs485_port->stopbits(1);
$rs485_port->handshake("xoff");
$rs485_port->write_settings;
$rs485_port->stty_echo("off");
$rs485_port->lookclear;
$rs485_port->purge_rx;
$rs485_port->write_settings;