konimarti / opc

OPC DA client in Golang for monitoring and analyzing process data based on Windows COM.
MIT License
237 stars 85 forks source link

Crash on working with remote node #2

Closed panter-dsd closed 5 years ago

panter-dsd commented 5 years ago

I trying to connect to the remote server.

client := opc.NewConnection(
        "Prosys.OPC.Service", // ProgId
        []string{"192.168.7.51"}, //  OPC servers nodes
        []string{"Bucket Brigade.ArrayOfReal8"},
    )
defer client.Close()

And I get a panic:

panic: TryConnect was not successful: Connection failed

goroutine 1 [running]:
github.com/konimarti/opc.NewConnection(0x83bbd0, 0x12, 0xc0000331b0, 0x1, 0x1, 0xc00003d500, 0x62, 0x62, 0x853678, 0xc00006c000)
    C:/projects/opcda2opcua/src/github.com/konimarti/opc/connection_windows.go:335 +0x269
main.main()
    C:/projects/opcda2opcua/src/gitlabinternal.litmusloop.com/loop-edge/opcda2opcua/main.go:10 +0xec

What I was doing wrong? Matrikon Explorer works with this server.

konimarti commented 5 years ago

Hi @panter-dsd sorry that you ran into trouble. We have this code running successfully with multiple remote hosts. Can you double-check that the ProgId and IP address are correct for your case? If you print out some more debug-related information by adding "opc.Debug()" before the opc.NewConnection call, we might get a better understanding where the problem lies. Thanks!

panter-dsd commented 5 years ago

Thank you for your answer! Yes, I rechecked and all correct. I didn't know about Debug, so:

2019/05/01 11:13:06 Could not load OPC Automation object with wrapper OPC.Automation.1
2019/05/01 11:13:06 Loaded OPC Automation object with wrapper Graybox.OPC.DAWrapper.1
2019/05/01 11:13:06 Connecting to Prosys.OPC.Service on node 192.168.7.51
2019/05/01 11:13:06 Connection failed.
panic: TryConnect was not successful: Connection failed
panter-dsd commented 5 years ago

image

konimarti commented 5 years ago

I just did some testing with the Prosys OPC Simulation server and I could reproduce your error:

2019/05/01 20:47:20 Loaded OPC Automation object with wrapper Graybox.OPC.DAWrapper.1
2019/05/01 20:47:20 Connecting to Prosys.OPC.Service on node localhost
2019/05/01 20:47:20 Connection failed.
panic: TryConnect was not successful: Connection failed

The solution is to set GOARCH to 386 before compiling your code, i.e. in Powershell enter: $ENV:GOARCH=386 With this, it does what it should:

2019/05/01 20:47:48 Loaded OPC Automation object with wrapper Graybox.OPC.DAWrapper.1
2019/05/01 20:47:48 Connecting to Prosys.OPC.Service on node localhost
2019/05/01 20:47:48 Connected.
map[Random.PsFloat1:92.0137066859752]

I tested it on my local machine but it should work remotely as well. I think it's a 32/64 issue somewhere between the OPC component/server apps.

I hope this solves your problem as well.

panter-dsd commented 5 years ago

I right understood - if the server 32 then I can't connect with client 64?

konimarti commented 5 years ago

I think this is correct. Did it work for you with the 32 code?

panter-dsd commented 5 years ago

No. But maybe the problem in gbda_aut.dll (it 64 bit) I will try tomorrow on 32 bit machine and write result here.

konimarti commented 5 years ago

Ok, thanks. Looking forward to hearing your results! Alternatively, Graybox offers a 32 or 64 OPC wrapper (http://www.gray-box.net/download_daawrapper.php?lang=en) Just copy the files (gbda_aut.dll) in the corresponding directories on your system:

konimarti commented 5 years ago

And register the module with regsvr32 gbda_aut.dll in the command line. (To remove Graybox OPC Automation Wrapper from your system's registry enter regsvr32 gbda_aut.dll -u.)

panter-dsd commented 5 years ago

Sure. I know about the procedure of installing gdba_aut. Thanks!

panter-dsd commented 5 years ago

image

panter-dsd commented 5 years ago

Doesn't work.

panter-dsd commented 5 years ago

For example, with local Matrikon server it works. image

konimarti commented 5 years ago

Ok, we're making some progress here; at least you can access the Matrikon server locally. Can you try to access the Matrikon server running on your remote host (192.168.7.51) as well?

I tested the Prosys OPC service with the Graybox Wrapper on a remote machine and it works as expected:

2019/05/02 17:10:26 Loaded OPC Automation object with wrapper Graybox.OPC.DAWrapper.1
2019/05/02 17:10:26 Connecting to Prosys.OPC.Service on node 10.100.100.81
2019/05/02 17:10:26 Connected.
map[Random.PsFloat1:67.02508991584182]

I found that it is crucial to compile the golang code with GOARCH=386 and to make sure that the x86 Graybox Wrapper is properly installed and registered.

panter-dsd commented 5 years ago
  1. I also can't connect to Matrikon on remote host.
  2. I use GOARCH=386
  3. I use x86 Graybox Wrapper. (I can't install x86_64 because I have x86 OS)
panter-dsd commented 5 years ago

Can I provide some more information? What's can help?

konimarti commented 5 years ago

Maybe you can double-check your DCOM settings as well? The problem doesn't seem to be with the code itself and more with your system setup/configuration since I could verify that the graybox wrapper works with the prosys server and your matrikon example works locally.

cookedsteak commented 2 years ago

@panter-dsd May I ask how to solved this problem finally ? Cause I 've got the very same issue. thx

panter-dsd commented 2 years ago

Sorry, I haven’t touched this this project since 2019. So, I remember nothing about this problem.