Author Topic: 32 bit modbus slave  (Read 15531 times)

bahpulo

  • Newbie
  • *
  • Posts: 7
  • I'm a llama!
    • View Profile
32 bit modbus slave
« on: May 21, 2012, 12:01:25 PM »
Can anyone please help? I have a flow meter which can speak either modbus ASCII or modbus rtu. The data format to read the modbus registers through the rs485 are in the form of real4. I am using a nano 10 plc to connect to this flow meter, so that I can read the registers into the nano 10 plc. I need to be able to do this so that my scada software can read data from the nano 10. However since nano 10 is 16 bits, I  want to know how I can read 32 bit real registers from the flow meter  into the nano 10 using modbus ASCII or RTU through the rs485 port.

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re: 32 bit modbus slave
« Reply #1 on: May 21, 2012, 06:03:43 PM »
Nano-10 supports 32-bit variables. But each Modbus register by default is 16-bit. So to read 32-bit it means you need to read two adjacent 16-bit Modbus registers to form a 32-bit register.

All you need to do is to use the READMB2 command to read 2 registers from your meter into the DMs and then use the SETHIGH16 command to insert one of the word into the upper 16-bit of a 32-bit variable and the second word into the lower 16-bit. Together they form a 32-bit integer variable.

See example in EEPROM.PC6 on how to use the SETHIGH16 command to convert two 16-bit words into a 32-bit long word.

The above steps read in the data as 32-bit variable. But since Nano-10 does not support floating point number it will not be able to intepret the number as a "real" floating point number.  It depends on what you need to do, you may be able to write a TBASIC command to convert the 32-bit floating point number into integer - although this is a pretty complicated stuff.

We have one FAQ thread showing how to convert integer  number into a 32-bit floating point representation so that it can be read by external Modbus master:

http://www.tri-plc.com/yabbse/index.php?board=2;action=display;threadid=1787

You might be able to follow the example and write your program to convert floating point number into integer number if that's what you need to do for processing.
« Last Edit: May 21, 2012, 06:12:00 PM by support »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

bahpulo

  • Newbie
  • *
  • Posts: 7
  • I'm a llama!
    • View Profile
Re: 32 bit modbus slave
« Reply #2 on: May 23, 2012, 04:50:40 AM »
Thanks for your reply, i must say that am new to plcs. Before going to the 32 bit problem, first of all i would like to establish a connection between the nano and the flow meter and read a 16 bit register into the DM. I found out that the readmodbus is not working between the two devices.

If i connect either the flow meter or nano plc using the rs485 to usb on my  pc, i would then get a reading with my scada software. This means that my serial setup is right. Please find here attached my ladder diagram, i may be doing something wrong, also find here the custom function codes used.

Cusfn for rs485;
SETBAUD 1,&H03

Cus_auto;
if DM[1]=1 then
setio pump
endif

if DM[1]=0 then
ClRIO pump
endif

rdmod1s;
DM[2]= READMODBUS(1,1,1442)
DM[3]= READMODBUS(1,1,158)



support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re: 32 bit modbus slave
« Reply #3 on: May 23, 2012, 07:21:43 AM »
Is your flow meter using Modbus RTU protocol (most are) instead of a Modbus ASCII?

For Modbus RTU, add 10 to the serial channel number. On Nano-10 this means channel 11 instead of channel 1. Try the following:

DM[2]= READMODBUS(11,1,1442)
DM[3]= READMODBUS(11,1,158)

Also your ladder program must be invoking the custom function that read the modbus everytime you need a new data.
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

bahpulo

  • Newbie
  • *
  • Posts: 7
  • I'm a llama!
    • View Profile
Re: 32 bit modbus slave
« Reply #4 on: May 25, 2012, 04:31:14 AM »
Thanks for the response. My flow meter can do both RTU and Ascii. I have tried the following codes with no success.

FOR MODBUS RTU
DM[2]= READMODBUS(11,1,1442)
DM[3]= READMODBUS(11,1,158)

FOR MODBUS ASCII
DM[2]= READMODBUS(1,1,1442)
DM[3]= READMODBUS(1,1,158)

I am now stuck and i don't know what to do. Can i send you the manual for the flow meter?

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re: 32 bit modbus slave
« Reply #5 on: May 25, 2012, 03:48:23 PM »
The best way to troubleshoot communication issue between the PLC and the device is to connect the U-485 adapter to the PC to monitor the traffic between the two devices. i.e. the U-485 RS485 terminals "tap" into the RS485 wires between the PLC and the flow meter.

For this to work you need to use a serial port monitoring software. Something like HyperTerminal will work quite well to monitor ASCII based communication such as Modbus ASCII but for binary type communication a 3rd party software can be downloaded/purchased.

Once you setup the monitoring program, trigger the Nano-10 to send out the command. If the communication hardware/software is setup properly the command should appear on the terminal software. Then check if the slave respond to the command. That way you have a clearer vision of what's going on between the two devices.
« Last Edit: May 26, 2012, 01:06:56 PM by support »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

bahpulo

  • Newbie
  • *
  • Posts: 7
  • I'm a llama!
    • View Profile
Re: 32 bit modbus slave
« Reply #6 on: May 26, 2012, 10:43:34 AM »
Finally i was able to connect to the flow meter using the nano 10. Turns out that the relay that invokes the reading of the registers should be normally close instead of normally open as on the demo examples. Many thanks