http://www.perlmonks.org?node_id=967472


in reply to serial port hex only

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!