Going into this project, the Tormach-PLC interface was one of our biggest unknowns. Unlike a solenoid valve, there was not a clearly defined way to read and write commands to/from the Tormach using a PLC. And since we were not using a Tormach-brand robot arm, we couldn't simply write a Python script that interfaced between the Tormach and robot directly. Ultimately, these limitations led to some pretty creative solutions that allowed us to get around these problems for very cheap.
This interface only needed to do two things: send cycle start commands, and figure out when the cycle was done. Our initial idea for this was that we would send cycle start commands to the Tormach using a microcontroller programmed as a keyboard emulator (since the Tormach controller runs on a PC), and we would receive commands from the Tormach via the USB I/O Interface Kit, an add-on which Tormach sells for $300.
The first part of the idea worked well - we were able to buy an Arduino Leonardo clone for very cheap, and we programmed it to press Alt-R, the keyboard shortcut for cycle start, whenever an input pin went high. In order to control this via the PLC, we simply wired the Arduino ground and PLC ground together, and used a DC-DC converter to step the input voltage down from 24V (the PLC output voltage) to 5V (the desired Arduino input voltage).
Once we figured out our budget was going to be much smaller than we had hoped, we decided we needed to find a way to receive done commands without the Interface Kit. We found a Tormach forum post online discussing wiggling some GPIO pins on the Mesa 7i92, a FPGA board in the Tormach PC that runs the controller. Using this board post and the LinuxCNC documentation, we were able to write two custom M-Codes (M101 and M102) that flipped a specific GPIO pin high or low depending on which M-Code was used.
In order to interface this GPIO pin with the PLC, we needed to wire up a relay between the PLC's power and one of its input pins. We would then have the GPIO pin flip the relay - this would close the circuit and provide 24V to the input pin, setting its value to 1. However, the GPIO pin did not provide enough power to energize the coil inside the relay. To get around this, we designed a circuit in which the GPIO pin controlled a transistor, which then activated a 5V-1A power supply which flipped the relay, setting the input pin to 1.
The circuit for powering the relay via the Tormach PC's GPIO pin
The code for the custom M-Code to flip the GPIO pin