Hi JP,
You successfully reached at least one of the people with in depth
knowledge. The other would be the current maintainer (see the README in
the distribution). He took over in part because he had a more complete
test environment including a Solaris machine. These days, I only have a
couple of linux variants and several Windows versions. One of the tricky
parts of changing/maintaining the SerialPort family of modules was that
they run on a lot of different hardware - although not always
identically :-(
But we have tried to make the look identical
If you want to try to detect and respond to momentary disconnects more
reliably, I would tend to stay away from the tied filehandle interface
and use either input or read directly. That way, you can test the return
values for undef before trying to use them in other operations. So in
your case, you were receiving these errors:
Use of uninitialized value $count_in in addition (+) at /usr/lib/perl5/Device/SerialPort.pm line 2214.
Use of uninitialized value $string_in in concatenation (.) or string at /usr/lib/perl5/Device/SerialPort.pm line 2232.
Where the underlying code is (in part, [[line#]] and ###comments added):
[[2206]] ($count_in, $string_in) = $self->read($size);
###
### This is the real problem. $self->read is returning undef
### perhaps from some logic in read itself or perhaps in the
### call to POSIX::read that happens further up the pipeline.
###
### It might be possible to do something like this
### unless (defined $count_in) {
### $count_in = 0;
### $string_in = "";
### }
###
### I haven't tested it and I won't guarantee it would work in your case.
$$buf = '' unless defined $$buf;
my $buflen = length $$buf;
my ($tail, $head) = ('','');
if($offset>= 0){ # positive offset
[[2214]] if($buflen> $offset + $count_in){
$tail = substr($$buf, $offset + $count_in);
}
if($buflen< $offset){
$head = $$buf . ("\0" x ($offset - $buflen));
} else {
$head = substr($$buf, 0, $offset);
}
} else { # negative offset
$head = substr($$buf, 0, ($buflen + $offset));
if(-$offset> $count_in){
$tail = substr($$buf, $offset + $count_in);
}
}
# remaining unhandled case: $offset< 0&& -$offset> $buflen
[[2232]] $$buf = $head.$string_in.$tail;
return $count_in;
-bill
On 05/01/2012 03:40 PM, JPH via RT wrote:
Show quoted text> Queue: Device-SerialPort
> Ticket<URL:
https://rt.cpan.org/Ticket/Display.html?id=76881>
>
> Thnx Bill for your comment, I'll have to study/think about your pipeline steps 1-8, maybe with this sum up I can figure out how to prevent DTS from pulsing when I open the filehandle (which is
> effectively resetting my Arduino).
>
> About the disconnect/recover, Sometimes the devices get disconnected due to EMI (eg. a 'tuned' motorbike passing the house), so I have to recover from that. I'm able to recover just fine, just don't
> like the two undefined variable warnings. Perl does throws proper errors too if I don't catch them myself.
>
> Anyways, My opinion is that it is a 'nice to have fixed'. I added (what I think is) a fix, but I know too little about the inner workings to be sure. For now I'm using my 'patched' version on my PC.
>
> What would be a proper way get in contact with people who have in depth knowledge on Device::SerialPort? My experience is that it is hard to find. Is there a forum/mailing list ...
>
> Thanks for your time.
>
> Enjoy!
>
> JP
>
> On 05/01/2012 05:27 AM, Bbirthisel@aol.com via RT wrote:
>> But I never envisioned someone trying to
>> disconnect/recover from within a tied-filehandle interface.
>> Here is the pipeline:
>> 1. Your device
>> 2. Serial to USB (with internal buffering)
>> 3. USB Cable
>> 4. linux USB Driver (with internal buffering and emulation to look like
>> hardware serial device)
>> 5. POSIX.pm (serial port interface including buffering)
>> 6. Device::SerialPort
>> 7. Tied-Filehandle interface
>> 8. Your code