konimarti / opc

OPC DA client in Golang for monitoring and analyzing process data based on Windows COM.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Opc connections take a long time, two minutes at a time

HOULL2 opened this issue · comments

gbda_aut.dll is registered ,but when i ues the functions opc.NewConnection() it take two minutes at a time until connected

2019/08/19 13:12:35 Could not load OPC Automation object with wrapper OPC.Automation.1
2019/08/19 13:12:35 Loaded OPC Automation object with wrapper Graybox.OPC.DAWrapper.1
2019/08/19 13:12:35 Connecting to Kepware.KEPServerEX.V6 on node 127.0.0.1
2019/08/19 13:14:35 Connected.
2019/08/19 13:14:35 Transport [http] Listening on [::]:5218
2019/08/19 13:14:35 Broker [http] Connected to [::]:5219

Hi @HOULL2 your performance issue seems to be while the OLE connect function of the DLL is being called. Please also check out the closed issue #11 where a successful connection to an Kepware OPC sever can be established within seconds. Hence, I don't think the long connection time is package related. Maybe you can post your code and I'll have a look at it.

func opcconnect() error {
Println(handler.VarResult.Servers.Name)
Println(handler.VarResult.Servers.IP)
fopc.Debug()
var err error
handler.OpcClient, err = fopc.NewConnection(handler.VarResult.Servers.Name,
[]string{handler.VarResult.Servers.IP}, []string{})
if err != nil {
return err
}

return nil

}

func main() {
// New Service
service := micro.NewService(
micro.Name("go.micro.srv.opc"),
micro.Version("latest"),
)

// Initialise service
service.Init(
	micro.BeforeStart(func() error {

		if err := ReadXml(); err != nil {
			return err
		}

		if err := opcconnect(); err != nil {
			return err
		}
		return nil
	}),
)

// Register Handler
opcPb.RegisterOpcServiceHandler(service.Server(), new(handler.OpcServiceHandler))

go func() {
	ch := make(chan os.Signal, 1)
	signal.Notify(ch, os.Interrupt, syscall.SIGINT, os.Kill, syscall.SIGKILL, syscall.SIGTERM)
	select {

	case <-ch:
		Println("shutdown....")
		timeout := 5 * time.Second
		_, cancle := context.WithTimeout(context.Background(), timeout)
		//	defer cancel
		Println(cancle)
		//	app.Shutdown(ctx)
		handler.OpcClient.Close()
	}

}()
// Run service
if err := service.Run(); err != nil {
	log.Fatal(err)
}

}