Greeting fellow monks!

I have been trying to write a bit of perl to talk to a piece of equipment at work. I'm fortunate enough that the manufacturer has thouroughly documented the protocol to issue commands and talk to the instrument. I believe I've narrowed the problem to the mysterious pack function.

I'd like to send the hex:

CA 00 01 00 00 FE

Over the serial port (pretty sure I've got the serial port working, thanks to Win32::SerialPort). I'm actually using a little USB to serial converter that comes with a nice little monitor utility that can show the hex dump of what goes over the port. Here's the code I've come up with so far:

#! C:\perl\bin\perl.exe use strict; use warnings; use Win32::SerialPort; my $port_name = 'COM4'; my $config_file = 'thermo.cfg'; my $port = new Win32::SerialPort($port_name, $config_file) || die "Una +ble to open: $^E\n"; my $status = pack('HHHHHH', 'ca', '00', '01', '00', '00', 'fe'); $port->write($status."\n"); sleep 1; my $result = $port->input; print "result = $result\n"; $port->close || warn "Close Failed!\n"; undef $port;

The script executes fine with no results to speak of, but the port monitor sees:

00009 8 (351.485.411): TX: C0 00 00 00 F0 00

I've been through the limited amount of examples and tutorials that I could find on Win32::SerialPort but to no avail. I loved process control in college and would love to learn how to control process equipment with perl! (Who needs LabVIEW? is where I'd like to be able to go with it.)

Any insights would be greatly appreciated. Thanks!


In reply to Sending and reading hex commands on a Win32 serial port by c4onastick

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.