Author Topic: Modbus rtu read Digital Inputs problem  (Read 7103 times)

detunius

  • Newbie
  • *
  • Posts: 6
    • View Profile
Modbus rtu read Digital Inputs problem
« on: November 29, 2014, 10:28:09 AM »
Hi,

I have diy setup:

Arduino uno running simple modbus rtu slave library:
http://code.google.com/p/arduino-modbus-slave/downloads/detail?name=MODBUS.zip&can=2&q=
 , some sketch for testing inputs outputs from same arduino libbrary.
My arduino is connected to PC using rs232 ->USB adapter. I am using Windows 7 x64 and AdvancedHMI v35.
Problem is that i can only read (basic indicator) first input address from arduino. like: 10001 , but other basic indicators with next addresses stays inactive all the time.
Write function working perfect, can read and can write without problem adresses 00001-00016, analog read also all ok addr:30001-10010. All workin values are changing as supposed to be. Only one problem with digital inputs read, if i change address for the first basic indicator it starts reading that input, but all others stays inactive.
My arduino setup is working correctly(i think) i have tested it with mbus tester:   http://www.modbus.pl/node/10 it reads the digital inputs corectly with correct addresses.
What could be the problem? is it related with arduino modbus library or i don't know how to put correct adreses in advanced HMI . I am putting them simply 10001, 10002, 10003 one address for each indicator in PlcAddressSelectColor2.
Please help.


Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Modbus rtu read Digital Inputs problem
« Reply #1 on: November 29, 2014, 11:12:37 AM »
I am trying to test this. I downloaded the library and uploaded the example program into an Arduino Leonardo. I set my Com port and baud rate to 9600. When I start the program, the RX light blinks on the Arduino, but I never get a TX light showing the response.

What settings are you using for Stop bits and parity?

detunius

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Modbus rtu read Digital Inputs problem
« Reply #2 on: November 29, 2014, 11:27:14 AM »
I am using standar 9600,  8E1,
have you set arduino:


//Assign the modbus device ID. 
  regBank.setId(1)

and the same id in the modbus rtu properties station address ?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Modbus rtu read Digital Inputs problem
« Reply #3 on: November 29, 2014, 11:34:43 AM »
I tried those settings but no luck. I am running the example that comes with the library which sets the id to 1. It doesn't want to respond to any setting. I wonder if it has anything to do with it being a Leonardo over USB.

detunius

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Modbus rtu read Digital Inputs problem
« Reply #4 on: November 29, 2014, 11:46:02 AM »
Arduino leonardo is based on ATmega32u4 maybe this is the problem off communication. I am using arduino uno type board with Atmega328 chip.
Now i will try to do same thing with arduino mega 2560, will post the result.

detunius

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Modbus rtu read Digital Inputs problem
« Reply #5 on: November 29, 2014, 11:54:22 AM »
And with Arduino mega 2560 same thing, i have full communication , but can read only first addres of analog inputs, others no effect.
Communication is made throught the same port as used program arduino usb serial. 9600b 8N1 handshake controll -none.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Modbus rtu read Digital Inputs problem
« Reply #6 on: November 29, 2014, 12:06:10 PM »
The only other Arduino I have is an Esplora. I will give that one a try.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Modbus rtu read Digital Inputs problem
« Reply #7 on: November 29, 2014, 12:09:53 PM »
I get the same thing with the Esplora. One blink on the RX light and no response. Are you trying the example that is part of the Modbus libray download?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Modbus rtu read Digital Inputs problem
« Reply #8 on: November 29, 2014, 12:21:38 PM »
I tried this out on a Click PLC and I do see the same problem you are seeing. I will figure this out here shortly.

detunius

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Modbus rtu read Digital Inputs problem
« Reply #9 on: November 29, 2014, 12:25:15 PM »
Yes i am using the same library example. only my slave station adres is 10 and i add more random generators for more digital input values. In the example only for 10001 is added 01 random simulation. But this is not the case. You are not getting communication at all

It is nice to have such quick support.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Modbus rtu read Digital Inputs problem
« Reply #10 on: November 29, 2014, 12:44:05 PM »
I wasn't getting any response at all from the Arduino. I even put a break point at the lowest level event handler to see if anything at all came back, but nothing. However I did test it with the PLC and found the problem.

If you go to line 831 in ModbusRTUCom.vb and change the code to this:
Code: [Select]
                        While index < PolledAddressList(i).Address.NumberOfElements
                            Dim ValueIndex As Integer
                            If PolledAddressList(i).Address.BitsPerElement > 1 Then
                                '* INT32 values in Modbus skip every other address, so compensate
                                ValueIndex = CInt((PolledAddressList(i).Address.Element - SavedRequests(e.TransactionNumber).Element) / (PolledAddressList(i).Address.BitsPerElement / 16)) + index
                            Else
                                '* Bit level
                                ValueIndex = CInt((PolledAddressList(i).Address.Element - SavedRequests(e.TransactionNumber).Element))
                            End If
 
                            If SavedResponse(e.TransactionNumber).Values.Count > ValueIndex Then
                                f.Values.Add(SavedResponse(e.TransactionNumber).Values(ValueIndex))
                            End If
                            index += 1
                        End While

detunius

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Modbus rtu read Digital Inputs problem
« Reply #11 on: November 29, 2014, 12:56:45 PM »
That worked perfectly, thank you !

Now lot of arduinos can be as part of HMI hardware without using ethernet shields.

For curiosity - What that change actualy does ? becouse i am not a vb specialist.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Modbus rtu read Digital Inputs problem
« Reply #12 on: November 29, 2014, 01:02:49 PM »
When using controls with address that are consectutive or close together, the driver will group them into a single read for efficiency. The data comes back in an array. The top level driver (ModbusRTUCom) must find which element in the array belongs to which address and send it to the control for display. The current code would parse INT and INT32 correctly, but not bits.