Author Topic: Lost in MODBUS land  (Read 11135 times)

jbrandall

  • Newbie
  • Posts: 19
  • farmer boy
    • View Profile
Lost in MODBUS land
« on: November 27, 2011, 06:06:03 PM »
I'm having so much fun with one Nano-10 that I got another one.  Actually, I need a third analog input and everything I read says it is so easy to have the two plc's talk to each other.  Not so much for me!  What I've got so far is: nano1 and nano2 up and running and wired together via the RS485 ports with about 18" of twisted pair, negative to negative and positive to positive. They are also both hooked up to a wireless router via the RJ45 ports, but with no internet. The router is at 192.168.2.1, nano1 is at 192.168.2.5:9080, ID 01, and nano2 is at 192.168.2.6:9080, ID 02. They both use a common NPN proximity sensor to control input2 on each plc (could this be a problem?)

The programming for nano2 is that when input2 is on, it does a custom function that is:  

M= ADC(1)   REM read moisture
Input[10] = M   REM store moisture
N=Input[10]   REM for testing

This seems to work when viewed with TRiLOGI.  There is no setup routine (yet).

The programming for nano1 is that when input2 is on, it also does a custom function which is longer, but ends with:

REM hyd pressure test
P = ADC(1)  REM hyd pressure
DM[3879] = P
W = ADC(2)  REM scale pressure

REM go get moisture
M=READMODBUS(3,2,10)   (as per Modbus.PC6 sample program)

When viewed with TRiLOGI, P and W change as expected, but M stays at zero.  There is a setup routine for this nano, but nothing with SETSYSTEM or SETPROTOCOL.

My TRiLOGI manual shows the syntax as SETSYSTEM n,data - with the choices for n being 1,2,or 3 and the choices for data being 4,5,6,8, and 256.  The user's manual for the Nano-10 shows an examples of SETSYSTEM 19,0 (page 14-6), SETSYSTEM 253,n (page 12-5), and I'm sure I've seen SETSYSTEM 20,?? somewhere, but with so little information, I don't dare play with that.

I think that I want to use the RS485 port (COMM1?) but believe that the NETCMD$ function would also work.  If possible, could someone please show programming for both methods.

Thanks


support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:Lost in MODBUS land
« Reply #1 on: November 27, 2011, 09:03:26 PM »
The problem is the Nano-10 doesn't have COMM3. It has only COMM1 so you should change the MODBUS command to reference COMM1 instead of COMM3.

Also I hope you understand that INPUT[10] INPUT[10] is the variable name reserved for the inputs #161 to #168. Although these are not available physically (and therefore it actually works). I suppose you probably find it convenient as a quick test.

The recommended way of doing it is to write to data memory (DM[1] to DM[4000]) and the READMODBUS command can be used to access the DM memory which is mapped to address 1000 to 4999.
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

jbrandall

  • Newbie
  • Posts: 19
  • farmer boy
    • View Profile
Re:Lost in MODBUS land
« Reply #2 on: November 28, 2011, 12:33:02 PM »
I changed M=READMODBUS(3,2,10) to M=READMODBUS(1,2,10) and get the same results; M=0,  should be 1760.

I am trying to save all the DM's for data logging to be retrieved by ExcelLink and thought I could use unused input and output memory as 16 bit variables. So I read about WORD ADDRESS MAPPING (p 14-9) and did the following:

 I tried M=READMODBUS(1,2,INPUT[10]])  answer 2
then I tried M=READMODBUS(1,2,40010)  answer 30368
changed nano2 to DM[1]=M
tried M=READMODBUS(1,2,DM[1])  answer 2
tried M=READMODBUS(1,2,4101)   answer 0

I'm still confused....

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:Lost in MODBUS land
« Reply #3 on: November 28, 2011, 09:56:20 PM »
Chapter 14, section 14.6.1 shows how the PLC's internal register is mapped to Modbus register space.

1) Assuming Nano#2  stores its data in DM[1] to DM[10].

2) According to Table 14.1, DM[1] is mapped to Modbus holding register space 41001.

3) Section 14.7 explains that the address parameter to be passed to READMODBUS or READMB2 command is the holding register address minus 40001. Therefore to read DM[1], you use command:
       
      M = READMODBUS(1, 2, 1000)   ' 41001-40001

4) To read all DM[1] to DM[10] from Nano#2 to DM[101] to DM[110] in Nano#1 using a single command, you can use READMB2:

     READMB2 1, 2, 1000, DM[101], 10



   


« Last Edit: November 30, 2011, 08:40:18 AM by support »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS