Hi Wolfgang,
I'll try to help with that as I'm the one who created it.
If you have a look at the examples, you should see how to do this.
In general you add the following:
- Add this to your go.mod:
github.com/apache/plc4x/plc4go v0.0.0-20210216155100-5b8708f70b7c
(Right now I'd stick to the latest snapshot)
- You create an instance oft he DriverManager:
driverManager := plc4go.NewPlcDriverManager()
- You manually add the drivers and transports you need (might change that to
just adding the driver and the drivers then add the transports they need):
driverManager.RegisterDriver(modbus.NewModbusDriver())
driverManager.RegisterDriver(knxnetip.NewKnxNetIpDriver())
driverManager.RegisterTransport(udp.NewUdpTransport())
driverManager.RegisterTransport(tcp.NewTcpTransport())
- You get a connection:
crc := driverManager.GetConnection("modbus:tcp://192.168.23.30")
// Wait for the driver to connect (or not)
connectionResult := <-crc
if connectionResult.Err != nil {
fmt.Printf("error connecting to PLC: %s",
connectionResult.Err.Error())
return
}
connection := connectionResult.Connection
- You ensure the connection is closed at the end:
defer connection.BlockingClose()
- You read something:
// Prepare a read-request
rrb := connection.ReadRequestBuilder()
rrb.AddItem("field", "holding-register:26:REAL")
readRequest, err := rrb.Build()
if err != nil {
fmt.Printf("error preparing read-request: %s",
connectionResult.Err.Error())
return
}
// Execute a read-request
rrc := readRequest.Execute()
// Wait for the response to finish
rrr := <-rrc
if rrr.Err != nil {
fmt.Printf("error executing read-request: %s", rrr.Err.Error())
return
}
// Do something with the response
if rrr.Response.GetResponseCode("field") != model.PlcResponseCode_OK {
fmt.Printf("error an non-ok return code: %s",
rrr.Response.GetResponseCode("field").GetName())
return
}
value := rrr.Response.GetValue("field")
As I mentioned ... there are some examples in the "plc4go/examples" directories.
Hope that helps.
But keep in mind PLC4Go is fresh and new. Right now weh ave only Modbus and KNX
drivers in go, but we're working hard on porting more drivers and extending
features. Help greatly appreciated with that ;-)
Chris
-----Ursprüngliche Nachricht-----
Von: Wolfgang Huse <[email protected]>
Gesendet: Donnerstag, 18. Februar 2021 09:30
An: [email protected]
Betreff: plc4Go Internal Packages
Hello. i try to add the PLC4Go Framework within one of my projects but I am not
able to use it as there are INTERNAL Modules I am not allowed to use out of the
Project-Scope. Can anybody give me a hint how to add plc4go to a custom project
?
Regards,
Wolfgang