Commits

Tino de Bruijn committed f186d49

Fixed send_sysex method. Values passed should be 7-bit bytes beforehand. Removed send_sysex from Pin as it is not logical to have it there, and it can always be accessed by Pin.board.send_sysex

Comments (0)

Files changed (2)

pyfirmata/pyfirmata.py

         Sends a SysEx msg.
         
         :arg sysex_cmd: A sysex command byte
-        :arg data: A list of data values
+        :arg data: A list of 7-bit bytes of arbitrary data
         """
         self.sp.write(chr(START_SYSEX))
         self.sp.write(chr(sysex_cmd))
             try:
                 byte = chr(byte)
             except ValueError:
-                byte = chr(byte >> 7) # TODO send multiple bytes
+                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))
         
                 msg += chr(value % 128)
                 msg += chr(value >> 7)
                 self.board.sp.write(msg)
-                
-    def send_sysex(self, sysex_cmd, data=[]):
-        """
-        Sends a SysEx msg.
-        
-        :arg sysex_cmd: A sysex command byte
-        :arg data: A list of data values
-        """
-        # TODO make the boards send_sysex available to the pin
-        self.board.sp.write(chr(START_SYSEX))
-        self.board.sp.write(chr(sysex_cmd))
-        for byte in data:
-            try:
-                byte = chr(byte)
-            except ValueError:
-                byte = chr(byte >> 7) # TODO send multiple bytes
-            self.board.sp.write(byte)
-        self.board.sp.write(chr(END_SYSEX))
         
     def servo_config(self, min_pulse, max_pulse, angle=0):
         """
         sysex = (chr(0xF0), chr(0x79), chr(1), chr(2), chr(3), chr(0xF7))
         self.assert_serial(*sysex)
         
+    def test_send_sysex_to_big_data(self):
+        self.assertRaises(ValueError, self.board.send_sysex, 0x79, [256, 1])
+        
     def test_receive_sysex_message(self):
         sysex = (chr(0xF0), chr(0x79), chr(2), chr(1), 'a', '\x00', 'b', 
             '\x00', 'c', '\x00', chr(0xF7))