Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

how to convert data from a serial port read...

by tachekent (Acolyte)
on Dec 03, 2002 at 03:12 UTC ( #217112=perlquestion: print w/replies, xml ) Need Help??

tachekent has asked for the wisdom of the Perl Monks concerning the following question:

O monks,
I have a serial device (a scrolling led sign to be precise) which I can send text to. It also has a buffer, which I can read the current length of. Both of these things I have managed to do in windows and freeBSD using (respectively) Win32::SerialPort and Dev::SerialPort.

I am trying to work out how to change the output (which should be the number of bytes in the buffer) into a readable form that I can test things against; From my windows monitoring it seems that the device is returning hex in the form:

00 3e
00 23
00 0c

I know this output to be the number of bytes in the buffer, however, when I capture it with $PortObject->read, and try to print it out I get unicode characters. I've tried using hex() and ord() but both convert all output to 0.

How can I convert my hex into decimal?

  • Comment on how to convert data from a serial port read...

Replies are listed 'Best First'.
Re: how to convert data from a serial port read...
by dws (Chancellor) on Dec 03, 2002 at 03:24 UTC
    If you have a string of bits, and want an ASCII representation of them, there are a couple of ways to go, but the easiest is to avail yourself of unpack().     $hex = unpack("H*", $bits); will give you data in hex. If instead you want numbers, unpack() will do that, too.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://217112]
Approved by ybiC
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2022-08-08 19:30 GMT
Find Nodes?
    Voting Booth?

    No recent polls found