modbus-tk and python3

660 views
Skip to first unread message

Yuriy Vlasenko

unread,
Jan 2, 2016, 12:37:53 PM1/2/16
to modbus-tk
Hi everybody,

I use modbus-tk in a python2 project and all is good. Now I want to migrate to python3 (PyQt and Qt5 and so on). How can I use modbus-tk in python3 project?

Regards,
Yury

Luc JEAN

unread,
Jan 2, 2016, 12:39:40 PM1/2/16
to modb...@googlegroups.com
Hello Yuri,

Python 3 support is in progress. You can try the last commit. If you do it, please let me know if it is ok for you.

Best
luc

--
You received this message because you are subscribed to the Google Groups "modbus-tk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to modbus-tk+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Yuriy Vlasenko

unread,
Jan 2, 2016, 5:07:28 PM1/2/16
to modbus-tk
Hi luc,

Thanks for an answer. I do need modbus library to python3, so I'm ready to try the steps you'll show.

Python 3 support is in progress. You can try the last commit. If you do it, please let me know if it is ok for you.

What is the last commit? I try modbus_tk 0.4.3 - is it right? 
And what is a way of trying? I installed modbus_tk with python3:

sudo python3 setup.py install

There were errors during the installation, so I attach 2 files with screenshots. On the 2-nd screenshot there is a test import, it shows OK. So I decided to continue.
But my project refused to work with the library - cannot import mobdus_tk.

Maybe you can see an error in my proceedings already? Please specify, I'm ready to co-operate.

Not seeing your answer I tried to include all your package in my project and to transform it to puthon3. But it is not so easy :)
BTW I found a puzzling thing in the modbus.py module: the var starting_addressW_FC23 (in an execute() function). It is not defined anywhere, AFAIK.

Best regards,
Yury


Luc Jean

unread,
Jan 2, 2016, 5:21:19 PM1/2/16
to modb...@googlegroups.com
Hi Yuri

Thanks for your help.

You should try the last commit of the github repository


I've tried to start to support Python 3

Best
luc

Yuriy Vlasenko

unread,
Jan 2, 2016, 5:42:48 PM1/2/16
to modbus-tk
luc,

I need a little bit of guidance. 

 

You should try the last commit of the github repository



1) I've made:


2) Next? 
I mean - where are those 281 files and how should I install them (sudo python3 setup.py install will take not the last commit?)

Luc JEAN

unread,
Jan 3, 2016, 4:17:20 AM1/3/16
to modb...@googlegroups.com
Hi Yuri,

You can make a "sudo python3 setup.py develop" See http://stackoverflow.com/a/19048754/117092 for difference

Best
luc

--

Yuriy Vlasenko

unread,
Jan 3, 2016, 12:57:37 PM1/3/16
to modbus-tk
Hi luc,

Thanks for you help with GIT. I am a newbie in this field.
I've made as you said and managed to run my script somehow. But got an error (look screenshots: 1-st is traceback, then the last call (utils.py) and my module call (adc_io.py). I read about this error but with no success.

Regards,
Yury


Luc JEAN

unread,
Jan 4, 2016, 10:15:18 AM1/4/16
to modb...@googlegroups.com
Hello Yuri,

I've pushed a new version on the github repository. It should improve Python 3 support. I am able to run RTU and TCP, master and slave, with Python 2 and Python 3.

One of the "big change" is that data is managed as bytes now in Python 3 and not as string. It could have impact on hooks if you use this feature. There is a 'to_data' function in utils.py if you need to manage conversion between string and bytes.

I am interested to know if it works for you. It would be great if some other people can also make a test on this new version.

Best
luc




Yuriy Vlasenko

unread,
Jan 4, 2016, 10:33:42 AM1/4/16
to modb...@googlegroups.com
Hi luc
 
I've pushed a new version on the github repository

Does it mean that I have to repeat: these steps: "clone" and "python3 setup.py develop"? Is it possible that that error I've mentioned before is corrected now? 
Or have I to use to_data() somehow to correct the error myself?

Regards,
 Yuty

Luc JEAN

unread,
Jan 4, 2016, 10:41:59 AM1/4/16
to modb...@googlegroups.com
You should just have to make git pull and git checkout. It should update the code source. 
I don't have access to all your code so I can't say if all is going to work "out of the box" or if you will need to change a few things. I think if you have no hooks, everything should be ok.

Best
luc





Yuriy Vlasenko

unread,
Jan 4, 2016, 12:18:02 PM1/4/16
to modb...@googlegroups.com
Hi luc,

Success! Thank you very much for you help!

I repeated clone and  python3 setup.py develop and tested your library in my Python3 project. It works OK.

I'm not sure you are interested in details, but I attach a screenshot with the test commands and their results in PyCharm IDE.

My next step is GUI development with Qt Designer 5 and then I return to a full project. Maybe I'll have some new results in mobdbus_tk testing.

Best regards,
Yury

--
You received this message because you are subscribed to a topic in the Google Groups "modbus-tk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/modbus-tk/ifpqanu4Z6g/unsubscribe.
To unsubscribe from this group and all its topics, send an email to modbus-tk+...@googlegroups.com.
modbus_tk-good-test.png

Luc JEAN

unread,
Jan 4, 2016, 12:21:42 PM1/4/16
to modb...@googlegroups.com
Great :-)

Thanks for feedback.

Best
luc

Yuriy Vlasenko

unread,
Jan 6, 2016, 5:02:05 AM1/6/16
to modb...@googlegroups.com
Hi Luc,

I've proceeded with Qt5 just enough to return to MODBUS.
And in looped call of request-respond I have a problem now.

2016-01-04 17:41 GMT+02:00 Luc JEAN <luc....@gmail.com>:

I think if you have no hooks, everything should be ok.

Maybe I'll need to use hooks and logging to find a bug. 
Here is a problem as I see it: 
1) modbus Master sends a request to a Slave and the Slave responds instantly (all transactions are less then 40 ms in duration - oscilloscope says). So far so good...
2) But! But Modbus stack returns the result in 1502 ms after the begin of request. Where does it waste all this time?

The screenshot shows exactly 1502 ms (excuse that lot of my prints).

I try the prev version of my script - with your modbus_tk but under Python2 - no problems. So it is surely not a hardware problem.

Can you suggest the best way to find a bug? If no - OK, I'll search myself.

Regards,
Yury


modbus_tk_1502ms.png

Yuriy Vlasenko

unread,
Jan 7, 2016, 4:11:14 PM1/7/16
to modbus-tk
Hi Luc,

As i wrote:

середа, 6 січня 2016 р. 12:02:05 UTC+2 користувач Yuriy Vlasenko написав:

2) But! But Modbus stack returns the result in 1502 ms after the begin of request. Where does it waste all this time?

The screenshot shows exactly 1502 ms (excuse that lot of my prints).

The only reason I've found is a 

time.sleep(self.get_timeout())

line in send() function in the modbus_rtu.py file. 

I commented the line and everything runs OK, so far. Can you comment it? 

Regards,
Yury


 

Luc JEAN

unread,
Jan 22, 2016, 4:29:34 AM1/22/16
to modb...@googlegroups.com
Hello Yuri,

Sorry for late answer. 

Can you please tell me exactly where is this 'the.sleep'? Do you use master or server?

This  timeout should correspond to the interframe delay. It depends of your baud rate but should only be a few milliseconds. Can you please check the value returned by get_timeout? It should be 

>>> 3.5 * calculate_rtu_inter_char(baud_rate)
For 9600 --> 0.0040104166666666665 seconds

I hope it helps

Best
luc





--

Yuriy Vlasenko

unread,
Jan 24, 2016, 6:18:42 AM1/24/16
to modb...@googlegroups.com
Hello Luc!

I use PC as a Master. 

2016-01-22 11:29 GMT+02:00 Luc JEAN <luc....@gmail.com>:
Hello Yuri,

Can you please tell me exactly where is this 'the.sleep'?

I attached a screenshot of the problem place (selected in editor) in /modbus_tk/modbus_rtu.py file. After I commented line 128 - problem dissolved :) 
As you can see, I'd printed the time.time() before and after the time.sleep() call. And the result showed - unwanted delay lays here.


 
Can you please check the value returned by get_timeout? It should be 

>>> 3.5 * calculate_rtu_inter_char(baud_rate)
For 9600 --> 0.0040104166666666665 seconds


Sorry, I cannot do it now. Another project is on my desk.

Regards,
Yury

Yuriy Vlasenko

unread,
Jan 24, 2016, 6:19:40 AM1/24/16
to modb...@googlegroups.com
Sorry! Attachment :)

--
You received this message because you are subscribed to a topic in the Google Groups "modbus-tk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/modbus-tk/ifpqanu4Z6g/unsubscribe.
To unsubscribe from this group and all its topics, send an email to modbus-tk+...@googlegroups.com.
my-intrusion-in-send-method.png

Luc JEAN

unread,
Feb 4, 2016, 2:42:53 PM2/4/16
to modb...@googlegroups.com
Hi Yuri,

Sorry for late answer. I didn't have time to look at this yet. Could you please enter an issue on the githup page to follow this problem?

Best
luc

Yuriy Vlasenko

unread,
Feb 4, 2016, 3:07:07 PM2/4/16
to modbus-tk
Hi Luc,

You write:

Could you please enter year after githup on the page to follow this problem?

I do not know exactly what I have to do now. Please tell me.

Regrds,
Yury

Luc JEAN

unread,
Feb 4, 2016, 4:28:19 PM2/4/16
to modb...@googlegroups.com
Yuri,

Can you please enter an issue with as much details as possible for the timing issue you have on Python 3 : https://github.com/ljean/modbus-tk/issues?

Thanks

Best
luc

--
Reply all
Reply to author
Forward
0 new messages