Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Pyserial question

Reply
Thread Tools

Re: Pyserial question

 
 
David Goodger
Guest
Posts: n/a
 
      01-05-2004
Kelia Nichols wrote:
> I am using Pyserial to work with a RS232 device. My question is,
> how do I write hex to the device or cannot write hex to it pyserial?


What do you mean exactly? Do you want to write a value in hex to the
RS232 port (e.g. write 26 [decimal] as "1A")? If so, just use string
formatting:

>>> "%02X" % 26

'1A'

Or do you want to send a byte for which you know the hex
representation (e.g. send "1A" as ASCII 26)? If so, use integer
conversion & character value conversion:

>>> chr(int('1a', 16))

'\x1a'

If it's more complex than that (values larger than 255, etc.), the
"struct" module may help. Post more details for better help.

-- David Goodger



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
pySerial question, setting certain serial parameters [newbie] Jean Dupont Python 2 02-08-2012 12:16 AM
Re: pyserial question Dennis Lee Bieber Python 0 06-19-2009 05:36 AM
Beginner Pyserial Question JAMoore84@gmail.com Python 3 01-24-2008 05:45 PM
pyserial with Mac and USB converter, possible? jorjun Python 1 01-08-2004 02:43 PM
Pyserial question Diez B. Roggisch Python 1 01-05-2004 03:59 PM



Advertisments