Handling the Physical Layer
Dealing with ground loops on a factory floor is a quick way to kill a Raspberry Pi. Instead of building a custom opto-isolator circuit on a breadboard, I just used a commercial Valtoris unit to act as the transparent bridge. It handles all the messy RS485 timings in hardware, so my Python script only has to worry about clean TCP packets.
Christopher.Scott