Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: Difficulties with Device::SerialPort

by EvanK (Chaplain)
on Sep 07, 2005 at 15:30 UTC ( [id://489895]=note: print w/replies, xml ) Need Help??


in reply to Re: Difficulties with Device::SerialPort
in thread Difficulties with Device::SerialPort

hmmm...I've tried this two ways, one with jsut the built-in i/o methods, and another way with a tied filehandle. here's what i'm usign right now:
# note, ive tried ttyS0 and S1, same error with both $port = '/dev/ttyS0'; # creates a hidden config file in user's home dir $config = '~/.conf'; # this tests for an existing config file, # and creates one if necessary... if(! -e $config) { $PortObj = new Device::SerialPort ($port) || die(RED,"Can't open $port: $^E\n",RESET); $PortObj->databits(7); $PortObj->baudrate(19200); $PortObj->parity("even"); $PortObj->stopbits(1); $PortObj->handshake("xoff"); $PortObj->buffers(4096, 4096); $PortObj->write_settings || undef $PortObj; $PortObj->save("$config"); $PortObj->close || die(RED,"failed to close",RESET); undef $PortObj; } # and this connects to the port by loading said # config file and tying to SERIAL filehandle $PortObj = tie (*SERIAL, 'Device::SerialPort', "$config") || die(RED,"Can't open $port: $^E\n",RESET); # use non-blocking read on serial port $PortObj->read_char_time(5); $PortObj->read_const_time(500); # create flag variables initialized to zero... my $EXIT = 0; # ...when a trapped system signal is sent, set flag to 1 $SIG{'INT'} = sub { $EXIT = 1 };
i've used this before with a tied filehandle, so it should work.

__________
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
- Terry Pratchett

Replies are listed 'Best First'.
Re^3: Difficulties with Device::SerialPort
by rob_au (Abbot) on Sep 07, 2005 at 23:10 UTC
    While, probably somewhat lateral to your current problem, please be aware that despite documentation to the contrary, the tied-handle interfaces of the Win32::SerialPort and Device::SerialPort modules are not the same - If you have a read through the source for Device::SerialPort, you will find that the TIEHANDLE subroutine calls the new method in place of the start method as what occurs in Win32::SerialPort - A convenience in Device::SerialPort which means that you do not need to have a configuration file for the serial port previously written, but one which breaks compatability with Win32::SerialPort.

     

    perl -le "print unpack'N', pack'B32', '00000000000000000000001000000000'"

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://489895]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-20 00:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found