Sorry that it took so long. Have many things to do today, but I'm not quiet sure how this part of your code works:
op_index, op_msg = [qval.value for qval in system.tag.readBlocking([op_index_path, op_msg_path])]
can you explane how this operates or is there a doc for this?
or is this replacing the tagpath for the value
It's a list comprehension. It's basically a loop.
Here's what happens:
there's the call to system.tag.readBlocking
. It reads the 2 tags passed as parameters and returns a qualified value for each.
For each of these, we take the value.
Since there are 2 paths, we'll get 2 qualified values, extract 2 values out of them, and assign the values to 2 variables.
We could decompose it like this:
values = []
for qval in system.tag.readBlocking(paths):
values.append(qval.value)
foo, bar = values
1 Like
As far as I know should the code that you suggested to me be the same functionality as what I had but then much easier. I have read it through and looks good.
I have tested it and it looks like almost every thing work like it suppose to but the value that must be passed in the first place of the array is being passed in the whole array
elif action == 1: # Incoming alarm
for index in range(20):
if op_msg[index] == 0:
op_msg[index] = msg_nr
Is there a way to say when this code found the place in the array that is 0 and placed msg_nr is it that it stops the for loop?
idx = op_msg.index(0)
op_msg[idx] = msg_nr
Get rid of the loop entirely.
1 Like
Yes this works!!! thanks guys. It does exactly what I want. I will have to check the rest of it but my work shift is over so I will update you guys next week.
you can also try replacing this:
for index in xrange(20):
if op_msg[index] == msg_nr:
temp_index = index - 1
while temp_index < 20:
temp_index += 1
op_msg[temp_index] = op_msg[temp_index + 1]
with this:
idx = op_msg.index(0)
del op_msg[idx]
This assumes there's only one value to remove
5 Likes
Am I wrong or is this just deleting the first value in the array that is 0?
I replaced the 0 for msg_nr and now it works great, exactly as it should be!
Yes indeed, glad you could get it working.