Hi all,
I have program in which I read register’s value over Modbus.
In main thread I have method read_Reg defined like below:
def read_Reg(self, attr):
self.info_stream("Command number = %d" % self.ord)
# variable that is used for tracking how often this function is called
self.ord += 1
if (self.get_state() in [PyTango.DevState.STANDBY]):
self.attr_Reg_read = self.mtc.read_holding_registers(2, 1, unit=1)
self.info_stream("Data = %d" % self.attr_Reg_read.registers[0])
attr.set_value(self.attr_Reg_read.registers[0])
elif (self.get_state() in [PyTango.DevState.RUNNING]):
self.info_stream("Data = %d" % self.Reg_Data)
attr.set_value(self.Reg_Data)
In Standby mode, value of register is constant, while in Running state value is changing every 100ms. This is enabled by another thread beside main.This thread is started by executing command Change, and stopped by executing command Stop.
def t_Run_Reg(self):
self.set_state(PyTango.DevState.RUNNING)
self.t_mtc = ModbusTcpClient(host="10.1.1.138", port=502)
while (self.t_mtc.connect() == False):
pass
try:
# used for control when to start or stop thread
while not self.t_LED_stop:
regN = (random.sample([4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768], 1)).pop()
self.t_mtc.write_register(52, regN, unit=1)
self.Reg_Data = regN
time.sleep(self.speed / 1000.0)
finally:
self.t_mtc.close()
At start of a thread I’m establishing connection, and when it is established, I choose one random number and write it to the PLC’ register.
When I start program, register change its value at speed of 100ms on the PLC’s side, but its value isn’t displayed in AtkPanel. But when I click on three dots on the right, current value of register is showed.
In the first picture is the moment before clicking three dots
.
In the next picture is the moment after clicking three dots.
From this you can see that function read_Reg is called only by clicking on three dots (I dont know If that means that I want to refresh values, but my refresh period is already set to 1000ms).
What is more confusing, from Log Viewer you can see that command is called twice in a row.
My question is next, why function read_Reg isn’t called every 1000ms, which is my refreshing period?
Again, second thread is working fine changing register’s value, and when I click on three dots, read value is correct.
I hope I was clear enough so someone can help me.
Best regards,
Dusan