but it prints and runs forever in IDLE. What gives ? I may very well have set up some horrible recursive environment variables or something in Windows 10… that’s the only thing I can think of. What say you ?
you would have to do something to x to get out of the while loop:
x=10
while x == 10:
print(x)
x += 1
Touch waits until the script is done in 1 frame - so in the case of your while loop, it will never leave the frame and lock up.
Instead can you use an Execute DAT and execute the script every frame?
so if my script is big what is the ‘best practice’ besides tabbed cutting and pasting within:
def frameStart(frame):
return
?
Is there an efficient way for me to call a remote script each frame, that will start at my ‘while 1’ loop(rather than at beginning of script)? I tabbed/pasted a big script under frameStart but Im still locking up and de-bugging. The script involves a python-opened serial/USB port and im trying to send an updated variable each frame(within ‘while 1’ loop.) . For the sake of speed im trying to keep my serial connections open and available.
It’s a bit hard to judge your code without knowing what is in there, but if you mainly want to send a variable out of your serial port each frame, why not simply use a Serial DAT? Then you only need this line of Python to send out a message, which is quite fast:
You can’t do “while 1” loops. TouchDesigner is single-threaded, so once you’re in a while loop, TouchDesigner is only computing that while loop, if you never leave the while loop, TouchDesigner never continues running. For serial, do what nettoyeur said. For other things that you need something running every frame, put it in the Execute DAT frameStart() callback, but no while 1 loops.
thanks for the input(s).
I have been dabbling with serial DAT, but since a whole bunch of the example code for these motors I’m working with was Python I was trying to integrate some of that , en masse.
I keep going back and forth between trying to to send serial HEX command packets and trying to hook into the work that others have done already in Python.
Third method is probably me developing my own ‘packets’ in hex or ASCII and sending via serial DAT.
thks for the words.
back to the lab!
If you’re in a situation where you have a bunch of python code and don’t want to port it, we’ve had a lot of success running a local TCP server in a Python applet with all your python code, then use TCPIP Dat in TouchDesigner, connect to your TCP server and then just send json data back and forth to trigger commands in the Python applet. There’s a lot of really easy examples of setting up Python TCP server/client and sending messages between them.
What do you think about using a python applet with UDP client/server with TD instead? I dont know why im trying to complicate a proven suggestion(thanks!), other than my dyslexic brain hurts , and Im growing weary of learning yet another set of syntax I already understand UDP pretty good.
maybe I shouldnt fear the json/TCPIP. I just really struggle with juggling mutliple symbols across various languages.
You can use whichever you like. Wouldn’t really make a difference. I went with TCP/json since we’re used to it all and there were a lot of examples on setting up a tcp server really quickly, so didn’t end up being much work.
So I got a decent UDP connection going, then realized I wanted it to go bidirectional and rather than figure out how to have UDP send/receive in the same applet- I went back to exploring TCPout. UDP seemed to actually be less inclined to ‘break’ - perhaps because its not attempting to ‘guarantee delivery’ ? I find the tcp connection is buffering somewhere,creating lag and backlog and I’m wondering if there are flags/parameters in python socket that will stop or minimize this buffering behavior. Otherwise I may go back to UDPout. Not sure if I want/need to guarantee all my messages are ‘delivered’ -lots of experimenting to do.
Another thought I gleaned from my reading - what about shared memory? Seems like TD offers a shared chop or a top.Can this be accessed in my Python applet ? Would this have speed advantages over tcp or udp ? I can see my commands quickly being non-integers though - i suppose there is a way to stuff ascii or hex into a TOP,(or convert chars to ints ?) but this is sounding overly complicated. Seems like i need an array of shared data- a shared chop is just a single shared int ?
essentially i am driving position of a ‘smart servo’ with TD by sending goal position to an applet, which then makes control packets and sends them rs485. I would just go serial out with a control packet that changes the register in the servo, but this requires CRC16 calc, which i haven’t quite figured out how to generate(despite having formula), and also there’s a lot of servo network bus stuff