Open mfassler opened 5 years ago
On Sun, 14 Apr 2019, Mark Fassler wrote:
If I set tune2=b'' then the struct.pack() statement seems to do the correct thing.
Here's what MAVProxy does (near enough to canonical use case at the moment...):
def cmd_playtune(self, args):
'''send PLAY_TUNE message'''
if len(args) < 1:
print("Usage: playtune TUNE")
return
tune = args[0]
str1 = tune[0:30]
str2 = tune[30:]
if sys.version_info.major >= 3 and not isinstance(str1, bytes):
str1 = bytes(str1, "ascii")
if sys.version_info.major >= 3 and not isinstance(str2, bytes):
str2 = bytes(str2, "ascii")
self.master.mav.play_tune_send(self.settings.target_system,
self.settings.target_component,
str1, str2)
(from https://github.com/ardupilot/MAVProxy/blob/master/MAVProxy/modules/mavproxy_misc.py#L257)
The default argument for strings has been fixed in master. This issue can probably be closed.
Hello,
I'm trying to run this code:
The command
vehicle.play_tune()
fails with the following error:If I manually construct the message myself, specifying
tune2=b''
, it works.I believe this is because the generator is interpreting the message datatype of
char[200]
as an array of 200 strings, like this:tune2=['', '', '', '' ... '', '']
which is incorrect for Python3.If I set
tune2=b''
then the struct.pack() statement seems to do the correct thing.