Ask a Question related to PERL Modules, Design and Development.
-
Olaf Stetzer #1
Waiting for a char received by a serial port (Device::SerialPort)
Hello,
I just did my first steps in programming perl today and got
a "nearly" functioning program. What it should do:
Send a file to /dev/ttyS0 char by char. After each char,
wait for the echo to come back, then continue.
Here is what I wrote, but there seems to be a bug in the
receving/waiting part, it waits endlessly! :-(
Can anyone help me out here?
Thanks,
Olaf
--------------
#!/usr/bin/perl
use Device::SerialPort qw( :PARAM :STAT 0.07);
$Port = "/dev/ttyS0";
$file = "rollei.out";
$device = new Device::SerialPort($Port);
$device->baudrate(9600) || die ("Couldnt set baudrate");
$device->parity("none") || die ("Couldnt Set Parity");
$device->databits(8) || die ("Couldnt Set Databits ");
$device->stopbits(1) || die ("Couldnt set stopbits");
$device->write_settings || die ("No Settings");
open(INFO, $file); # Open for input
@lines = <INFO>; # Read it into an array
close(INFO); # Close the file
foreach $curr_line (@lines) {
for ($i = 0; $i <= length($curr_line); $i++) {
$pass=$device->write(substr($curr_line,$i,1));
$in=1;
while ($in) {
$rcv = $device->input;
if ($rcv ne "") {
print $rcv;
$in=0;
}
}
}
}
undef $device;
Olaf Stetzer Guest
-
flash to interact with a device in the serial port(rs232)
Somebody to say would know me if is possible the flash to interact with a device in the serial port (rs232)? It is a device of contactless.... -
Help compiling Device::SerialPort
I am trying to get Device::SerialPort working on Soalris 10. The build fails during the make stage. What's hapening is that, even though... -
Problems with Device-SerialPort
I'm trying to posr a perl application from FreeBSD to Soalris 10 X86. One of the key requirements of this application is communicating via the... -
problem with Device::SerialPort
Hi. I've been googling all afternoon now but wasn't able to find my problem mentioned someplace, but if for some reason my google-fu was weak,... -
Loopback with Device::SerialPort?
This is cross-posted to .misc and modules, as I'm not certain where it belongs. Feel free to redirect the conversation to whichever group you feel... -
Bbirthisel #2
Re: Waiting for a char received by a serial port (Device::SerialPort)
Hi Olaf,
It looks like it does do that.>What it should do:
>Send a file to /dev/ttyS0 char by char.
Two issues:> After each char,
>wait for the echo to come back, then continue.
1. What are you doing to get an echo? Are you connecting via a loopback?
The module (and the port itself) does not echo characters back to the
program that writes them.
2. Unless you set them otherwise, linux ports are commonly configured to
receive a full line of data at a time. You can arrange to receive
char-by-char,
see demo6 for a read-timeout-based way, demo8 for a way that samples
from a recurring loop. You can also adjust the port using stty - but that
is
more difficult to get right than using the time-based alternatives.
There is a lot of error handling missing from the script - especially from
critical
operations like "new" and "open" which really can fail. And no "-w" or "use
strict"
either - and BOTH are recommended when working with devices.
I think you should start by running the examples that come with the
distribution,
to see what they do and assure yourself everything is running properly. Then
try
modifying demo8 to do what you want (your file write replaces the section with
the TERM::Readkey call).
Good luck,
-bill
Bbirthisel Guest



Reply With Quote

