Write an Array (of real) to an Siemens 1500 with OPC UA on WINDEV

901 views Asked by At

(sorry for my french way to write english)

Hi, After many research on net and doc, i can't resolve my problem

I try to write an array of 150 real to siemens with OPC UA :

PROCÉDURE WriteArrayToNode(NodeIdTxt is string)

Trace("lets write")


myNodeId        is NodeId(gsNotreBD+"."+NodeIdTxt)
nodesToWrite    is WriteValueCollection <- new WriteValueCollection()
nodeToWrite     is WriteValue           <- new WriteValue()
nodeToWrite.NodeId                  = myNodeId
nodeToWrite.AttributeId             = Attributes.Value

Trace(Attributes.ValueRank,Attributes.Value,Attributes.ArrayDimensions)

vTemp is Opc.Ua.variant(gTab_W_PARA)   //gTab_W_PARA is the array of 150 real i trying to write
clDataValue1 is DataValue <- new DataValue(vTemp);

nodeToWrite.Value=clDataValue1
nodeToWrite.IndexRange="1:150"

nodesToWrite.Add(nodeToWrite);

clRequestHeader is RequestHeader <- new RequestHeader()
myResults is StatusCodeCollection dynamic = new StatusCodeCollection
myDiagsInfo is DiagnosticInfoCollection dynamic = new DiagnosticInfoCollection
request is RequestHeader dynamic =  new RequestHeader

gmySession.Write(request,nodesToWrite,myResults,myDiagsInfo)

Trace(myDiagsInfo.get_Count())

Trace("scribe ? ")
RETURN True
Trace(" yes scribe ")

CASE ERROR:
Trace("erreur",ExceptionInfo)
RETURN False
CASE EXCEPTION:
Trace("exception",ExceptionInfo)
RETURN False

The TRACE give :

lets write      //start of process
15 13 16        // Attributes.ValueRank,Attributes.Value,Attributes.ArrayDimensions  I don't understand :
                // With doc, I admit it say Attributes is 15 dimensional array with value of 13 ? and 16 
                // index,  but who is Attributes ? I never use array like that
0               
scribe ?        //it return true, so there is no error ?

But in siemens my array don't change, so the write not work ? i try use variant and Datavalue like in many example, but i not sure its the good way. if someone can help I thank him in advance

1

There are 1 answers

0
Frank Burkart On

Probably your using of IndexRange is wrong.

Assuming that you only use an OneDimensional S7 Array REAL[1..150] (which the dataVariable indicates whith Attributes ValueRank and ArrayDimensions)

Do not use S7 ranges syntax with OPC UA IndexRange!

  1. From the UA Spec:

"All indexes start with 0. The maximum value for any index is one less than the length of the dimension."

So "1:150" adresses a range, that doesn't exists on the server. "0:149" would be correct.

  1. If you address the whole array, don't use an IndexRange at all. In fact, this will have some performance issues on servers.

  2. Maybe S7-1500 OPC Server does not support IndexRange at all, when writing. But it should return an error.