3
On twido PLC you can use two methods for modbus master communication. First method is that you use so called com-macros (on example which you writed, this is also easier). If you use comm macros, you don't need to take care of modbus query syntaces, because comm macro will do it automatically on plc program. Second method is that you write every command to plc program via operate blocks. If you use this method, you need take care of bunch of parameters, modbus query function, how many bytes will be transferred an so on... Com macro is lot of easier to use than second method. Com macros can configured on plc program if you doubleclick com macro ex. C_RDNW_ADDR1 3 := %MW200 C_RDNW3 48 means use of com macro number 3. Read N words starting of address %MW200 (from slave which is configured on comm macro) Second line calls com macro3 and 48 number tells to com macro read 48 words from slave. If you want see real code for comm macro, select first list editor and after that from tools ->Display real code equivalent fo com macros.. ex. code for C_RDNW_ADDR1 3 := %MW200 C_RDNW3 48 6 (* -- READ N WORDS FUNCTION -- *) 7 LD %MSG1.D 8 [ %MW400 := 16#0106 ] 9 [ %MW401 := 16#0300 ] 10 [ %MW402 := 1 ]

Modbus Master Communication

Embed Size (px)

DESCRIPTION

modbus

Citation preview

Page 1: Modbus Master Communication

On twido PLC you can use two methods for modbus master communication. 

First method is that you use so called com-macros (on example which you writed, this is also easier). If you use comm macros, you don't need to take care of modbus query syntaces, because comm macro will do it automatically on plc program. 

Second method is that you write every command to plc program via operate blocks. If you use this method, you need take care of bunch of parameters, modbus query function, how many bytes will be transferred an so on...

Com macro is lot of easier to use than second method. Com macros can configured on plc program if you doubleclick com macro 

ex. 

C_RDNW_ADDR1 3 := %MW200 C_RDNW3 48

means use of com macro number 3. Read N words starting of address %MW200 (from slave which is configured on comm macro)

Second line calls com macro3 and 48 number tells to com macro read 48 words from slave. 

If you want see real code for comm macro, select first list editor and after that from tools ->Display real code equivalent fo com macros..

ex. code for C_RDNW_ADDR1 3 := %MW200 C_RDNW3 48

6 (* -- READ N WORDS FUNCTION -- *)7 LD %MSG1.D8 [ %MW400 := 16#0106 ]9 [ %MW401 := 16#0300 ]10 [ %MW402 := 1 ]11 [ %MW402 := SHL( %MW402, 8 ) ]12 [ %MW402 := %MW402 + 3 ]13 [ %MW403 := %MW200]14 [ %MW404 := 55 - 7 ]15 [ EXCH1 %MW400:55 ]

Page 2: Modbus Master Communication

line8 = Exchange command number and length send 6 words (modbus query lenght for reading multiple words)line9 = Reception offset Line10 = Slave number (slave = 1)Line11..12 = Shift left and adding of 3 => %MW402 =16#0103 slave number and modbus function 3 (read multiple words)Line13 = Starting address (Address of first word to be read on slave plc)Line14 = Transmission lenght Line15 = Exch1 inscruction (Use port1 to communication, %MW400..%MW454 is used for this command. (Variable %MW407 has value of first readed word (slave's word %MW200 value, %MW454 has value of slave plc memory address %MW248 variables %mw400..%MW406 is used for modbus query)

Same for write multiple words:

C_WRNW_ADDR1_3 := %MW100C_WRNW 3 48

= Write 48 variables to slave which is configured on com macro number3. First memory address were to write is %MW100 on slave plc.

Real code for this on plc is : 

20 (* -- WRITE N WORDS FUNCTION -- *)21 LD %MSG1.D22 [ %MW604 := 57 - 9 ]23 [ %MW605 := %MW604 * 2 ]24 [ %MW600 := 1 ]25 [ %MW600 := SHL( %MW600, 8 ) ]26 [ %MW600 := %MW600 + %MW605 ]27 [ %MW600 := %MW600 + 8 ]28 [ %MW601 := 16#0007 ]29 [ %MW602 := 1 ]30 [ %MW602 := SHL( %MW602, 8 ) ]31 [ %MW602 := %MW602 + 16 ]32 [ %MW603 := %MW10033 [ EXCH1 %MW600:57 ]

Line 22 = Lenght in wordsLine 23 =Lenght on bytes (allways words*2)line 24...27 = Send command and calculation of total bytes for send = 48 mw*2 +8 bytes for query =>%MW600 =16#0100 + 104 =16#0168

Line28 =transmit offsetLine29..31 = slave 1 and modbus function 16 write multiple words => %MW602=16#0110 (dec 16 = hex 10)

Page 3: Modbus Master Communication

line33 = %MW100= Address of first word to write on slave plcline34 echance 1 command = send via port1...

master plc uses now %MW600..%MW605 for modbus query, %MW606... is used for writing values to slave plc.

so this is pretty easy