Author Topic: OPCDA and TwinCAT - pass arrays between using ComBridge  (Read 369 times)

AndyL

  • Newbie
  • *
  • Posts: 3
    • View Profile
OPCDA and TwinCAT - pass arrays between using ComBridge
« on: March 01, 2022, 04:25:20 AM »
I'm testing AdvancedHMI to see if I can pass data both ways between a Beckhoff PC running TwinCAT3 and an OPC server running on a remote PC.

I'd like to use the ComBridge, as it's very easy to set up, and seems to recover from network interruptions. It's quite easy to configure, with the caveat that you end up with a lot of ComBridge's! I've sucessfully read an ADS item from the Beckhoff PC and put it into an item on the OPC server. However this was a scalar item. I have quite a lot of arrays to read and write between the two machines.

I have configured the ComBridge in the same way as the scalar item, with the exception that I have added the NumberOfElements parameter. I have changed this to the number of elements in the array. The two arrays (source and destination) are of an equal size.

Although the application runs, I can see a "Exception thrown: 'MfgControl.AdvancedHMI.Drivers.Common.PLCDriverException' in AdvancedHMIDrivers.dll" in the Output window. I don't get this if remove the ComBridge that is handling the array from the project, so I guess this is the one that's causing the issue.

So, a few questions.

1) Have I configured this correctly? The configuration is shown in the image attached.
2) Are the array sizes zero or one based?
3) If you get the array size wrong, what happens? Does it require the actual array size, or can you copy less than the number of array items from the source array to the target array? For example, if your source is 20, and your destination is 10, can you set the array size to copy just the first 10 items of the source array?
4) Is there a way to get more debug information out? I can see that there has been an excepttion, but it would be nice to be able to pin point where it's coming from.

I'm using v399xR1, by the way.












AndyL

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: OPCDA and TwinCAT - pass arrays between using ComBridge
« Reply #1 on: March 01, 2022, 11:57:27 AM »
A bit more information.

I've moved on to AdvancedHMIv399yBeta38 and configured a ComBridge with the same data as before.

Now I get a message box that pops up saying " WriteData2. 1Elements in Loop Conversion from string "System.Single[]" to type 'Single' is not valid.

In the BeginWrite function, I can see that on line 1009, the ADS item is correctly identified as an array of the correct size. The function is called with NumberOfElements set to 1 - I don't know where that comes from? I've set the number of elements to 5 in the configuration of the ComBridge. On line 1012, BytesToWrite is set to 4. I would have thought that this should be 4*TheNumberOfElementsYouWantToWrite, or TheArraySizeIfNotConfigured? (I made those names up).

Now we go to the SelectCase, and it correctly identifies the type as an ADST_Real32.

This is the line that goes wrong:

BitConverter.GetBytes(CType(dataToWrite(i), Single)).CopyTo(BytesToWrite, i * LengthOfData)

dataToWrite is System.Single[], BytesToWrite is 4.

If I do the same thing with a scalar value, then dataToWrite(i) is a numeric value, and not a datatype.

I can see that the function Write gets called before BeginWrite, and the startAddress is the item name - which is correct - but the dataToWrite is wrong here (it's System.Single[]) and so it the numberOfElements (it's 1)

Now I've got about as far as I can. I hope this is of some help?




Godra

  • Hero Member
  • *****
  • Posts: 1438
    • View Profile
Re: OPCDA and TwinCAT - pass arrays between using ComBridge
« Reply #2 on: March 01, 2022, 11:40:01 PM »
Maybe try using this control instead:

   https://www.advancedhmi.com/forum/index.php?topic=2672.0

AndyL

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: OPCDA and TwinCAT - pass arrays between using ComBridge
« Reply #3 on: March 02, 2022, 04:19:37 AM »
Hi - thanks for the file. I added it to the solution, and it didn't appear in the toolbox. So I closed the solution and re-opened it. I then got an error:

Method 'System.Collections.Generic.List`1[[MfgControl.AdvancedHMI.Drivers.PLCAddressItem, MfgControl.AdvancedHMI.Drivers, Version=3.99.19.2, Culture=neutral, PublicKeyToken=null]].Add' not found.

and

Object of type 'MfgControl.AdvancedHMI.Drivers.PLCAddressItem' cannot be converted to type 'MfgControl.AdvancedHMI.Drivers.PLCAddressItem'

I tried this in both v399xR1 and v399Beta38, using VS2022 and VS2016 - got the same error.

« Last Edit: March 02, 2022, 04:26:04 AM by AndyL »