![]() |
Forum Index : Microcontroller and PC projects : Modbus Protocol in MMBasic
![]() ![]() |
|||||
Author | Message | ||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10315 |
Can you also confirm the bit pattern for modbus so I can test. Is it: start bit, 8 data bits, parity bit, stop bit? Is parity even or odd? or do you prefer 2 stop bits instead of parity? |
||||
goc30![]() Guru ![]() Joined: 12/04/2017 Location: FrancePosts: 435 |
its classic, 9600,8,n,1 |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10315 |
I'm confused - is this wrong? |
||||
goc30![]() Guru ![]() Joined: 12/04/2017 Location: FrancePosts: 435 |
I use RTU mode (binary frames with transmitting zero value) |
||||
Turbo46![]() Guru ![]() Joined: 24/12/2017 Location: AustraliaPosts: 1642 |
Hi Peter, No it's not wrong but I have never seen the ASCII version used. I've never seen the parity bit used either. Not sure about the number of stop bits though. I don't think it matters. I confess that I don't understand the interrupt problem but will continue my attempts to build a Modbus master and slave(s) with the MM2. Bill Keep safe. Live long and prosper. |
||||
goc30![]() Guru ![]() Joined: 12/04/2017 Location: FrancePosts: 435 |
this function is used for real-time process. if you work in polling mode, you spend time to wait (wait to receive a char, or wait taht sender has finish to send a char). In Modbus protocole, time-out is very important. It is used to begin master frame or to make error flags, etc.. second point: if you work in polling mode, you cann't use an other COM port also in polling mode. In my appli, i need the "1sec signal" from GPS with 1 millsec precision. In polling mode it is impossible (in racing appli, you have 1 GPS on start line, and 1 GPS in finish line) |
||||
Azure![]() Guru ![]() Joined: 09/11/2017 Location: AustraliaPosts: 446 |
Here is a link to the current Modbus Serial Standard Here is an extract on the serial protocol (there are some illustrations in the pdf): |
||||
goc30![]() Guru ![]() Joined: 12/04/2017 Location: FrancePosts: 435 |
Hi Azure With CRC16 (and short time-out), it is not necessary to add an odd/even bit |
||||
Azure![]() Guru ![]() Joined: 09/11/2017 Location: AustraliaPosts: 446 |
I was only providing a reference to the official Modbus serial protocol. It is linked directly from the Modbus website and is the new specification, there is an older specification for legacy purposes. |
||||
Phil23 Guru ![]() Joined: 27/03/2016 Location: AustraliaPosts: 1667 |
Posted this a few days back. It would essentially be a Modbus RTU master polling 3 devices using 2 different requests. Phil. |
||||
Turbo46![]() Guru ![]() Joined: 24/12/2017 Location: AustraliaPosts: 1642 |
Hi All, Does anyone know of a good Modbus master program for the PC? Hopefully a free one. Thanks Bill Keep safe. Live long and prosper. |
||||
goc30![]() Guru ![]() Joined: 12/04/2017 Location: FrancePosts: 435 |
hi Bill Modbus is only a communication protocol and not a complete application, so first you have to know what you want to do with, then choose a prog language, finally know the device (s) you want to connect to the PC and using MODBUS protocol. if the device is an RTU or any "end user" thing, then you have to see with the manufacturer who usually offers a MODBUS driver for PC. So we need more precision |
||||
CircuitGizmos![]() Guru ![]() Joined: 08/09/2011 Location: United StatesPosts: 1427 |
http://qmodbus.sourceforge.net/ Micromites and Maximites! - Beginning Maximite |
||||
Turbo46![]() Guru ![]() Joined: 24/12/2017 Location: AustraliaPosts: 1642 |
Thanks CircuitGiszmos, I'll give it a go. Have you used it? @goc30: I wish to make a Modbus Slave/RTU using an MM2, test it thoroughly with a PC Modbus master and then make a Modbus master using another MM2 or a Maximite. They will comply with the 'Modbus Serial Standard' as in the link supplied by Azure above. The RTU will have Digital Outputs, Digital Inputs and Analogue Outputs. I am aware for your need for a "transmit buffer empty" interrupt, if I hit that problem I will find a way around it. Regards, Bill Keep safe. Live long and prosper. |
||||
CircuitGizmos![]() Guru ![]() Joined: 08/09/2011 Location: United StatesPosts: 1427 |
Yes I have used it. Great for initial slave development and testing. Micromites and Maximites! - Beginning Maximite |
||||
Turbo46![]() Guru ![]() Joined: 24/12/2017 Location: AustraliaPosts: 1642 |
Modbus function 05 (Force single coil) question. Thanks to TassyJim for providing the CRC in MMBasic and CircuitGizmos for recommending Qmodbus my Modbus slave implementation is progressing slowly as time permits. For those of you who have a wider experience with the use of Modbus than me, I have a question concerning the use of function 05: I will be using bi-stable relays for the outputs - so two separate pulsed outputs are required - one for ON (close) and one for OFF (trip). This can be handled by using two points in the memory map, one for "device 1 ON" and one for "device 1 OFF". An alternative is to have one point in the memory map for "device 1" and use logic within the program to pulse the appropriate ON or OFF output. Which is the more standard approach? I am, or rather was, familiar with protection relays for electricity substations that used the first approach. A third method would be to use a demultiplexer to reduce the number of I/O pins but that's not for me in this case. Thanks Biil Keep safe. Live long and prosper. |
||||
Volhout Guru ![]() Joined: 05/03/2018 Location: NetherlandsPosts: 5091 |
If you use the alternate method, you will loose control of the actual state of the relay. There are ways to "remember" the state, but you are never 100% sure. I.e. if there was a short disconnect during a command, you think it is in ON state, while it did not get the pulse, and actually is in OFF state. Out of sync forever after..... Only way to resync is a slave reset. PicomiteVGA PETSCII ROBOTS |
||||
Turbo46![]() Guru ![]() Joined: 24/12/2017 Location: AustraliaPosts: 1642 |
Thanks Volhout, that's a good point. One of the digital inputs will report the state of the output to the master though, so the master should know the result of the control operation after the next poll (read input status). I am assuming that the master has the responsibility to send the correct command. Bill Keep safe. Live long and prosper. |
||||
![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |