Page 1 of 1

ModBus Master Read coil

Posted: Thu Aug 24, 2023 11:29 am
by george_b
Hi,

For the purpose of a project i need to write and read several bits using read and write coil function of modbus.

I can successfully write to the slave coil status but i can not read the coil status from the slave.

Is there any example using Modbus Master to read coil from a slave?

I would be really grateful for anyone who can give me some help on this one.

Thank in advance!


Regards
George

Re: ModBus Master Read coil

Posted: Thu Aug 24, 2023 11:35 am
by chipfryer27
Hi

The WiKi is a good starting point.

https://www.flowcode.co.uk/wiki/index.p ... s:_System)

Hope this helps.

Regards

Re: ModBus Master Read coil

Posted: Thu Aug 24, 2023 12:49 pm
by george_b
Hi,


Thanks for you reply. I have already checked the examples in wiki page. None of them shows how to read coils while using Modbus Master component!

Re: ModBus Master Read coil

Posted: Mon Aug 28, 2023 9:59 am
by george_b
would it be possible for any member to attach an example of a program reading coil using Modbus Master?

Thanks in advance!

Regards
George

Re: ModBus Master Read coil

Posted: Mon Aug 28, 2023 10:41 am
by seokgi
Hello?
I program using the 3XXXX Holding Register address.
This advantage is that only one address is used during Modbus communication and there is less error occurrence.

Hope this helps.

Re: ModBus Master Read coil

Posted: Mon Aug 28, 2023 2:07 pm
by george_b
Attached is a program thrying to read modbus registers using Modbus Master component.

Note that this program is not working on hardware. Any idea what is wrong ?


Regards
George

Re: ModBus Master Read coil

Posted: Mon Aug 28, 2023 5:15 pm
by chipfryer27
Hi

The "old" forum has a lot of info re Modbus. Don't know if it will help

https://www.matrixtsl.com/mmforums/sear ... l&start=25

Also, these Demo's appear to be using coils.

https://www.flowcode.co.uk/wiki/index.p ... s:_System)

Regards

Re: ModBus Master Read coil

Posted: Tue Aug 29, 2023 2:31 pm
by BenR
Hi George,

Looking at your program it appears you're close. Have you done a LED flasher test to confirm things like delays are accurate, this is required to get the communications baud correct.

https://www.flowcode.co.uk/wiki/index.p ... ED_flasher

I've changed a couple of things in your program, firstly to move the delay so that you're not constantly hammering the comms and seconds to change the index for GetResponseInt from 0 to 4 which is the start of the return data.

MODBUS.fcfx
(15 KiB) Downloaded 411 times
Lastly the RegAddress parameter might not be correct, what address are you trying to read?

Re: ModBus Master Read coil

Posted: Mon Oct 09, 2023 1:58 pm
by george_b
Hi Ben and thanks for you reply.

I did manage to make it working after a loooot of time trying and trying different things.

Indeed GetResponseInt must be 4 as you said.

RegAddress is correct since the device i am trying to read gives me this registers map .

Thanks again for your support.


Regards
George