Skip to content

Commit

Permalink
feat(plc4go/plc4xbrowser): add support for opcua
Browse files Browse the repository at this point in the history
  • Loading branch information
sruehl committed Aug 7, 2023
1 parent b8b888a commit 2fea480
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
6 changes: 6 additions & 0 deletions plc4go/pkg/api/drivers/drivers.go
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/apache/plc4x/plc4go/internal/eip"
"github.com/apache/plc4x/plc4go/internal/knxnetip"
modbus2 "github.com/apache/plc4x/plc4go/internal/modbus"
"github.com/apache/plc4x/plc4go/internal/opcua"
"github.com/apache/plc4x/plc4go/internal/s7"
"github.com/apache/plc4x/plc4go/pkg/api"
"github.com/apache/plc4x/plc4go/pkg/api/config"
Expand Down Expand Up @@ -75,6 +76,11 @@ func RegisterModbusAsciiDriver(driverManager plc4go.PlcDriverManager, _options .
transports.RegisterTcpTransport(driverManager)
}

func RegisterOpcuaDriver(driverManager plc4go.PlcDriverManager, _options ...config.WithOption) {
driverManager.RegisterDriver(opcua.NewDriver(converter.WithOptionToInternal(_options...)...))
transports.RegisterTcpTransport(driverManager)
}

func RegisterS7Driver(driverManager plc4go.PlcDriverManager, _options ...config.WithOption) {
driverManager.RegisterDriver(s7.NewDriver(converter.WithOptionToInternal(_options...)...))
transports.RegisterTcpTransport(driverManager)
Expand Down
8 changes: 8 additions & 0 deletions plc4go/tools/plc4xbrowser/ui/actions.go
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/apache/plc4x/plc4go/internal/ads"
"github.com/apache/plc4x/plc4go/internal/bacnetip"
"github.com/apache/plc4x/plc4go/internal/cbus"
"github.com/apache/plc4x/plc4go/internal/opcua"
"github.com/apache/plc4x/plc4go/internal/s7"
plc4go "github.com/apache/plc4x/plc4go/pkg/api"
"github.com/apache/plc4x/plc4go/pkg/api/transports"
Expand Down Expand Up @@ -117,6 +118,13 @@ func registerDriver(driverId string) error {
transports.RegisterTcpTransport(driverManager)
tcpRegistered = true
}
case "opcua":
driver = opcua.NewDriver()
driverManager.RegisterDriver(driver)
if !tcpRegistered {
transports.RegisterTcpTransport(driverManager)
tcpRegistered = true
}
default:
return errors.Errorf("Unknown driver %s", driverId)
}
Expand Down
2 changes: 1 addition & 1 deletion plc4go/tools/plc4xbrowser/ui/common.go
Expand Up @@ -29,7 +29,7 @@ import (
"time"
)

const protocols = "ads,bacnetip,c-bus,s7"
const protocols = "ads,bacnetip,c-bus,opcua,s7"

var protocolList = strings.Split(protocols, ",")

Expand Down
5 changes: 5 additions & 0 deletions plc4go/tools/plc4xbrowser/ui/config.go
Expand Up @@ -26,6 +26,7 @@ import (
"gopkg.in/yaml.v3"
"os"
"path"
"sync"
"time"
)

Expand Down Expand Up @@ -83,7 +84,11 @@ func LoadConfig() {
}
}

var saveMutex sync.Mutex

func saveConfig() {
saveMutex.Lock()
defer saveMutex.Unlock()
config.LastUpdated = time.Now()
f, err := os.OpenFile(configFile, os.O_RDWR|os.O_CREATE, 0755)
if err != nil {
Expand Down

0 comments on commit 2fea480

Please sign in to comment.