例如你可以利用OMRON的HOSTLINK 协议。例程如下:
'COMMUNICATION SETTING
'Hostlink master protocol in PORT 1 (RS232)
SETCOM(9600,7,2,2,1,5)
'WA(100)
'Variables to Read and write
VR(0)=1
VR(1)=200
VR(2)=300
loop:
'Write to the PLC VR(0), VR(1) and VR(2) to
'DM1000, DM1001 and DM1002
HLM_WRITE(1,0,PLC_DM,1000,3,MC_VR,0)
WA (1000)
'Write in terminal screen (channel 5) the written information
PRINT #5,"Write Status (0=OK) : ";HLM_STATUS PORT(1)
PRINT #5,"WR DM1000 from VR(0)=";VR(0)
'PRINT #5,"WR DM1001 from VR(1)=";VR(1)
'PRINT #5,"WR DM1002 from VR(2)=";VR(2)
'Read from the PLC the same DM that we wrote, plus DM1003
'and put the information to VR(5) to VR(8)
HLM_READ(1,0,PLC_DM,1000,1,MC_VR,5)
WA (1000)
'Print the status of the communication and the read registers
PRINT #5,"Read Status (0=OK) : ";HLM_STATUS PORT(1)
PRINT #5,"DM1000 to VR(5)=";VR(5)
'PRINT #5,"DM1001 to VR(6)=";VR(6)
'PRINT #5,"DM1002 to VR(7)=";VR(7)
'PRINT #5,"DM1003 to VR(8)=";VR(8)
'Change VR(2) to check that the system is "alive"
VR(0)=VR(0)+1
GOTO loop
这些变量 VR,都可以定义成SPEED或ACCEL等参数写入控制器,或从控制器读出。