Git Product home page Git Product logo

Comments (12)

GoogleCodeExporter avatar GoogleCodeExporter commented on July 30, 2024 1
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 [email protected] on 10 May 2010 at 5:41

from modbus-tk.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 30, 2024 1
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 [email protected] on 12 May 2010 at 12:37

from modbus-tk.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 30, 2024
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 [email protected] on 10 May 2010 at 5:39

from modbus-tk.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 30, 2024
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 [email protected] on 10 May 2010 at 5:46

from modbus-tk.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 30, 2024
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 [email protected] on 10 May 2010 at 7:18

from modbus-tk.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 30, 2024
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 [email protected] on 11 May 2010 at 7:29

from modbus-tk.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 30, 2024
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 [email protected] on 11 May 2010 at 9:48

from modbus-tk.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 30, 2024
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 [email protected] on 12 May 2010 at 1:33

from modbus-tk.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 30, 2024
i think may be my device has some problem

Original comment by [email protected] on 12 May 2010 at 1:35

from modbus-tk.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 30, 2024
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 [email protected] on 12 May 2010 at 5:29

from modbus-tk.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 30, 2024
Have you tried to remove the expected length? it should calculate the right 
length
for you

Original comment by [email protected] on 21 May 2010 at 8:29

from modbus-tk.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 30, 2024
Please try the expected_length and rev 110 where reopen of the port has been 
slightly
improved

Original comment by [email protected] on 26 May 2010 at 3:08

  • Changed state: Accepted

from modbus-tk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.