Channel Initialsation


Recommended Posts

I have a sequence that unpacks bits from 16 bit words read via Modbus TCP to a PLC. However when there is a communication error from the start with the PLC it stops the sequence. There is a 'C1086 one of the parameters was empty: Background Line 96 - Uncaught error in sequence Background' error.

 

This look to me like the channels are not getting initialised and it's causing the sequence to abort. How can I solve this? I've tried forcing a value to the channel variable at the start of the sequence but that doesn't work?

 

XMTV T5016.zip

Link to comment
Share on other sites

First, I'm not sure what you are doing here:

 

global hyd_memory{64:80}

 

Its not really a valid line (or the other similar ones), though the script parser may just ignore the syntax errors (for now...)

 

Second, yes, most likely hyd_memory hasn't been initialized yet, so it can't process that line.  You have two choices:

 

1) initialize hyd_memory, for example:

 

global hyd_memory = fill(0,160)

 

will initialize it to all 0's

 

2) add some try/catch blocks around your switch statements:

try
   switch ....
catch()
   ? strLastError
endcatch
delay(0.1)

Then if any error occurs, the error is printed, but the loop continues.

 

Finally, the way you are converting your words into this bit array works, but is a bit brute force and very slow.  In general you want to avoid loops in DAQFactory for data processing, and DAQFactory provides many ways to do this.  In your case, instead of:

for (private counter = 0, counter < 16, counter++)      hyd_memory[counter+64]= testbit(hyd_mw117[0],counter)
      hyd_memory[counter+80]= testbit(hyd_mw118[0],counter)
endfor
You can just do:
hyd_memory[64] = transpose(to.bit(htd_mw117[0]),0)[0,15]
hyd_memory[80] = transpose(to.bit(htd_mw118[0]),0)[0,15]
With two registers, the difference is probably 5 miliseconds, but you have 160 bits, so the difference is probably more on the order of a few hundred milliseconds.  Since your registers are in order, you can do your entire block very easily:
 
for (private x = 0, x < 19, x++)
   hyd_memory[x * 16] = transpose(to.bit(evaluate("htd_mw" + doubletoStr(104+x) + "[0]")),0)[0,15]
endfor
(or something close to that, I didn't test the loop).  This means all your bits will end up in hyd_memory though, and not split into hyd_input and output.  If you want to keep that distinction, use my first method without the loop, it'll still be a dramatic improvement.
Link to comment
Share on other sites

That helped me solve my problem - thanks.

 

I've still got to use your improved way of extracting bits as the line you wrote does produce an error and I've not sorted out why yet. However I was under pressure to solve the problem of the sequence stopping which I've now done.

 

This may not be the right place in the forum but can you answer why the TCP Modbus coms will not automatically recover if DAQ is started without the PLC connected and then the Ethernet cable is connected. DAQ has to be shut down and restarted to recover the coms.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.