How can i send 8-bit data or binary data with pyserial?

Discussion in 'Python' started by ouz as, Dec 13, 2004.

  1. ouz as

    ouz as Guest

    hi,

    I want to transfer 0 bit and 1 bit in order with pyserial.But pyserial only
    send string data.
    Can anyone help me?
    Sorry about my english..

    _________________________________________________________________
    Depolama alani sikintisindan kurtulun - hemen Hotmail'e üye olun!
    http://odeme.hotmail.com.tr
     
    ouz as, Dec 13, 2004
    #1
    1. Advertising

  2. Hi !

    1 byte is 8 bits. If you want to manage bits, one by one, you can rewrite a
    protocol, and replace pyserial.

    Have a good day
    --
    Michel Claveau
     
    Michel Claveau - abstraction méta-galactique non t, Dec 13, 2004
    #2
    1. Advertising

  3. "ouz as" <> wrote in message
    news:...

    > I want to transfer 0 bit and 1 bit in order with pyserial.But pyserial only
    > send string data.


    string _is_ the type one would normally use in Python for 8-bit
    encoded data. If you are a Unicode purist, that's perhaps
    all you would use it for.

    If you have a list [11, 22, 33] of bytes to send, you can write:
    buffer = [chr(i) for i in [11, 22, 33]]

    Or possibly, use the struct or array module. Either way, the
    problem you have to solve is converting the format you have
    to/from an appropriate string. We lack the detail to suggest the
    best solution to that.
     
    Richard Brodie, Dec 13, 2004
    #3
  4. > I want to transfer 0 bit and 1 bit in order with pyserial.But pyserial
    > only send string data.


    Convert your data to numbers and use module struct to create strings out of
    it.

    Apart from that: You can only send chunks of bits as configured in your
    serial settings - e.g. 8N1 means that you will have to send 8 Bits in a
    row. I personally never used anything else, but it might be possible to
    alter that setting to lets say 7N1 or even lower numeber - but I doubt that
    this will work down to 1N1.

    If you give us more details on your actual problem, we migh be able to give
    better answers.
    --
    Regards,

    Diez B. Roggisch
     
    Diez B. Roggisch, Dec 13, 2004
    #4
    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. Fangs
    Replies:
    3
    Views:
    9,953
    darshana
    Oct 26, 2008
  2. alastair

    pyserial with binary data

    alastair, Nov 26, 2004, in forum: Python
    Replies:
    3
    Views:
    1,500
    Grant Edwards
    Nov 30, 2004
  3. ouz as
    Replies:
    1
    Views:
    966
    Diez B. Roggisch
    Dec 14, 2004
  4. Fredrik Lundh
    Replies:
    1
    Views:
    4,148
    Scott David Daniels
    Dec 15, 2004
  5. Replies:
    12
    Views:
    610
    Richard Heathfield
    Apr 8, 2007
Loading...

Share This Page