[Tutor] Re: sending hex data on port

Lloyd Kvam pythontutor@venix.com
Wed Jun 18 15:18:12 2003


I am not clear as to what output you really want.

18 as a number = 12 in hex
1 8 as string = 31 38 in hex

Are either of those what you are trying to do?

Do you process one character at a time? strings? numbers?

vicki@stanfield.net wrote:
> On Wed, 18 Jun 2003 13:26:47 -0500 (EST),
> 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. 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. I
>>realize this is quite simplistic, but it is really all
>>I need to do. If I put '18', it complains about not
>>being able to convert a hex value to a hex value.
>>
>>Pardon my ignorance, but can someone please point me
> 
> in
> 
>>the right direction?
>>
>>--vicki
> 
> 
> Okay, sorry to reply to my own post, but I am still
> working on this. I tried something which I think is
> close to what I need. I am using binascii.
> 
> port.write(binascii.a2b_hex("18"))
> 
> Is this what I am supposed to be using to translate dec
> to hex?
> 
> --vicki
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 


-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice:	603-443-6155
fax:	801-459-9582