Sending serial commands using ChopExec

Not really a coder, but just wondering if anyone can help me implement this code into TD.

def bytes(num):
return hex(num >> 8), hex(num & 0xFF)

I have a slider with a math op that goes from 0 to 65535. the slider gives a value “num” and that “num” will split it’s value into two hex by the given code above.

the final print packet will go something like this:
0x43 (constant header) + 100 (address that’s an integer or hex) + num1 (1st part of def bytes(num)) + num2 (2nd part of def bytes(num)) + terminator = 0xFF, 0xEE, 0xFF, 0xEE.

would please anyone help me please. I have the concept down, but not really versed into python coding. thank you very much for your time.

Might be something like:

n.sendBytes( 0x43, 100, num>>8, num&0xff, 0xFF, 0xEE, 0xFF, 0xEE)
where n points to the output OP you’ve set up.

Note the arguments to sendBytes are numeric, so they can be expressed as decimal, or hexadecimal.

Your bytes function, on the other hand returns an actual string (example “0x1” for 1), which is incompatible.

Cheers,
Rob.

FIGURED IT OUT!!! WHOOPPPEEEE!

thank you very much! I’ve been at it with this servo motor and TouchDesigner for months now. I’ve actually figured it out. it’s basically n.sendBytes(bytes())

this is for a follow focus motor. made it talk to TouchDesigner so we can actually automate follow focus for precise, repeatable shots. if any of you want the .toe file, let me know :wink:

Congrats! If you want to share your followfocus module I would be happy to publish it on chopchopchop.org/

I would love to check out the .toe file! I’ve been trying to get a servo array moving around to artnet data.