I keep putting off a project to use this thing. But I did look at Win32::SerialPort docs.

I have written binary data to disk files before. One way, open file, set binmode, use syswrite() to write a binary buffer. Looks like something similar can be done here. You don't say how you are doing the write, but if you are using tied file handles, I would : binmode FH; and then use syswrite(). There are some examples in the docs. The buffer that syswrite uses are bytes, so you need to think about pack and unpack if you are say trying to send something that is not already a binary byte.

Update: This makes a binary file on my machine. I always have to stare at pack a long time to get it right - so I did something simple here - however it did work. I'd suggest using a disk file like this sort of thing to get the "right incantation" to generate the binary write sequence that you need based on the values that you want to send for testing, then see if you can do the same thing on the serial port.

#!/usr/bin/perl -w use strict; open FH, ">", "testingbin" or die "unable to open testingbin $!"; binmode FH; foreach (1,2,3,4,5,6,7,8,9) { my $buf = chr($_); syswrite FH,$buf; } close FH; __END__ my text editor says: 0102030405060708 09 as binary bytes
My Update to your Update:

Yes, this transmit one char at a time thing looks fine and is similar to the above test code. The pack and unpack functions can generate/decode a whole buffer (maybe many KB) of stuff that can be sent/received at one time. This makes a difference when mucking around with big binary files like maybe .WAV files, but sounds like your serial port application will do just fine reading or writing a character at a time - computers are so fast nowadays that it will keep up with the serial port at even a high baud rate.

PS: Welcome to Perl! This stuff is just amazing!


In reply to Re: serial port hex only by Marshall
in thread serial port hex only by ccherri

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.