Enable or Disable Group off channels


Recommended Posts

OK, then to stop one channel you'd do:

mychannel.timing = 0

channel.restart()

To stop several, you'd do:

chan1.timing = 0

chan2.timing = 0

...

channel.restart()

To restart, just repeat with a non-zero value. I recommend doing this in a loop. Probably the best way is to list the channels in each group in an array of strings, then loop through it. Something like this:

function startStop(string group, timing)
   private string group1 = {"chan1","chan2"}
   private string group2 = {"chan10","chan11"}

   private rows = evaluate("numrows(" + group + ")")
   for (private i = 0, i < rows, i++)
	  execute(evaluate(group + "[i]") + ".timing = " + timing)
   endfor
   channel.restart()

Then pass in the name of the group and 0 or the desired timing. For example:

startStop("group2", 0)

would stop the channels in group2, and:

startStop("group1", 1)

would set the timing of the channels in group1 to 1 second

Note: the script was off the cuff, so there might be a typo or two. It uses execute / evaluate heavily to make it more flexible.

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 months later...

This code to set timing of a group is just what i need in my project.

- But i cant get i to work.

I have put your code in a sequence, and get an "One of the parameters was empy: ..Line5

this line private rows = evaluate("numrows(" + group + ")")

Hope you can tell me what i am doing wrong.

Link to comment
Share on other sites

You probably didn't pass anything in to the function so group does not exist. There is a difference between an empty array (like a channel without any values) which will return 0 from numrows(), and trying to do numrows() with a variable that just plain doesn't exist.

Link to comment
Share on other sites

Here is the sequence

 function startStop(string group, timing)
   private string group1 = Channel.ListAll("registerCANadr2")
   private string group2 = Channel.ListAll("bitCANadr2")
   private string group3 = Channel.ListAll("registerCANadr3")
   private string group4 = Channel.ListAll("bitCANadr3")

 while(1) 
   private rows = evaluate("numrows(" + group + ")")
   for (private i = 0, i < rows, i++)
	  execute(evaluate(group + "[i]") + ".timing = " + timing)
   endfor
   channel.restart()

catch()
   ? strLastError
   endcatch
   delay(0.2)
endwhile

In the decription you say Then pass in the name of the group - in the sequence?

Link to comment
Share on other sites

I am still not getting it right

I have tried this simple code and it only sets the timing of the first channel to 1.1

private string group1 = {"O2_1_set_L_CANadr3","O2_2_set_L_CANadr2"}
execute(evaluate("group1") + ".timing = " + 1.1)
   channel.restart()

Hope you can help me out.

Link to comment
Share on other sites

Archived

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