COMatePLUS Array Problems

Just starting out? Need help? Post your questions and find answers here.
Kollmetz
New User
New User
Posts: 1
Joined: Thu Apr 25, 2024 2:27 pm

COMatePLUS Array Problems

Post by Kollmetz »

Hello,

I have the following problem:
I use the COMatePLUS lib. And try to pass an array of COMateObject. However, I get the following error message: Object of type "System.String" cannot be cast to type "System.Object[]". Could someone help me here?

Thank you

Greetings Norbert

Code: Select all

;/////////////////////////////////////////////////////////////////////////////////
;***COMate***  COM automation through iDispatch.
;*===========
;*
;*
;/////////////////////////////////////////////////////////////////////////////////

IncludePath "..\"
XIncludeFile "COMatePLUS.pbi"

DisableExplicit
 OpenConsole()

Structure ReadArguments
    id.i
    Pfad.s 
    Name.s
    isDouble.i    
EndStructure
  
; Global deklarieren des Arrays von ReadArguments
Global Dim ReadArgumentsList.ReadArguments(100) ; Initialisiert ein Array mit Platz für 101 Elemente

Global Dim ArgList.COMateObject(48) ; Initialisiert ein Array mit Platz für 101 Elemente
Global Dim ArgListOut.COMateObject(48)
Global ArgCounter.i = 0              ; Ein globaler Zähler für die ID


Global CurrentID.i = 0 ; Ein globaler Zähler für die ID

 Procedure AddToReadArgumentsList(Pfad.s, Name.s,Doubletype.i)

    ReadArgumentsList(CurrentID)\id = CurrentID + 1
    ReadArgumentsList(CurrentID)\Pfad = Pfad
    ReadArgumentsList(CurrentID)\Name = Name
    ReadArgumentsList(CurrentID)\isDouble = Doubletype
    
    Define.COMateObject ReadArguments1, EndpointDescriptor,NodeDescriptor,NodeId
    ReadArguments1 = COMate_CreateObject("OpcLabs.EasyOpc.UA.OperationModel.UAReadArguments")
    
    EndpointDescriptor = ReadArguments1\GetObjectProperty("EndpointDescriptor")
    EndpointDescriptor\SetProperty("UrlString='opc.tcp://192.168.6.81:4840'")
        
    NodeDescriptor = ReadArguments1\GetObjectProperty("NodeDescriptor")
    NodeId = NodeDescriptor\GetObjectProperty("NodeId")
    NodeId\SetProperty("ExpandedText='"+Pfad+"'")
    
    ArgList(CurrentID) = ReadArguments1
    
    CurrentID + 1 ; Erhöht den ID-Zähler
  EndProcedure
  


 
For i = 1 To 6
  
  SiloNr.s = Str(i)  
  AddToReadArgumentsList("BA_"+Str(i),"nsu=http://www.siemens.com/simatic-s7-opcua;ns=3;s="+Chr(34)+"Silo"+SiloNr+Chr(34)+"."+Chr(34)+"Aktueller_Auftrag"+Chr(34)+"."+Chr(34)+"BAB"+Chr(34)+"."+Chr(34)+"BabNr"+Chr(34),0)
  AddToReadArgumentsList("ArtikelBez_"+Str(i),"nsu=http://www.siemens.com/simatic-s7-opcua;ns=3;s="+Chr(34)+"Silo"+SiloNr+Chr(34)+"."+Chr(34)+"Aktueller_Auftrag"+Chr(34)+"."+Chr(34)+"BAB"+Chr(34)+"."+Chr(34)+"ArtikelBez1"+Chr(34),0)
  AddToReadArgumentsList("Charge_"+Str(i),"nsu=http://www.siemens.com/simatic-s7-opcua;ns=3;s="+Chr(34)+"Silo"+SiloNr+Chr(34)+"."+Chr(34)+"Aktueller_Auftrag"+Chr(34)+"."+Chr(34)+"BAB"+Chr(34)+"."+Chr(34)+"Charge"+Chr(34),0)
  AddToReadArgumentsList("ID_"+Str(i),"nsu=http://www.siemens.com/simatic-s7-opcua;ns=3;s="+Chr(34)+"Silo"+SiloNr+Chr(34)+"."+Chr(34)+"Aktueller_Auftrag"+Chr(34)+"."+Chr(34)+"Steuerung"+Chr(34)+"."+Chr(34)+"Istwerte"+Chr(34)+"."+Chr(34)+"BBID"+Chr(34),1)
  AddToReadArgumentsList("Saugdruck_"+Str(i),"nsu=http://www.siemens.com/simatic-s7-opcua;ns=3;s="+Chr(34)+"Silo"+SiloNr+Chr(34)+"."+Chr(34)+"Saugdruck"+Chr(34),1)
  AddToReadArgumentsList("Chargengewicht_"+Str(i),"nsu=http://www.siemens.com/simatic-s7-opcua;ns=3;s="+Chr(34)+"Silo"+SiloNr+Chr(34)+"."+Chr(34)+"Aktueller_Auftrag"+Chr(34)+"."+Chr(34)+"Steuerung"+Chr(34)+"."+Chr(34)+"Istwerte"+Chr(34)+"."+Chr(34)+"Chargengewicht"+Chr(34),1)
  AddToReadArgumentsList("Chargenmenge_"+Str(i),"nsu=http://www.siemens.com/simatic-s7-opcua;ns=3;s="+Chr(34)+"Silo"+SiloNr+Chr(34)+"."+Chr(34)+"Aktueller_Auftrag"+Chr(34)+"."+Chr(34)+"BAB"+Chr(34)+"."+Chr(34)+"Chargenmenge"+Chr(34),1)
  AddToReadArgumentsList("Gewicht_"+Str(i),"nsu=http://www.siemens.com/simatic-s7-opcua;ns=3;s="+Chr(34)+"Silo"+SiloNr+Chr(34)+"."+Chr(34)+"Gewicht"+Chr(34),1)
  
Next

  



Define.COMateObject Client, WorkBook

For x = 1 To 1000


  Client = COMate_CreateObject("OpcLabs.EasyOpc.UA.EasyUAClient")
  
  If Client  
    
    Define var.VARIANT
    With var
      \vt = #VT_ARRAY|#VT_I4
      \parray = *ArgList
    EndWith

     ArgListOut = Client\GetIntegerProperty("ReadMultiple('"+Str(@ArgList) + " As COMateObject')")
    
     
      Debug COMate_GetLastErrorDescription()

  
  
  
  Delay (1000)
      
Client\Release()




Else
  MessageRequester("COMate -Excel demo", "Couldn't create the application object!")
EndIf



Next


User avatar
spikey
Enthusiast
Enthusiast
Posts: 778
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: COMatePLUS Array Problems

Post by spikey »

I think, but I don't know for certain because I can't test, that you will need to bundle the arguments into a safearray and the safearray into a variant and then pass the address of the variant to the COM method.

See the COMate demo file "Demo_Excel - FillSheetFromSafeArray 2.pb" for an example.
User avatar
mk-soft
Always Here
Always Here
Posts: 6320
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: COMatePLUS Array Problems

Post by mk-soft »

Have you tried it with VB-Script?
I'm interested in this with OPC-UA

Link: Module ActiveScript
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply