MODBUS implementation

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
satya369
Posts: 32
Joined: Tue Aug 18, 2015 3:45 am

MODBUS implementation

Post by satya369 » Wed Mar 16, 2016 6:15 pm

Does any one know how to implement MODBUS protocol on pyboard?

Here is the basic description of what I want to do.
1. Read a variable (for example accelerator x axis) and store it in a register X
2. Use my user interface software to read the register from pyboard using Modbus RTU
3. I also want to write to variable Y using my user interface through Modbus RTU.

Once I can figure out how to implement this, I will expand this to reading and writing to multiple registers.

Can someone point me out in right direction?

miltmobley
Posts: 30
Joined: Mon Mar 07, 2016 11:44 pm

Re: MODBUS implementation

Post by miltmobley » Thu Mar 17, 2016 3:56 am

All I know about modbus i read on wikipedia. But it appears to be a command and control protocol that can be used
over serial links, with some computer being the master and your pyboard being a slave. You would have to implement
a monitor program to run on the pyboard that would continuously wait for commands to arrive on the serial link, process
them and return data and/or status to the master, similar to the way the gdb debug stub does.

Hope this helps.

satya369
Posts: 32
Joined: Tue Aug 18, 2015 3:45 am

Re: MODBUS implementation

Post by satya369 » Fri Mar 18, 2016 2:20 am

I am stuck at how to implement the code on pyboard. I have my MODBUS code on my PC that works with another device that already has MODBUS protocal implemented on it. I was able to talk to the salve and write to it.

The step where I am stuck is, with MODBUS protocol I have to define registers and have to implement communication on Pyboard. I was able to send ASCII commands like "X=1", "X" to the pyboard and got responses back through UART. But have no idea how to implement MODBUS. Little complex for the knowledge I have.

vfl68
Posts: 4
Joined: Sun Feb 28, 2016 9:54 am

Re: MODBUS implementation

Post by vfl68 » Fri Mar 18, 2016 7:32 am

I had a look on MODBUS on Wikipedia, and found that link : https://github.com/bashwork/pymodbus/tr ... r/pymodbus
It seems to be a python implementation of the different MODBUS protocols.
Perhaps you can start from that and adapt it to micropython,

satya369
Posts: 32
Joined: Tue Aug 18, 2015 3:45 am

Re: MODBUS implementation

Post by satya369 » Sat Mar 19, 2016 2:44 pm

I think this is a MOBUS protocol you can implement on your PC to talk to devices that can talk MODBUS as well. I already have basic MODBUS protocol implemented on my PC.

I am also look for information about how to implement MODBUS on the Pyboard itself. Since the pyboard has to respond to MODBUS commands that I send from my PC. Right now I dont think pyboard is setup to respond as registers have to be defined.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: MODBUS implementation

Post by pythoncoder » Sat Mar 19, 2016 4:55 pm

I think @vfl68 was suggesting that you use some of the code from that site to create an implementation to run on the Pyboard. Strip it down to a usable subset capable of running on a resource-constrained device. That would be my approach; easier than designing it from scratch.
Peter Hinch
Index to my micropython libraries.

satya369
Posts: 32
Joined: Tue Aug 18, 2015 3:45 am

Re: MODBUS implementation

Post by satya369 » Sun Mar 20, 2016 4:08 am

Thank you for the clarification.

I was looking at some of the examples that pymodbus has, these might be helpful. @vfl68, thank you for the information.

If I have any questions I will let you guys know.

Bradnz
Posts: 1
Joined: Tue Oct 31, 2017 12:19 am

Re: MODBUS implementation

Post by Bradnz » Tue Oct 31, 2017 12:27 am

Hi

I’m looking for a modbus rtu library or code example. How did you get on with this? Do you have anything you would be happy to share with me? I’m a bit stuck and need modbus operating on micropython for a project

Thx

Post Reply