1、台达PLC通讯协议台达PLC通讯协议 V1.12通讯接口 RS-232C RS-4852.通讯协议 ASCII 模式, 9600 (传输速率) , 偶同位 , 1 个起始位 , 1 个停止位 9600,7,e,13.通讯资料格式STX 起始字符 :( 3AH)ADR 1 通讯地址:ADR 0 8-bit 地址包含了 2 个 ASCII 码CMD 1 命令码:CMD 0 8-bit命令包含了 2个ASCII码DATA(0) 资料内容:DATA( 1) n 个 8-bit 资料包含了 2n 个 ASCII 码 n =74 个 ASCII 码DATA( n- 1 )LRC CHK 1侦误值:LRC
2、CHK 0 8-bit 侦误值包含了 2 个 ASCII 码END 1 结束字符:END 0 END 1 = CR(0DH),END 0 = LF( 0AH)ADR (通讯地址)PLC 通讯地址出厂设定值为 0x01 ,因此( ADR 1, ADR 0)=0,1 0=30H, 1 = 31HLRC CHK(侦误值)CMD (命令指令)及DATA (数据字符)LRC CHK(侦误值)侦错方式采用 LRC( Longitudinal Redundancy Check )侦误值。 LRC 侦误值乃是将 ADR1 至最 后一个资料内容加总,将该值取 2补码(2 s CompIement )得到之结果即
3、为 LRC侦误值。附录 -3 例:STX :0103ADR 1ADR 0CMD 1CMD 0起始资料地址 0401资料数 0001LRC CHK 1 FLRC CHK 0 6END 1 CREND 0 LF01H+03H+04H+01H+00+01H = 0AH0AH的2补码为F6H注12补码的求法:(1补码再加1)0A( H) = 0000 1010( B)先取 1 补码(将 b0b7 反相)得 1111 0101( B),再加 1 为 1111 0110(B) = F6 (H)即为 0A( H)的 2 补码。注2ADR1,0)至因此在收到一串完整的通讯命令,要检查这串通讯命令是否有误,只要
4、将(LRC1,0)加总等于0,则通讯无误,否则表示命令中资料有些是错误的。通讯异常PLC的响应:附录-4PLC收到完整的通讯命令时,会判断命令是否有效,造成无效的原因有:原因 EXCEPTION CODELRC CHK ERROR 07DEIVCE ADDRESS INVALID 02要求的资料超过范围 03COMMAND CODE INVALID 01通讯命令格式INVALID 07例:使用命令码 01读取X000X017的状态Field Name Exa mp le (Hex)Headi ng 3ASlave Address 01Fun ction 01Starti ng Address
5、Hi 04Starti ng Address Lo 00Number of Poin ts Hi 00Number of P oi nts Lo 10Error Check ( LRC ) EA 附录-5PLC响应:Field Name Exa mp le (Hex)Headi ng 3ASlave Address 01Fu nction 81Exce pti on Code 02Error Check ( LRC ) 7C因为 Address 0400 对 Function 01 是不合法的,所以响应 Exception code = 0x02,且 Function 01被设为81 ( b7
6、被设为1),亦即由响应的 Function code的MSB被设为1表示PLC响应ERRORMESSAGE并且由Exception code可得知是何种错误。可用之命令码叙述如下:(每个device的address,请参考最后一页)Code Name Descri pti on01 Read Coil Status S, YM, T, C02 Read Input Status S, X, YM,T, C03 Read Holdi ng Registers T, C, D05 Force Si ngle Coil S, YM, T, C06 P reset Sin gle Register T
7、, C, D15Force Mult ip le Coils S, Y, M, T, C16P reset Mult ip le Register T, C, D17Report Slave ID None附录-6资料字符之格式依命令码而定,依可用之命令码的资料内容分别叙述如下:Function Code: 01, Read Coil StatusField Name Exa mp le (Hex)Headi ng 3ASlave Address 01Fu nction 01Starti ng Address Hi 06Starti ng Address Lo 14Number of P oi
8、 nts Hi 00Number of P oi nts Lo 25Error Check ( LRC ) BFNumber of Poi nts(max) = 255 = 0x00FF例:由从动装置(slave device) 01读取线圈 T20T56PS PLC “: 01 01 06 14 00 25 BF CR LFPLSPC “: 01 01 05 CD 6B B2 0E 1B D6 CR LFField Name ContentsSlave Address 01Fu nction 01Field Name Exa mp le (Hex)Headi ng 3ASlave Addre
9、ss 01Fun ction 02Starti ng Address Hi 05Starti ng Address Lo 14Number of Poin ts Hi 00Number of P oi nts Lo 25Error Check ( LRC ) BF例:由从动装置01读取接点 Y024Y070PS PLC “: 01 02 05 14 00 25 BF CR LFPLSPC “: 01 01 05 CD 6B B2 0E 1B E5 CR LFField Name ContentsSlave Address 01Fun ction 02Error Check ( LRC) E5
10、附录-8Function Code: 03, Read Holding Register Holding Register: T, C, DField Name Exa mp le (Hex)Headi ng 3ASlave Address 01Fun ction 03Starti ng Address Hi 06Starti ng Address Lo 14Number of Poin ts Hi 00Number of P oi nts Lo 08Error Check ( LRC ) DANumber of Poin ts(max)=18 (for 16 bit register)=9
11、(for 32 bit register )例:由从动装置 01读取线圈T20T27PS PLC “: 01 03 06 14 00 08 DA CR LFPLS PC “: 01 03 10 00 01 00 02 00 03 00 04 00 05 00 06 00 07 00 08 B8 CR LF 3A 30 31 30 33 31 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 45 43 0D 0A 3A 30 B1 30 33 B1
12、 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 C5 C3 8D 0A3A 8A 30 A6 83 30 82 30 82 30 82 30 82 30 82 30 82 30 82 30 82 30 82 30 82 30 2A C3 63 E1Field Name ContentsSlave Address 01Fun ction 03Bytes Cou nt 10Data Hi (T20) 00Data Lo(T20)01Data Hi(
13、T21)00Data Lo(T21)02Data Hi(T22)00附录-9Data Lo(T22)03Data Hi(T23)00Data Lo(T23)04Data Hi(T24)00Data Lo(T24)05Data Hi(T25)00Data Lo(T25)06Data Hi(T26)00Data Lo(T26)07Data Hi(T27)00Data Lo(T27)08Error Check (LRCB8Function Code: 05, Force Single CoilField Name Exam pie (Hex)Headi ng 3ASlave Address 01Fu
14、nction 05Coil Address Hi 05Coil Address Lo 00Force Data Hi FFForce Data Lo 00Error Check ( LRC ) F6MMNN = 0xFF00 .CoiONMMNN = 0x0000 .Coil OFF 例:强制设定线圈 Y000 ONPS PLC “: 01 05 05 00 FF 00 F6 CR L”PLSPC “: 01 05 05 00 FF 00 F6 CR L” 附录-10Field Name Exam pie (Hex)Headi ng 3ASlave Address 01Function 05Coil Address Hi 05Coil Address Lo 00Force Data Hi FFForce Data Lo 00Error Check ( LRC ) F6Function Code: 06, Preset Single RegisterField Name Exa mp le (Hex)Headi ng 3ASlave Address 01Fun ction 06Register Address Hi 06Register Address Lo 00Preset Data Hi 12P reset Data Lo 3
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1