Furthermore, depending on the complexity of the protocol of your controller, Tcl/Tk has an extension called Expect that's all about saying "wait for this, then send that, then wait for this, and then send that".