Recent

Author Topic: OPC client with Lazarus  (Read 63754 times)

avra

  • Hero Member
  • *****
  • Posts: 2520
    • Additional info
Re: OPC client with Lazarus
« Reply #75 on: April 22, 2023, 10:47:10 pm »
Yes that was my first troubleshooting test, I used a OPC test client based on python and it worked perfectly so I know Ignition is configured and operating correctly.
You confirmed step 2, but not a word about step 1. Do you have libopen62541.so on your system? Did you follow https://www.open62541.org/doc/1.3/installing.html#installing instructions? Can you compile some open62541 server and client examples? If for instance you compile some example like gcc -std=c99 -o server tutorials_server_firststeps.c -lopen62541 and after that you execute objdump -p server | grep NEEDED or ldd server you will see that something like libopen62541.so.1 is needed for execution.

You can also take a look at open62541.pas:
Code: Pascal  [Select][+][-]
  1. {$IFDEF UNIX}
  2.   libopen62541 = 'libopen62541.so';
  3. {$ELSE}
  4.   libopen62541 = 'libopen62541.dll'; // GCC libgcc_s_sjlj-1.dll and libwinpthread-1.dll are also required
  5.                                      //  they can be downloaded from packages at http://win-builds.org/1.5.0/packages/windows_32/
  6. {$ENDIF}

I tried to compile the test example that is shipped with fpopen62541 but it does not compile, there is an issue with an identifier 'memberTypeIndex' so I cannot run the TestOPCUa to test it. Do you have a pascal client I can use to test with so I can confirm open62541 is working
Try this older version compatible with open62541 v1.2:
https://github.com/fluisgirardi/fpopen62541/tree/d9132e968d9d050c90225a493121acb67cdceac3
You will probably need to match it with https://github.com/open62541/open62541/releases/tag/v1.2.6

Btw, if libopen62541.so is installed, but still can not be found you can execute this for current session:
Code: Bash  [Select][+][-]
  1. export LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib
or to make the change permanent you can add /usr/local/lib to /etc/ld.so.conf and run ldconfig as root.
« Last Edit: April 22, 2023, 11:02:53 pm by avra »
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

TheMouseAUS

  • Jr. Member
  • **
  • Posts: 52
Re: OPC client with Lazarus
« Reply #76 on: April 23, 2023, 01:37:15 am »
Sorry did not fully understand the first question.

When I first tried to compile and run I got the message could not open open libopen62541.so. I check the fedora repo's and it was there for install both implementation and dev packages so no I did not compile libopen62541.so I just installed them. After that the application runs but just no connection is happening, as its version 1.3.4 , maybe its just incompatible with the wrapper at this stage.

Three months ago ver 1.3 was added to fpopen62541 and there has been commits since but maybe its incomplete at this time. I will attempt to compile and install ver 1.2.6 and see how I go. Thanks :-)

avra

  • Hero Member
  • *****
  • Posts: 2520
    • Additional info
Re: OPC client with Lazarus
« Reply #77 on: April 23, 2023, 02:15:57 am »
When I first tried to compile and run I got the message could not open open libopen62541.so. I check the fedora repo's and it was there for install both implementation and dev packages so no I did not compile libopen62541.so I just installed them. After that the application runs but just no connection is happening, as its version 1.3.4 , maybe its just incompatible with the wrapper at this stage.
If you do not compile and test some open62541 server and client, or at least server and test it with some external client, we will not know if problem is in open62541 or fpopen62541 part.

Three months ago ver 1.3 was added to fpopen62541 and there has been commits since but maybe its incomplete at this time. I will attempt to compile and install ver 1.2.6 and see how I go. Thanks :-)
I suggest you to first compile just demo from old fpopen62541 version I gave you with open62541 1.3 you already have. I can compile similar version locally. Only if that Lazarus demo compiles but does not execute well, you should try to uninstall open62541 1.3 and install 1.2.
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

TheMouseAUS

  • Jr. Member
  • **
  • Posts: 52
Re: OPC client with Lazarus
« Reply #78 on: April 23, 2023, 02:34:00 am »
Yes I was thinking that :-)
OK i found fedora open62541 rpm's for version 1.2.6 which I have just installed. I have just compiled the fpopen62541 version you gave me and attempted to connect to Ignition.

Same fault 'Fail status code: 80AD0000 BadDisconnect'

I started the UA server in fpopen62541 and attempted to connect to that

'4/6 UA_SESSIONSTATE_ACTIVATED/UA_SECURECHANNELSTATE_OPEN'

so open62541 works. I just cannot connect to Ignition for some reason.

Using FreeOpcUa I can connect and see the PLC so I know the server is working.

TheMouseAUS

  • Jr. Member
  • **
  • Posts: 52
Re: OPC client with Lazarus
« Reply #79 on: April 23, 2023, 11:16:43 am »
Been investigating and I think it maybe a configuration issue, trying to work out the different config options.

The test server reports the following when queried

uaclient.uaclient - INFO - Endpoint 1:')
uaclient.uaclient - INFO -   Endpoint URL: opc.tcp://localhost:4840')
uaclient.uaclient - INFO -   Application URI: urn:open62541.server.application')
uaclient.uaclient - INFO -   Product URI: http://open62541.org')
uaclient.uaclient - INFO -   Application Name: LocalizedText(Locale='en', Text='open62541-based OPC UA Application')')
uaclient.uaclient - INFO -   Application Type: 0')
uaclient.uaclient - INFO -   Discovery URL: opc.tcp://localhost:4840')
uaclient.uaclient - INFO -   Server Certificate: [no certificate]')
uaclient.uaclient - INFO -   Security Mode: 1')
uaclient.uaclient - INFO -   Security Policy URI: http://opcfoundation.org/UA/SecurityPolicy#None')
uaclient.uaclient - INFO -   User policy: open62541-anonymous-policy')
uaclient.uaclient - INFO -     Token type: 0')
uaclient.uaclient - INFO -   User policy: open62541-username-policy')
uaclient.uaclient - INFO -     Token type: 1')
uaclient.uaclient - INFO -     Security Policy URI: http://opcfoundation.org/UA/SecurityPolicy#None')
uaclient.uaclient - INFO -   Transport Profile URI: http://opcfoundation.org/UA-Profile/Transport/uatcp-uasc-uabinary')
uaclient.uaclient - INFO -   Security Level: 1')
uaclient.uaclient - INFO - ')

the Ignition server :-

uaclient.uaclient - INFO - Endpoint 1:')
uaclient.uaclient - INFO -   Endpoint URL: opc.tcp://localhost:62541')
uaclient.uaclient - INFO -   Application URI: urn:inductiveautomation:ignition:opcua:server:5e954f0a-ab48-41cb-bbac-f36d4fcc3819')
uaclient.uaclient - INFO -   Product URI: urn:inductiveautomation:ignition:opcua:server')
uaclient.uaclient - INFO -   Application Name: LocalizedText(Locale='en', Text='Ignition OPC UA Server')')
uaclient.uaclient - INFO -   Application Type: 0')
uaclient.uaclient - INFO -   Discovery URL: opc.tcp://localhost:62541/discovery')
uaclient.uaclient - INFO -   Server Certificate: commonName=Ignition OPC UA Server, organizationName=Inductive Automation, organizationalUnitName=, localityName=Folsom, stateOrProvinceName=CA, countryName=US (self-signed), 2023-04-20 14:00:00 - 2026-04-20 14:00:00')
uaclient.uaclient - INFO -   Security Mode: 1')
uaclient.uaclient - INFO -   Security Policy URI: http://opcfoundation.org/UA/SecurityPolicy#None')
uaclient.uaclient - INFO -   User policy: anonymous')
uaclient.uaclient - INFO -     Token type: 0')
uaclient.uaclient - INFO -   User policy: username')
uaclient.uaclient - INFO -     Token type: 1')
uaclient.uaclient - INFO -     Security Policy URI: http://opcfoundation.org/UA/SecurityPolicy#Basic256')
uaclient.uaclient - INFO -   Transport Profile URI: http://opcfoundation.org/UA-Profile/Transport/uatcp-uasc-uabinary')
uaclient.uaclient - INFO -   Security Level: 32')
uaclient.uaclient - INFO - ')

avra

  • Hero Member
  • *****
  • Posts: 2520
    • Additional info
Re: OPC client with Lazarus
« Reply #80 on: April 23, 2023, 06:25:05 pm »
I am glad you have your Lazarus OPC UA client working now. Now disconnection issue...

Comparing logs, differences seam to be that Ignition has certificate, and that Ignition has security policy Basic256 (with security level 32).

Can you temporary switch off all security in Ignition server and try Lazarus OPC UA client again?

Are Ignition, Python OPC UA client, and Lazarus OPC UA client all on the same physical computer? If not, can you try that and report? How does Python code that connects with success look like?

Maybe you can get an idea related to possibly missing client encryption parameters here: https://github.com/open62541/open62541/tree/master/examples/encryption

If all fails, then you could adapt some open62541 C client example to read a single Ignition tag and if still the same problem discuss it and report on open62541 IRC, mail list, or report an issue.


Btw, it seams that Basic256 has been dropped from OPC UA 1.04, so if open62541 decided to follow it maybe Basic256 is no longer supported and that can be the problem. Try to change security in Ignition and report results.
https://github.com/open62541/open62541/issues/3619
« Last Edit: April 23, 2023, 06:32:54 pm by avra »
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

TheMouseAUS

  • Jr. Member
  • **
  • Posts: 52
Re: OPC client with Lazarus
« Reply #81 on: April 23, 2023, 08:41:19 pm »
I think I have figured it out. I decided to install wireshark and see if I could see anything out of the ordinary. I saw the issue immediately. open62541 would seem to default to IP v6 where as asyncua for python uses IP v4. As soon as I changed the address from 'localhost' to 127.0.0.1 it connected.

What made me think of this is I knew I could not be security as that security policy was 'None' for anonymous user and the test client was set to no security and it could connect.

localhost:62541

7   1.361425663   ::1   ::1   TCP   94   46204 → 62541 [SYN] Seq=0 Win=65476 Len=0 MSS=65476 SACK_PERM TSval=458882369 TSecr=0 WS=128
8   1.361462140   ::1   ::1   TCP   74   62541 → 46204 [RST, ACK] Seq=1 Ack=1 Win=0 Len=0

127.0.0.1:62541

39   8.175677017   127.0.0.1   127.0.0.1   TCP   74   42252 → 62541 [SYN] Seq=0 Win=65495 Len=0 MSS=65495 SACK_PERM TSval=1879333019 TSecr=0 WS=128
40   8.175759508   127.0.0.1   127.0.0.1   TCP   74   62541 → 42252 [SYN, ACK] Seq=0 Ack=1 Win=65483 Len=0 MSS=65495 SACK_PERM TSval=1879333019 TSecr=1879333019 WS=128

Thank for you help. Now I have to figure out how to read and write data, onto the next step.

Miniekans

  • Newbie
  • Posts: 1
Re: OPC client with Lazarus
« Reply #82 on: May 30, 2023, 01:35:54 pm »
Hello,
I have a strange issue with fpopen and Linux.
open62541 v1.3.3 library built with MSVS 2022 on Windows 10 and everything works fine. I can connect to OPC UA server, read and write values. I use built-in fpopen example.

But, on Linux some strange things happens. Not all function from libopen62541.so is working.
I can connect to OPC UA server and read values via UA_Client_readValueAttribute but i cant write because functions like UA_Variant_setScalarCopy, UA_Variant_setInteger, UA_Client_readDataTypeAttribute and others does not working properly. UA_TYPES array items is empty. UA_Copy returns zeros and some garbage in result.

I have done some reads and writes in QT and everything is ok.

Lazarus and Linux new for me, so maybe its my issue. But everything works on Win10 and it confuses me.

Lazarus 2.0.6 (FPC 3.0.4) on Ubuntu 20.04.


alr1976

  • Newbie
  • Posts: 1
Re: OPC client with Lazarus
« Reply #83 on: August 05, 2023, 04:35:32 pm »
Hi!

I have problem to use Client stateCallback. Doesn' t works. It notify me nothing....

 client := nil;
  client := UA_Client_new();

  conf := UA_Client_getConfig(client);
 UA_ClientConfig_setDefault(conf);
  conf^.timeout:= 60000;
  conf^.stateCallback:=@mystatecallback;


procedure mystateCallback(client: PUA_Client; channelState: UA_SecureChannelState; sessionState: UA_SessionState; connectStatus: UA_StatusCode);
begin
   showmessage('ok');
end;

any ideas?
 

lagodnol

  • Newbie
  • Posts: 2
Re: OPC client with Lazarus
« Reply #84 on: March 05, 2024, 07:52:17 am »
Has anyone managed to get the wrapper to work correctly in Delphi? Everything works in Lazarus. In Delphi I can connect, read the values, but I can't add a variable on the server and I can't subscribe.
And even when reading values, if I make a second reading request after more than 30 seconds, I get the error: BadSessionIdInvalid.
I suspect there are differences in the configuration structures, but I haven't figured them out in two days.
I would be grateful for any suggestions.
I use the code: https://github.com/fluisgirardi/fpopen62541
Win32. Dll version: 1.2-RC2, 1.2.6
« Last Edit: March 05, 2024, 08:00:45 am by lagodnol »

lagodnol

  • Newbie
  • Posts: 2
Re: OPC client with Lazarus
« Reply #85 on: March 09, 2024, 07:59:09 pm »
Looks like I found the problem. It is related to the optimization of record transfer in Delphi: if the const keyword is specified, the address of the record is transmitted, and not the record itself. It is necessary to remove the const when passing records in imported functions. For example:
Code: [Select]
   UA_Client_Subscriptions_delete: function(client: PUA_Client; const request: UA_DeleteSubscriptionsRequest): UA_DeleteSubscriptionsResponse; cdecl;
should be replaced by
Code: [Select]
   UA_Client_Subscriptions_delete: function(client: PUA_Client; request: UA_DeleteSubscriptionsRequest): UA_DeleteSubscriptionsResponse; cdecl;

mrogerf

  • Newbie
  • Posts: 2
Re: OPC client with Lazarus
« Reply #86 on: April 08, 2024, 08:51:32 pm »
Hello,
I have a strange issue with fpopen and Linux.
open62541 v1.3.3 library built with MSVS 2022 on Windows 10 and everything works fine. I can connect to OPC UA server, read and write values. I use built-in fpopen example.

How do you could compile fpopen? I tried code from there and got this error: TestOpcUa1.pas(244,23) Error: Unknown record field identifier "memberTypeIndex"


Thaddy

  • Hero Member
  • *****
  • Posts: 15173
  • Censorship about opinions does not belong here.
Re: OPC client with Lazarus
« Reply #87 on: April 09, 2024, 06:52:16 am »
Can it be that there is a name clash at play here?
fpopen is a fpc function in the unix rtl... from baseunix.fpopen? --> resolves to unix open.
In that case you can fix that with <your-other-unit-name>.fpopen
Or rename the other fpopen
(since it seems to compile on windows I suspect the name clash, since windows does not use baseunix, so it can use a different fpopen without issue)
« Last Edit: April 09, 2024, 07:00:01 am by Thaddy »
Of course the national anthem of the U.S.A. was written by Jimi Hendrix, didn't you know that?

mrogerf

  • Newbie
  • Posts: 2
Re: OPC client with Lazarus
« Reply #88 on: April 10, 2024, 07:17:10 pm »
Can it be that there is a name clash at play here?
fpopen is a fpc function in the unix rtl... from baseunix.fpopen? --> resolves to unix open.

No ... it's not the standard fpopen. It's fpopen62541, a freepascal wraper to open62541 OPC UA C library.

Miniekans commented that could successfully compile the example application. But I could not due the errors from my previous post.
« Last Edit: April 10, 2024, 07:19:47 pm by mrogerf »

ponsdaniel

  • Newbie
  • Posts: 2
Re: OPC client with Lazarus
« Reply #89 on: June 18, 2024, 05:32:23 pm »
Good,
I am testing the example in lazarus to connect to an OPC UA server using the libopen62541.dll library.

The source code is an example that I have found on the net, that other forums have answered working on linux.

Here in windows I can't find the problem because it is not working for me.

I have placed the library in the executable folder, I have placed a path in another folder where the library is.

But I always get the error.

Who can help me?

Translated with DeepL.com (free version)

 

TinyPortal © 2005-2018