You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@plc4x.apache.org by Wolfgang Huse <wo...@nutanix.com> on 2021/02/18 08:30:03 UTC
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
AW: plc4Go Internal Packages
Posted by Wolfgang Huse <wo...@nutanix.com>.
Yes… now it works as expected!
Thanks!
Mit freundlichen Grüßen – With kind regards
Wolfgang Huse
Von: Christofer Dutz <ch...@c-ware.de>
Datum: Freitag, 19. Februar 2021 um 08:32
An: dev@plc4x.apache.org <de...@plc4x.apache.org>
Betreff: AW: plc4Go Internal Packages
Hi all,
I was a bit confused as I'm using PLC4Go in a project outside of PLC4Go itself and there it worked.
However I registered the transports and drivers differently. I just updated the examples.
The helpers have allways been there, I just didn't use them in the Go examples.
Sorry for the confusion.
Chris
-----Ursprüngliche Nachricht-----
Von: Otto Fowler <ot...@gmail.com>
Gesendet: Freitag, 19. Februar 2021 00:05
An: dev@plc4x.apache.org
Betreff: Re: plc4Go Internal Packages
This is a bug I think.
The modbus package is internal, this cannot be used outside the package.
If you have to register it using a class from the module ( and not by name for example ) that will never work.
You should log a jira issue for this, maybe with an attached, simple project.
> On Feb 18, 2021, at 11:32, Wolfgang Huse <wo...@nutanix.com> wrote:
>
> Yes… theoretically i am able to run the Examples within your Project-Structure… but as soon as I create my own Project this error occurs:
> hello_world_plc4go_read.go:23:2: use of internal package github.com/apache/plc4x/plc4go/internal/plc4go/modbus not allowed
>
> Regards,
> Wolfgang
AW: plc4Go Internal Packages
Posted by Christofer Dutz <ch...@c-ware.de>.
Hi all,
I was a bit confused as I'm using PLC4Go in a project outside of PLC4Go itself and there it worked.
However I registered the transports and drivers differently. I just updated the examples.
The helpers have allways been there, I just didn't use them in the Go examples.
Sorry for the confusion.
Chris
-----Ursprüngliche Nachricht-----
Von: Otto Fowler <ot...@gmail.com>
Gesendet: Freitag, 19. Februar 2021 00:05
An: dev@plc4x.apache.org
Betreff: Re: plc4Go Internal Packages
This is a bug I think.
The modbus package is internal, this cannot be used outside the package.
If you have to register it using a class from the module ( and not by name for example ) that will never work.
You should log a jira issue for this, maybe with an attached, simple project.
> On Feb 18, 2021, at 11:32, Wolfgang Huse <wo...@nutanix.com> wrote:
>
> Yes… theoretically i am able to run the Examples within your Project-Structure… but as soon as I create my own Project this error occurs:
> hello_world_plc4go_read.go:23:2: use of internal package github.com/apache/plc4x/plc4go/internal/plc4go/modbus not allowed
>
> Regards,
> Wolfgang
Re: plc4Go Internal Packages
Posted by Otto Fowler <ot...@gmail.com>.
This is a bug I think.
The modbus package is internal, this cannot be used outside the package.
If you have to register it using a class from the module ( and not by name for example ) that will never work.
You should log a jira issue for this, maybe with an attached, simple project.
> On Feb 18, 2021, at 11:32, Wolfgang Huse <wo...@nutanix.com> wrote:
>
> Yes… theoretically i am able to run the Examples within your Project-Structure… but as soon as I create my own Project this error occurs:
> hello_world_plc4go_read.go:23:2: use of internal package github.com/apache/plc4x/plc4go/internal/plc4go/modbus not allowed
>
> Regards,
> Wolfgang
AW: plc4Go Internal Packages
Posted by Wolfgang Huse <wo...@nutanix.com>.
Yes… theoretically i am able to run the Examples within your Project-Structure… but as soon as I create my own Project this error occurs:
hello_world_plc4go_read.go:23:2: use of internal package github.com/apache/plc4x/plc4go/internal/plc4go/modbus not allowed
Regards,
Wolfgang
AW: plc4Go Internal Packages
Posted by Christofer Dutz <ch...@c-ware.de>.
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 <wo...@nutanix.com>
Gesendet: Donnerstag, 18. Februar 2021 09:30
An: dev@plc4x.apache.org
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