[Tutor] Re: sending hex data on port
Jeff Shannon
jeff@ccvcorp.com
Thu Jun 19 14:11:49 2003
vicki@stanfield.net wrote:
>>What module are you using? Does it make sense to say
>>port.write(chr(24))?
>>
>>
>
>That might be it. Is there a function that
>automatically translates between the 0x18 and the chr
>value that I need? I understand how you got the value
>and could write my own, but if it already exists.....
>
>
This depends on exactly what form you have the 0x18 in. You can simply
use port.write(chr(0x18)), but I'm guessing that you want to send the
contents of a variable, not a constant. :) If you have a variable, c,
which already contains the number 0x18, you can do port.write(chr(c)).
If c is, instead, the string "18", and you want to interpret that as a
hex value, then you can use the radix option of int() --
port.write(chr(int("18", 16))). In essence, your problem now is a
matter of figuring out how to convert your data source into a series of
integers, one for each byte you wish to send.
Jeff Shannon
Technician/Programmer
Credit International