-4

Following Java code creates a message I can write to an arduino serial port to control a robotic arm:

public static byte[] uArmMessage(short armRot, short armStr, short armHt, short handAng, boolean ctlData){
   byte[] msg ={(byte)0xFF,(byte)0xAA,(byte)((armRot>>8) 0xFF),
      (byte)(armRot&0xFF),(byte)((armStr>>8)&0xFF),
      (byte)(armStr&0xFF),(byte)((armHt>>8)&0xFF),
      (byte)(armHt&0xFF),(byte)((handAng>>8)&0xFF),
      (byte)(handAng&0xFF),(byte)(ctlData ? 1 : 2)};
   return msg;
}

I need help writing this function in python. If someone could explain to me how exactly i get the output from this function into an arduino I would also really appreciate it!

if it is any help I have a PDF that explains the Communication Protocol being used.

if this is not the place for this kind of question, could someone reefer me to somewhere more fitting?

Community
  • 1
  • 1

1 Answers1

1
msg =[0xFF,0xAA,((armRot>>8)& 0xFF),
      (armRot&0xFF),((armStr>>8)&0xFF),
      (armStr&0xFF),((armHt>>8)&0xFF),
      (armHt&0xFF),((handAng>>8)&0xFF),
      (handAng&0xFF),(1 if ctlData else 2)];

s = serial.Serial("COM5",9600)
s.write("".join(map(chr,msg)))

basically it was just a matter of remove all the (Byte) and replaceing {} with [] ....

Joran Beasley
  • 110,522
  • 12
  • 160
  • 179