Re: Pyserial question

Discussion in 'Python' started by David Goodger, Jan 5, 2004.

  1. 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
    David Goodger, Jan 5, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Diez B. Roggisch

    Pyserial question

    Diez B. Roggisch, Jan 5, 2004, in forum: Python
    Replies:
    1
    Views:
    389
    Kelia Nichols
    Jan 5, 2004
  2. jorjun
    Replies:
    1
    Views:
    627
    John P. Speno
    Jan 8, 2004
  3. Replies:
    3
    Views:
    395
  4. Dennis Lee Bieber

    Re: pyserial question

    Dennis Lee Bieber, Jun 19, 2009, in forum: Python
    Replies:
    0
    Views:
    637
    Dennis Lee Bieber
    Jun 19, 2009
  5. Jean Dupont
    Replies:
    2
    Views:
    319
    Peter
    Feb 8, 2012
Loading...

Share This Page