Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I've only used Device::SerialPort under Linux, but, your stated data format looks funny. 1 start bit is ok. 1 stop bit is ok. 8 data bits dictates no parity, not odd parity. Serial data bytes are 8 bits, not 11.

Sample code:

# Perl Polling Test # Title: Perl to chipKIT Serial Poll Test # Author: James M. Lynes, Jr. # Version: 1.0 # Creation Date: June 10, 2012 # Modification Date: June 10, 2012 use strict; use warnings; # Initialize the serial port - creates the serial port object $Arduino use Device::SerialPort::Arduino; my $Arduino = Device::SerialPort::Arduino->new( port => '/dev/ttyUSB0', baudrate => 9600, databits => 8, parity => 'none', ); while(1) { $Arduino->communicate('P'); # Send a poll print ($Arduino->receive(), "\n"); # Print poll respons +e sleep(1); # Delay until next p +oll }
package Device::SerialPort::Arduino; use strict; use warnings; use Time::HiRes; use Carp; use Device::SerialPort; use vars qw($VERSION); our $VERSION = '0.07'; sub new { my $class = shift; my $self = bless {}, $class; my %init = @_; # Sets many parameters for Device::SerialPort usage $self->{'port'} = $init{'port'}; $self->{'baudrate'} = $init{'baudrate'}; $self->{'databits'} = $init{'databits'}; $self->{'parity'} = $init{'parity'}; $self->{'stopbits'} = $init{'stopbits'}; $self->initialize(); return $self; } sub initialize { my $self = shift; $self->{'DSP'} = Device::SerialPort->new( $self->{'port'} ) or croak "Can't open " . $self->{'port'} . " - $!\n";

James

There's never enough time to do it right, but always enough time to do it over...


In reply to Re: How to read serial port with WIN32:SerialPort? by jmlynesjr
in thread How to read serial port with WIN32:SerialPort? by mastertone

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2024-03-29 11:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found