OK I'm not very hopeful of a resolution but I thought I'd give it a shot here.
I have an OPC Simulator that I can create "in-memory arrays". These arrays can be of various data types. For example they can be VT_I2, VT_I4, VT_UI2, etc...
If these look familiar to you then keep reading... AFAIK I2 = Signed Integer, I4 = Singed Long (both native VB6 data types). Ergo, UI2 = Unsigned Integer, however VB6 cannot declare a variable as an Unsigned Int or Long (a known limitation to VB6).
As you may have guessed, I have successfully Read data from and Written data to the VT_I2 and the VT_I4 arrays, but am unable to Write to the VT_UI2 array (although strangely I can read from it).
I will try to condense all the code as small as possible.
VB Code:
Public Enum CanonicalDataTypes CanonDtShort = 2 ' VT_I2 CanonDtLong = 3 ' VT_I4 CanonDtFloat = 4 CanonDtDouble = 5 CanonDtString = 8 CanonDtBool = 11 CanonDtChar = 16 CanonDtByte = 17 CanonDtWord = 18 ' VT_UI2 CanonDtDword = 19 ' VT_UI4 CanonDtArray = 8192 ' VT_Array End Enum
The following code works for Longs (VT_I4):
VB Code:
Sub AddOPCItem ' Dim Types(1) As Integer ' ' Works: ' ' VT_I4 OPCItemIDs(1) = "Device_1.aLong" Types(1) = CanonDtLong + CanonDtArray ' ' ... ' Dim RequestedDataType As Variant RequestedDataType = CVar(Types) ' OPCItemCollection.AddItems ItemCount, OPCItemIDs, ClientHandles, ItemServerHandles, ItemServerErrors, RequestedDataType ' End Sub Sub WriteOPC ' Dim Vals(4) As Long ' DHS good for LONGs (VT_I4) ' For i = 1 To 4 Vals(i) = CLng("SomeNumericValue") Next ' ' ... ' ASyncItemValues(1) = CVar(Vals) ConnectedGroup.AsyncWrite ItemCount, ASyncItemServerHandles, ASyncItemValues, ASyncItemServerErrors, TransactionID, CancelID ' End Sub
The following code works for Integers (VT_I2):
VB Code:
Sub AddOPCItem ' Dim Types(1) As Integer ' ' Works: ' VT_I2 OPCItemIDs(1) = "Device_1.aShort" Types(1) = CanonDtShort + CanonDtArray ' ' ... ' Dim RequestedDataType As Variant RequestedDataType = CVar(Types) ' OPCItemCollection.AddItems ItemCount, OPCItemIDs, ClientHandles, ItemServerHandles, ItemServerErrors, RequestedDataType ' End Sub Sub WriteOPC ' Dim Vals(4) As Integer ' DHS - good for SHORTs (VT_I2) ' For i = 1 To 4 Vals(i) = CInt("SomeNumericValue") Next ' ' ... ' ASyncItemValues(1) = CVar(Vals) ConnectedGroup.AsyncWrite ItemCount, ASyncItemServerHandles, ASyncItemValues, ASyncItemServerErrors, TransactionID, CancelID ' End Sub
As you can see I can define a VB array of Integers to Write data down to VT_I2's and I can define a VB array of Longs to Write data down to VT_I4's.
However I am unable to create a VB array such that I can Write down to VT_UI2's or VT_UI4's.
I have tried using VB arrays of Integers and VB arrays of Longs in an attempt to Write data down to the VT_UI2 and VT_UI4 OPC arrays, but no data gets written down. No error is reported on either end. Its just like nothing happens.
Question: Can I create a VB Array of "Somethings" to trick the transport layer into accepting something as an Unsigned data type?
I have seen some blurbs about SAFEARRAYs but am unsure how that fits into the equation...
Thanks!
Dave




Reply With Quote