Monday, April 6, 2015

Raspberry Pi getting data from a Koyo DL-06 using python


It was an interesting process to sniff and break apart the ECOM protocol. But with the help of Wireshark I was able to create a simple class to read/write Inputs,Outputs,V Memory, and C Memory Bits.  My class may look a bit hokey to those more skilled at python than I, but I've found it very usefull.

If you're stuck with an old generation H0-ECOM ethernet module and want to make use of it this post may be of use to you.  I was able to get a few from work as we phased in new gear.  We only had a couple ECOM-100 modules (ModbusTCP). So I was driven to get these working with my Raspberry Pi.

With mine I made a raspberry controlled sprinkler system using the Koyo DL-06 as my remote I/O.  There was no logic programmed into the PLC because I wanted my pi to control it 100%. But with this python code anyone could make a raspberry pi powered cheap HMI or web based HMI for their system.

Link to PythonKoyo library:
https://github.com/SimplyAutomationized/PythonKoyo/blob/master/Koyo.py

Example code:

import Koyo as plc

myKoyo = plc.Koyo('192.168.1.26')
myKoyo.WriteOutput(0,1) # write output Y0 to true, (if this isn't tied to any rung in the ladder it should turn on)
print myKoyo.ReadInput(5)
print myKoyo.ReadC(16) #this currently only returns data of the first 4 bytes of C Memory
if(myKoyo.ReadOutput(5)):
   myKoyo.WriteC(16,false)
else:
   myKoyo.WriteC(16,true)

#other helpful commands:
myKoyo.FindKoyo()          #return a list (ip,mac) of koyo plcs on the network
myKoyo.ChangeIP(mac,newIP) #change an ip address of a koyo that's plugged into your subnet

Hope this helps anyone with a Koyo. Other options are trying to install the C Library AutomationDirect provides on the website. I was unable to compile it and found this much more enjoyable.

No comments:

Post a Comment