|
|
| Welcome to the Monastery | |
| PerlMonks |
Re: serial port hex onlyby Marshall (Prior) |
| on Apr 26, 2012 at 21:59 UTC ( #967472=note: print w/ replies, xml ) | Need Help?? |
|
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. 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 Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||