Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Accessing Serial port on windows and Linux

by kranthi (Sexton)
on May 23, 2008 at 05:14 UTC ( #688080=perlquestion: print w/ replies, xml ) Need Help??
kranthi has asked for the wisdom of the Perl Monks concerning the following question:

Hi perl monks, I have the below queries regarding the Serial port access on both Windows and Linux OS. 1. What are the perl packages that i need to download to access the port? 2. Can you please provide me the information or any URL which contain the information on how to access (Read, Write, Modify etc.) the data through the Serial port?

Comment on Accessing Serial port on windows and Linux
Re: Accessing Serial port on windows and Linux
by tachyon-II (Chaplain) on May 23, 2008 at 05:34 UTC

    Win32::SerialPort for Win32 and Device::SerialPort for linux. Common interface.

    my $PortObj; if ( $^O =~ m/Win32/ ) { require Win32::SerialPort; $PortObj = new Win32::SerialPort ($PortName, $quiet, $lockfile) or die "Can't open $PortName: $!\n"; } else { require Device::SerialPort; $PortObj = new Device::SerialPort ($PortName, $quiet, $lockfile) or die "Can't open $PortName: $!\n"; } # theoretically do same stuff on Win32 or Linux with same method calls
      Hi thankyou for your reply. for this do i need to download and install Win32::SerialPort, if so can u please let me know the procedure for the same. I am using Active perl 5.10.0 Build 1002.
Re: Accessing Serial port on windows and Linux
by TGI (Vicar) on May 23, 2008 at 16:18 UTC
Re: Accessing Serial port on windows and Linux
by xiaoyafeng (Chaplain) on May 27, 2008 at 15:14 UTC
    I haven't used whatever::serialport modules for long long time. You just simply type below:
    open( PORT, "+>/dev/S01/" or die "Can't open S01: $!"; #linux mode open( PORT, "+>COM1" ) or die "Can't open COM1: $!"; #Windows mode
    Please note you should install active perl first for the second method.

    I am trying to improve my English skills, if you see a mistake please feel free to reply or /msg me a correction
      How do you specify speed, parity and xon/off?

        By using ioctl, at least on Linux. The various serial port modules take care of that when you use them. I think Windows has something similar, RTFM. In the worst case, you get the OS defaults for the port.

        Note that /dev/S01 is usually not your first serial port. That would be named /dev/ttyS0, and the second one /dev/ttyS1. USB converters usually appear as /dev/ttyUSB0, /dev/ttyUSB1, and so on. (/dev/S01 seems to be a typo or a system-specific device.)

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re: Accessing Serial port on windows and Linux
by Anonymous Monk on May 28, 2008 at 05:08 UTC
    Hi, use Device-SerialPort for serial port handling. the documentation is also in detail. get it from cpan.
Re: Accessing Serial port on windows and Linux
by Anonymous Monk on Jan 18, 2013 at 06:37 UTC
    To the webmaster: You are using what seems to be a 4 px font to display the conversations. What waste so much screen and not use a 1 px font, so only those equipped with a good mag. glass could read it?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://688080]
Approved by NetWallah
Front-paged by moritz
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2014-12-26 07:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (168 votes), past polls