For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > August 2007 > Read and write operation in serial port









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Read and write operation in serial port
Saran j jegan

2007-08-28, 8:10 am

Hello, am using win32::serial port for serial communication i can open
the port and able to update the settings such as baud rate , parity
etc.,but i need to know how to transfer the data through it (read and
write), can any give me sound examples

Chas Owens

2007-08-28, 7:01 pm

On 8/27/07, Saran.j.jegan@gmail.com <Saran.j.jegan@gmail.com> wrote:
> Hello, am using win32::serial port for serial communication i can open
> the port and able to update the settings such as baud rate , parity
> etc.,but i need to know how to transfer the data through it (read and
> write), can any give me sound examples
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> http://learn.perl.org/
>
>
>


According to its documentation you can tie it to a file handle and the
read and write from it as if it were a normal file handle. There are
also methods on the object to read and write (streamline and write).

from http://search.cpan.org/~bbirth/Win3..._I/O_Processing
$PortObj = tie (*FH, 'Win32::SerialPort', $Configuration_File_Name)
|| die "Can't tie: $^E\n"; ## TIEHANDLE ##

print FH "text"; ## PRINT ##
$char = getc FH; ## GETC ##
syswrite FH, $out, length($out), 0; ## WRITE ##
$line = <FH>; ## READLINE ##
@lines = <FH>; ## READLINE ##
printf FH "received: %s", $line; ## PRINTF ##
read (FH, $in, 5, 0) or die "$^E"; ## READ ##
sysread (FH, $in, 5, 0) or die "$^E"; ## READ ##
close FH || warn "close failed"; ## CLOSE ##
undef $PortObj;
untie *FH; ## DESTROY ##

$PortObj->linesize(10); # with READLINE
$PortObj->lastline("_GOT_ME_"); # with READLINE, list only

$old_ors = $PortObj->output_record_separator("RECORD"); # with PRINT
$old_ofs = $PortObj->output_field_separator("COMMA"); # with PRINT
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com