I am fairly new to perl programming, but not new to programming. I am rusty however, as it has been a while. I have written several perl programs and am getting better at it.

BUT...

I am finding an extremely steep learning curve in figuring out how to do serial I/O under perl. I have the modules Win32-Serialport, Win32API-Commport, and have played with perl-GPS and Device-Davis (interfaces to Garmin GPS receivers, and Davis weather stations respectively). These seem *WAY* more complex than I need. Plus, I'm having a real dog of a time wrapping my brain around how they work, or more importantly, how to use them.

I have a Lexicon DC2 preamp in my media center. It is controllable via RS232, and I want to interface it to my home automation system using perl. It's communications protocol is very simple. Send it a few bytes representing a command, (say, select DVD player) look for an ack and exit. No protocol engine, no state machine, etc. It's essentially the same thing as communicating to it via IR (which is how my home automation system does it today) except it's two-way and you can inquire status, etc, as well as receive confirmation that commands worked. Plus you can control things that IR can't.

What I want to do is write a simple script that will take a literal command on the commandline (e.g. SelectDVD), translate it to the correct HEX string, output it to com1, wait for an ack, and then exit with a return code.

I can write it all quite easily except for the bit about sending the string out the serial port and looking for a response.

That learning curb again.

After several hours studying the topic, I decided to appeal to the monks for a leg up. Can anyone point me to some simple perl code that will accept a string of bytes, output it to a serial port, and return the answer, exiting with an error code if no answer is forthcoming within a second or so?

If so, you would be accomplishing two things. Helping a perl novice complete a useful program, and helping that same novice progress slowly toward enlightenment.

And I would be most appreciative.

Nathan


In reply to *extremely* simple Serial I/O by wa4otj

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.