[Tutor] sending hex data on port

Magnus Lyckå magnus@thinkware.se
Wed Jun 18 20:59:01 2003


At 13:26 2003-06-18 -0500, vicki@stanfield.net wrote:
>I am working on a project which requires that I read
>data in from a file and send the hex equivalent out on
>the serial port. I have everything except how to send
>the data in hex format.

Exactly what is is you want to send?

An ASCII code representation of your numerical values
in hexadecimal representation, or actual numeric values?

If you want to send numeric values, it's pointless to
talk about them as hexadecimal. Below this paragraph there
are 18 asterisks if you count in hexadecimal, or 24 if you
count in decimal, but that is still the same amount.

* * * * * * * * * * * * * * * * * * * * * * * *

You can't have such a thing as a hexadecimal amount of
asterisks (or apples or pears for that matter). An amount
is an amount. It's only a symbolic representation that can
be hexadecimal. So, talking about hexadecimal or decimal
numbers only makes sense if you talk about a textual
representation of the numeric value. The numeric value knows
no representation of itself, any more than a colour knows the
words in different languages that are used to describe it.

>I have looked through a lot of
>apps but most are really more complicated than I am
>ready for. If I simply try to do this:
>
>port.write(hex(18))
>
>It translates the 1 to hex and then the 8 to hex.

Really? Not for me.

 >>> hex(18)
'0x12'

Note the '0x' prefix though. Maybe you want

 >>> hex(18)[2:]
'12'

But these are the hexadecimal representations of the

Or do you simply want to send port.write(0x18) i.e.
port.write(24) ?


--
Magnus Lycka (It's really Lyckå), magnus@thinkware.se
Thinkware AB, Sweden, www.thinkware.se
I code Python ~ The Agile Programming Language