Read data from external devices via MC protocol
The PLC has the transmission right in the master communication. The communication is performed by sending commands to devices which support MC protocol and receiving responses. By specifying a memory address and executing a read instruction in a user program, the PLC generates a message according to the protocol automatically.
Input
Ethernet port e.g. SYS_ETHERNET_USER_CONNECTION_1
Memory area on the slave from where to request the data.
Unit |
Memory area type |
System variable |
||
---|---|---|---|---|
Bit |
Input |
X |
Hexadecimal SYS_MC_PROTOCOL_MEMORY_AREA_INPUT_X |
|
Output |
Y |
Hexadecimal SYS_MC_PROTOCOL_MEMORY_AREA_OUTPUT_Y |
||
Link relay |
B |
Hexadecimal SYS_MC_PROTOCOL_MEMORY_AREA_LINK_RELAY_B |
||
Internal relay |
M |
Decimal SYS_MC_PROTOCOL_MEMORY_AREA_INTERNAL_RELAY_M |
||
Latch relay |
L |
Decimal SYS_MC_PROTOCOL_MEMORY_AREA_LATCH_RELAY_L |
||
Word |
Data register |
D |
Decimal SYS_MC_PROTOCOL_MEMORY_AREA_DATA_REGISTER_D |
|
File register |
R |
Decimal SYS_MC_PROTOCOL_MEMORY_AREA_FILE_REGISTER_R |
||
ZR |
Hexadecimal SYS_MC_PROTOCOL_MEMORY_AREA_FILE_REGISTER_ZR |
|||
Link register |
W |
Hexadecimal SYS_MC_PROTOCOL_MEMORY_AREA_LINK_REGISTER_W |
Offset of the memory area on the slave from where to request the data.
Range: 16#0–16#F7FFFF (0–16252927)
The transfer method varies according to the data type of Destination.
Memory area specified in Destination |
Transfer method |
No. of transmitted data |
Remarks |
---|---|---|---|
16-bit memory area WX, WY, WR, WL, DT, LD |
Word transmission |
1–960 words |
|
1-bit memory area X,Y,R,L,DT,n,LD,n |
Bit transmission |
1–7168 bits |
When the number of transmitted data is odd, 4-bit dummy code 16#0 is added. |
Output
Word area or register on the master unit to which the requested data is written.
For FP7 only:
0: Normal completion
1: Communication port is used for master communication
2: Communication port is used for slave communication
3: No. of master communication instructions that can be used at the same time is exceeded
4: Transmission timeout
5: Timeout while waiting for a response
6: Error in received data
This error occurs when an abnormal telegram is received, e.g. when there is a format error in the header. In this case, the received data is discarded.
7: Insufficient area reserved in I/O map
This error occurs when the number of Ethernet connections exceeds 16 (Advanced Ethernet communication). Check whether the word area reserved for communication control flags is big enough for the number of Ethernet connections.
8: Send buffer currently in use
This error may occur for FP7 PLCs with firmware version 4.57 or later.
In case of communication errors, other error codes specific to the MC protocol may be set. For more details please refer to the documentation of the PLC used.
For other PLCs: set to 0
While sending: Master communication sending flag is TRUE
Sending done: Master communication sending flag is FALSE
Normal completion: FALSE
Abnormal completion: TRUE
if the area specified using the index modifier exceeds the limit.
if the Ethernet port is incorrect or the Ethernet connection is closed.
if the number of sent data specified by Words_Bits is incorrect.
if the area specified using the index modifier exceeds the limit.
if the Ethernet port is incorrect or the Ethernet connection is closed.
if the number of sent data specified by Words_Bits is incorrect.
All input and output variables used for programming this function have been declared in the POU header. The same POU header is used for all programming languages.
VAR
diMemoryOffset: DINT:=0;
awValues: ARRAY [0..2] OF WORD:=[3(0)];
iResult: INT:=0;
bEnable: BOOL:=FALSE;
abValues: ARRAY [0..2] OF BOOL:=[3(FALSE)];
iPort: INT:=0;
END_VAR
BODY
WORKSPACE
NETWORK_LIST_TYPE := NWTYPELD ;
ACTIVE_NETWORK := 0 ;
END_WORKSPACE
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 6 ;
NETWORK_BODY
B(B_COMMENT,,Bit transfer,2,0,10,1,);
B(B_COMMENT,,Memory Areas: SYS_MC_PROTOCOL_MEMORY_AREA_INPUT_X ^SYS_MC_PROTOCOL_MEMORY_AREA_OUTPUT_Y ^SYS_MC_PROTOCOL_MEMORY_AREA_LINK_RELAY_B ^SYS_MC_PROTOCOL_MEMORY_AREA_INTERNAL_RELAY_M ^SYS_MC_PROTOCOL_MEMORY_AREA_LATCH_RELAY_L,13,0,39,6,);
L(1,0,1,6);
END_NETWORK_BODY
END_NET_WORK
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 7 ;
NETWORK_BODY
B(B_VARIN,,iPort,26,2,28,4,);
B(B_VAROUT,,abValues,41,2,43,4,);
B(B_VARIN,,SYS_MC_PROTOCOL_MEMORY_AREA_INPUT_X,26,3,28,5,);
B(B_VARIN,,diMemoryOffset,26,4,28,6,);
B(B_VAROUT,,iResult,41,3,43,5,);
B(B_CONTACT,,bEnable,5,1,7,3,);
B(B_F,FP_MC_PROTOCOL_READ!,,28,0,41,7,,?DEN?DPort?HSourceMemoryArea?DSourceMemoryOffset?DWords_Bits?AENO?CDestination?CResult);
B(B_F,Size_Of_Var!,,21,5,28,7,,?D?C);
B(B_VARIN,,abValues,19,5,21,7,);
L(7,2,28,2);
L(1,2,5,2);
L(1,0,1,7);
END_NETWORK_BODY
END_NET_WORK
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 5 ;
NETWORK_BODY
B(B_COMMENT,,Memory Areas: ^SYS_MC_PROTOCOL_MEMORY_AREA_DATA_REGISTER_D ^SYS_MC_PROTOCOL_MEMORY_AREA_FILE_REGISTER_R ^SYS_MC_PROTOCOL_MEMORY_AREA_FILE_REGISTER_ZR ^SYS_MC_PROTOCOL_MEMORY_AREA_LINK_REGISTER_W,13,0,39,5,);
B(B_COMMENT,,Word Transfer,2,0,10,1,);
L(1,0,1,5);
END_NETWORK_BODY
END_NET_WORK
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 7 ;
NETWORK_BODY
B(B_VARIN,,iPort,26,2,28,4,);
B(B_VAROUT,,awValues,41,2,43,4,);
B(B_VARIN,,SYS_MC_PROTOCOL_MEMORY_AREA_DATA_REGISTER_D,26,3,28,5,);
B(B_VARIN,,diMemoryOffset,26,4,28,6,);
B(B_VAROUT,,iResult,41,3,43,5,);
B(B_CONTACT,,bEnable,5,1,7,3,);
B(B_F,FP_MC_PROTOCOL_READ!,,28,0,41,7,,?DEN?DPort?HSourceMemoryArea?DSourceMemoryOffset?DWords_Bits?AENO?CDestination?CResult);
B(B_F,Size_Of_Var!,,21,5,28,7,,?D?C);
B(B_VARIN,,awValues,19,5,21,7,);
L(1,2,5,2);
L(7,2,28,2);
L(1,0,1,7);
END_NETWORK_BODY
END_NET_WORK
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 5 ;
NETWORK_BODY
B(B_COMMENT,,only valid for ethernet ports! ^--> Valid Ports: SYS_ETHERNET_USER_CONNECTION_1 - SYS_ETHERNET_USER_CONNECTION_216,3,1,52,4,);
L(1,0,1,5);
END_NETWORK_BODY
END_NET_WORK
END_BODY
(*Bit transfer*)
If (bEnable) then
FP_MC_PROTOCOL_READ(Port := iPort,
SourceMemoryArea := SYS_MC_PROTOCOL_MEMORY_AREA_INPUT_X,
SourceMemoryOffset := diMemoryOffset,
Words_Bits := Size_Of_Var(abValues),
Destination => abValues, Result => iResult);
End_if;
(*Word transfer*)
If (bEnable) then
FP_MC_PROTOCOL_READ(Port := iPort,
SourceMemoryArea := SYS_MC_PROTOCOL_MEMORY_AREA_DATA_REGISTER_D,
SourceMemoryOffset := diMemoryOffset,
Words_Bits := Size_Of_Var(awValues),
Destination => awValues, Result => iResult);
End_if;