Giter Club home page Giter Club logo

Comments (6)

tino avatar tino commented on August 20, 2024

That is strange. What is the output?

I added this method to the tests and it passes...:

    def test_send_sysex_string(self):
        self.board.send_sysex(0x79, ["test"])
        sysex = (chr(0xF0), chr(0x79), 't', 'e', 's', 't', chr(0xF7))
        self.assert_serial(*sysex)

from pyfirmata.

anber500 avatar anber500 commented on August 20, 2024

I have tried the same code as @sunfffd and I'm also getting corrupt characters on my display.

@tino I have looked at your test and you are sending "0x79" to Firmata which is a firmware query.
"0x71" is the code for sending strings. I don't understand how your test can be accurate.

from pyfirmata.

anber500 avatar anber500 commented on August 20, 2024

I looked at the Firmata docs http://firmata.org/wiki/Protocol and according to the protocol spec, a string message must be 14-bits per char.
In pyfirmata.py, in the "send_sysex()" function, data is being send as 7-bits.
'Sysex data can be 7-bit bytes only. Consider using utils.to_two_bytes for bigger bytes.'

It seems like that could be the issues but I'm too noob with python to figure out how to use the "utils.to_two_bytes" function.

from pyfirmata.

anber500 avatar anber500 commented on August 20, 2024

I were able to figure it out :)
The chars need to be of 14-bits per char.

This can be send as per follows:
board.send_sysex(0x71, util.str_to_two_byte_iter("test message\0"))

If would be very nice if pyfirmata could do that for us.

def send_sysex(self, sysex_cmd, data=[]):
    """
    Sends a SysEx msg.

    :arg sysex_cmd: A sysex command byte
    :arg data: A list of 7-bit bytes of arbitrary data (bytes may be
        already converted to chr's)
    """
    #Convert strings to 14-bit chars. Also add a null terminator.
    if sysex_cmd == 0x71:
       data = str_to_two_byte_iter(data+"\0") 

    self.sp.write(chr(START_SYSEX))
    self.sp.write(chr(sysex_cmd))
    for byte in data:
        try:
            byte = chr(byte)
        except TypeError:
            pass # byte is already a chr
        except ValueError:
            raise ValueError('Sysex data can be 7-bit bytes only. '
                'Consider using utils.to_two_bytes for bigger bytes.')
        self.sp.write(byte)
    self.sp.write(chr(END_SYSEX))

Then we only need to call this:

self.board.send_sysex(0x71,"test")

This works fine and the string comes through as expected.

from pyfirmata.

tino avatar tino commented on August 20, 2024

Is this still a problem now that we are using byte arrays?

from pyfirmata.

tino avatar tino commented on August 20, 2024

Closing, as I can't move forward with this. Hopefully it's not a problem anymore!

from pyfirmata.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.