Open GoogleCodeExporter opened 9 years ago
additional, i have run that code in a thread like this:
self.thread = threading.Thread(target=self.Run, args=(self.dct, self.dctname))
self.thread.setDaemon(1)
self.thread.start()
self.alive.set()
def Run(self, dct, dctname):
while self.alive.isSet():
master....
Original comment by bcw...@gmail.com
on 10 May 2010 at 5:39
Hello
I am not sure that I understand your problem.
Do you miss a modbus_tk.modbus_rtu.ModbusInvalidResponseError exception when the
slave returns an bad CRC?
Is it right?
Original comment by luc.jean@gmail.com
on 10 May 2010 at 5:41
i find a method to resolve this problem:
when catch this type of exception:
i try to do master.close(),
then it can work normaly
Original comment by bcw...@gmail.com
on 10 May 2010 at 5:46
So the problem was that you were not able to communicate anymore after a bad CRC
query. Right?
Normaly, the master should "flush" the buffer before sending a query so you
shouldn't
have this problem. I 'll look at this pb.
However if you have a workaround that fix the pb, it's perfect.
Best
Original comment by luc.jean@gmail.com
on 10 May 2010 at 7:18
when modbus_tk.modbus_rtu.ModbusInvalidResponseError exception raised, i try to
use
master.close() to fix it.
unfortunately , it raised a new Exception like this:
Response length is invalid 0- Code=ModbusInvalidResponseError.
although I tried to use master.close() to make it work, it also return "Response
length is invalid 0- Code=ModbusInvalidResponseError" on the next loop every
time.
this is my log:
2010-05-11 15:22:16,407 ERROR main.Run Thread-1 Invalid CRC in response-
Code=ModbusInvalidResponseError
2010-05-11 15:22:16,407 DEBUG modbus.execute Thread-1 -> 1-3-0-13-0-1-21-201
2010-05-11 15:22:18,421 DEBUG modbus.execute Thread-1 <-
2010-05-11 15:22:18,421 ERROR main.Run Thread-1 Response length is invalid 0-
Code=ModbusInvalidResponseError
2010-05-11 15:22:18,421 DEBUG modbus.execute Thread-1 -> 1-3-0-15-0-1-180-9
2010-05-11 15:22:20,436 DEBUG modbus.execute Thread-1 <-
2010-05-11 15:22:20,436 ERROR main.Run Thread-1 Response length is invalid 0-
Code=ModbusInvalidResponseError
2010-05-11 15:22:20,436 DEBUG modbus.execute Thread-1 -> 1-3-0-16-0-41-133-209
Original comment by bcw...@gmail.com
on 11 May 2010 at 7:29
It seems that you don't receive any answer at all. Maybe you should investigate
why
the device doesn't answer. Maybe teh query is not Oh (wrong slave id?)
Have you set a timeout? master.set_timeout(1.0) set a 1 sec timeout. If no
answer is
received before the to elapsed an exception should be raised. Maybe the
Exception
name should be improved.
But getting an exception is not a problem, you should catch it.
Original comment by luc.jean@gmail.com
on 11 May 2010 at 9:48
I have set the timeout 3.0s, and catched it.
my code like this:
>>modbus code:
master = modbus_rtu.RtuMaster(serial)
master.set_timeout(3.0)
master.set_verbose(True)
while True:
try:
resp = self.master.execute(1, cst.READ_HOLDING_REGISTERS, 13, 1)
except modbus_tk.modbus.ModbusError, e:
logger.error("%s- Code=%d" % (e, e.get_exception_code()))
except modbus_tk.modbus_rtu.ModbusInvalidResponseError, e:
logger.error("%s- Code=ModbusInvalidResponseError" % (e))
self.master.close()
except:
logger.debug("other")
Original comment by bcw...@gmail.com
on 12 May 2010 at 12:37
Hi Luc,
I have found another pb,
>>code:
logger.info(master.execute(4, cst.READ_HOLDING_REGISTERS, 16,
expected_length = 38))
when the expected_length=38 it raise a exception like this:
"modbus_tk.modbus.ModbusInvalidResponseError: Response address 3 is different from
request address 4 "
when the expected_length>=39 it raise a exception like this:
"modbus_tk.modbus.ModbusInvalidResponseError: Invalid CRC in response"
Original comment by bcw...@gmail.com
on 12 May 2010 at 1:33
i think may be my device has some problem
Original comment by bcw...@gmail.com
on 12 May 2010 at 1:35
i use another tool to test my device , it work nice.
i think there are some thing wrong in pyserial.
when it read the serial port ,it can't read the whole respose byte.
so i got a bad CRC
Original comment by bcw...@gmail.com
on 12 May 2010 at 5:29
Have you tried to remove the expected length? it should calculate the right
length
for you
Original comment by luc.jean@gmail.com
on 21 May 2010 at 8:29
Please try the expected_length and rev 110 where reopen of the port has been
slightly
improved
Original comment by luc.jean@gmail.com
on 26 May 2010 at 3:08
Original issue reported on code.google.com by
bcw...@gmail.com
on 10 May 2010 at 5:34