1313"""
1414import struct , threading , time
1515from xbee .frame import APIFrame
16- from xbee .python2to3 import byteToInt , intToByte
16+ from xbee .python2to3 import byteToInt , intToByte , stringToBytes
1717
1818class ThreadQuitException (Exception ):
1919 pass
@@ -181,6 +181,9 @@ def _build_command(self, cmd, **kwargs):
181181 try :
182182 # Read this field's name from the function arguments dict
183183 data = kwargs [field ['name' ]]
184+ if isinstance (data , str ):
185+ data = stringToBytes (data )
186+
184187 except KeyError :
185188 # Data wasn't given
186189 # Only a problem if the field has a specific length
@@ -205,9 +208,8 @@ def _build_command(self, cmd, **kwargs):
205208 "The data provided for '%s' was not %d bytes long" \
206209 % (field ['name' ], field ['len' ]))
207210
208- # Add the data to the packet, if it has been specified
209- # Otherwise, the parameter was of variable length, and not
210- # given
211+ # Add the data to the packet, if it has been specified.
212+ # Otherwise, the parameter was of variable length, and not given.
211213 if data :
212214 packet += data
213215
@@ -393,7 +395,6 @@ def send(self, cmd, **kwargs):
393395 # Pass through the keyword arguments
394396 self ._write (self ._build_command (cmd , ** kwargs ))
395397
396-
397398 def wait_read_frame (self ):
398399 """
399400 wait_read_frame: None -> frame info dictionary
0 commit comments