A complete golang implementation of Ethernet/ip protocol.
This repository contains:
- A implementation of ethernet/ip protocol.
- A lightweight message router.
- Session management.
- A lightweight api interface makes you don't need to focus binary steam.
- Examples of go-ethernet-ip.
go-ethernet-ip
started with the my own project goplc which used for communication with rockwell control/compactLogix PLCs.
I separate common industrial protocol from ethernet/ip.
If your communication protocol is common industrial protocol, you should move to go-cip which base on this repository.
This project uses golang. Go check them out if you don't have them locally installed.
$ go get github.com/loki-os/go-ethernet-ip
Also go modules is supported.
I use some cip cases for demonstration.
Before you use these cases.You should block your main thread.Because all logic run in go routine.
func block(){
some_case()
// you'd better find other way to do this. Sleep is not recommended.
time.Sleep(time.Second * 10)
}
Before we start to communication with other device, we need to find them via lan. If you have clear ip skip this step.
devices, err := GetLanDevices(time.Second)
device, err := NewDevice("192.168.0.100")
Device Connect() is optional.You can skip this step to use default config.
Connect() should be call before other function, otherwise it will fail.
cfg := DefaultConfig()
cfg.TCPTimeout = time.Second * 5
device.Connect(cfg)
identity, err := device.ListIdentity()
interface, err := device.ListInterface()
services, err := device.ListServices()
device.SendRRData(cpf *commonPacketFormat, timeout typedef.Uint)
device.SendUnitData(cpf *commonPacketFormat, timeout typedef.Uint)
device.Disconnect()
Feel free to dive in! Open an issue or submit PRs.
MIT © 末日上投