/// <summary> /// 向CIO区写入地址命令 /// </summary> /// <param name="startAddr"></param> /// <param name="bitValue"></param> /// <param name="cmdBytes"></param> /// <param name="restr"></param> /// <returns></returns> public bool WriteCIOAddrCmd(float startAddr, short[] bitValue, ref byte[] cmdBytes, ref string restr) { try { string writeCioStr = ""; string finsLength = Convert.ToString((26 + bitValue.Length), 16).PadLeft(8, '0').ToUpper(); string addrStr = DataConvert.ConvertCIOAddr(startAddr); string addrCountStr = Convert.ToString((short)bitValue.Count(), 16).PadLeft(4, '0'); writeCioStr = FINSHEAD + finsLength + FINSWRCMD + FINSERRORCODE + FINSHEADCODE + this.PLCNode + this.PCNode + SID + WRITEORDERTYPE + CIOADDRAREA + addrStr + addrCountStr; for (int i = 0; i < bitValue.Length; i++) { if (bitValue[i] > 1) { restr = "地址位值错误!"; return(false); } string valueStr = Convert.ToString(bitValue[i], 16).PadLeft(2, '0'); writeCioStr += valueStr; } cmdBytes = DataConvert.StrToToHexByte(writeCioStr); return(true); } catch (Exception ex) { restr = ex.Message; return(false); } }
/// <summary> /// 读取CIO区地址命令 /// </summary> /// <param name="startAddr"></param> /// <param name="readAddrCount"></param> /// <param name="cmdBytes"></param> /// <param name="restr"></param> /// <returns></returns> public bool ReadCIOAddrCmd(float startAddr, short readAddrCount, ref byte[] cmdBytes, ref string restr) { try { string readDmStr = ""; string finsLenth = "0000001A";//读取命令长度固定26 string addrStr = DataConvert.ConvertCIOAddr(startAddr); string addrCountStr = Convert.ToString(readAddrCount, 16).PadLeft(4, '0'); readDmStr = FINSHEAD + finsLenth + FINSWRCMD + FINSERRORCODE + FINSHEADCODE + this.PLCNode + this.PCNode + SID + READORDERTYPE + CIOADDRAREA + addrStr + addrCountStr; cmdBytes = DataConvert.StrToToHexByte(readDmStr); return(true); } catch (Exception ex) { restr = ex.Message; return(false); } }