1. Scott Paxman
  2. PowerBuilder
  3. Thursday, 4 October 2018 17:08 PM UTC

I have a PB 8 that connects to an OPC server using the opc-da standard. It basically calls a ole/com object dll to communicate to the server which talks to plcs.  I am having an issue with the following AddItems external function call.

opc_struc.opc_items.AddItems(llEnd, ls_items, ll_client_handles, ref ll_item_server_handles, ref ll_server_errors )

 

long ll_item_server_handles[], ll_server_errors[],ll_client_handles[], llEnd

string ls_items[]

ls_items is an array of strings, tag names on the opc server we want  to connect to.

for example:

This call worked fine in PB 8 but we have never got it to work on later versions. I believe it is a unicode/ansi string issue.

I tried to convert these strings to ansi using the following code. ls_tmp contains the strings in the above snip.  

Blob lbl_data
lbl_data = Blob(ls_tmp, EncodingANSI!)
ls_items[ll_idx] = String(lbl_data, EncodingANSI!)

But it still blows up on the additmes call. 

Any help would be greatly appreciated.

Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Friday, 26 October 2018 17:08 PM UTC
  2. PowerBuilder
  3. # 1

Unfortunately, the only way I know of to deal with a .Net Assembly in PB2017Rx is to use the "COM Callable" approach.

Thought: I wonder if your original approach in PB2017 using the PB8 code is being thwarted by the byte alignment feature. This was addressed in PB 12.6 and higher by ...

Adding this to your PB.INI file:

[PB]

; Use 1 to force 8 Byte alignment. A value of 0 forces 1 byte alignment (before PB 12.6)
UseZp1=0

or

FUNCTION int STLAREGIO ( ref struc_kfzrechnerneu struc_kfz ) LIBRARY "KFZ_SS.DLL" alias for "STLAREGIO;Ansi" progma_pack(1)

progma_pack(1) is 1-byte align, progma_pack(8) is 8-bytes align.  In this way, the effect is only for external function that is declared with this alignment.

 

 

 

Comment
There are no comments made yet.
Scott Paxman Accepted Answer Pending Moderation
  1. Friday, 26 October 2018 16:40 PM UTC
  2. PowerBuilder
  3. # 2

Thanks that is what I was afraid of... Can you point me in a direction for calling .net assemblies in 2017 R03 classic? So I do not have to use the COM method. Or do you think this would still be an issue?

Thanks for all your input and time!!

Comment
There are no comments made yet.
Scott Paxman Accepted Answer Pending Moderation
  1. Friday, 26 October 2018 16:06 PM UTC
  2. PowerBuilder
  3. # 3

Hi Chris,

 

Thanks for all your input!!

I basically went a different  direction and downloaded a toolkit from opclabs  that allows me to talk to opc servers. It helps with development of my client. However, I can get it to work on simple read of one item when just passing a string.  But when I want to read multiple items from the plc at one time, I must pass an object that contains; server, tags to read etc. I cannot get the passing of the objects to work. I can create these objects using the connecttonewobject() method call but then when I pass an ANY array of these objects we blow up.. Does Powerbuilder allow passing of objects through com ole-automation  ?

Comment
  1. Chris Pollach @Appeon
  2. Friday, 26 October 2018 16:34 PM UTC
Yes it does, but unless it was a PB OLE Server (feature now deprecated) - it would not understand the object class being passed. The only thing that would be of a common understanding between the PB world and the OLE Server (AFAIK) would be a "Structure".

  1. Helpful
There are no comments made yet.
Scott Paxman Accepted Answer Pending Moderation
  1. Friday, 5 October 2018 15:43 PM UTC
  2. PowerBuilder
  3. # 4

The automation wrapper is in unicode. So I am still not sure what to do PB8 worked fine, PB10 up to the cureent version does not work. Any suggestions? 

Comment
  1. Chris Pollach @Appeon
  2. Friday, 5 October 2018 15:51 PM UTC


Since PB v8.x was only ANSI, I suspect that the OLE automation implementation that you have is also ANSI. Otherwise, it would not work with PB 8.x as you could not call an external Unicode resource. However since PB 10x being Unicode, you can call either ANSI or Unicode external resources. Its just that for ANSI based ones, you have to make sure that the passed data is in ANSI format.
  1. Helpful
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Thursday, 4 October 2018 17:16 PM UTC
  2. PowerBuilder
  3. # 5

Hi Scott;

  Before you go down the old ANSI path ... does the vendor not supply a Unicode interface COM/DLL?

Regards ... Chris

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.