/// <summary> /// 设置多个输入变量对象的状态 /// </summary> /// <param name="inVarObjList"></param> /// <param name="isOnOff"></param> /// <returns></returns> protected override bool DoSetPluralInvarStatus(InVarObjList inVarObjList, bool[] isOnOff) { bool rt = false; if (inVarObjList != null) { int cnt = inVarObjList.Count; int tnc = isOnOff.Length; try { if (cnt == tnc) { //最多8个触点 if (cnt < 9) { // 站号--2字节 string stationNum = string.Empty; // 变量类型--1字节 string varType = string.Empty; //控制变量地址--4字节 string varAddress = string.Empty; //控制变量状态 string state = string.Empty; string sectionArr = string.Empty; for (int i = 0; i < cnt; i++) { if (i == 0) { stationNum = inVarObjList[i].StationNumber; } varType = inVarObjList[i].VarType.Trim().ToUpper(); //限定以下触点类型有效 if (!(varType == "X" || varType == "Y" || varType == "R" || varType == "T" || varType == "C" || varType == "L")) { return(rt); } varAddress = inVarObjList[i].Address.ToString().PadRight(4, '0'); state = isOnOff[i] ? "1" : "0"; sectionArr += (varType + varAddress + state); } string cmd = string.Format("%{0}#WCP{1}{2}", stationNum, cnt.ToString(), sectionArr); string cmdChk = ProCommon.Communal.ToolFunctions.AddCheckCode(cmd); //向串口写入指令数据 stationNum = WriteData(cmdChk, 50); //串口无返回结果,则获取输入变量对象状态失败,返回 if (string.IsNullOrEmpty(stationNum)) { return(rt); } //根据串口返回结果字符串--索引位置为3的字符:"$"--响应正常,"!"--响应异常 switch (stationNum.Substring(3, 1)) { case "$": rt = true; for (int i = 0; i < cnt; i++) { inVarObjList[i].NewValue = isOnOff[i]; } break; default: break; } } } } catch (System.Exception ex) { } } return(rt); }
public bool GetPluralInvarStatus(InVarObjList inVarObjList, out bool[] isOnOff) { return(DoGetPluralInvarStatus(inVarObjList, out isOnOff)); }
public bool SetPluralInvarStatus(InVarObjList inVarObjList, bool[] isOnOff) { return(DoSetPluralInvarStatus(inVarObjList, isOnOff)); }
protected abstract bool DoSetPluralInvarStatus(InVarObjList inVarObjList, bool[] isOnOff);