void ReadDData() { if (status >= 0) { if (pDLst != null && pDLst.Count > 0) { ushort[] inputs = master.ReadHoldingRegisters((ushort)pDLst[0].Address, (ushort)pDLst.Count); if (inputs != null && inputs.Count() == pDLst.Count) { for (int i = 0; i < pDLst.Count; i++) { pDLst[i].ShowValue = inputs[i].ToString(); } } } } }
bool getDValueFromLst(List <XJPlcInfo> tDplcLst) { //这里dplcinfo 已经默认传进来 两个了 try { /*** * if (tDplcLst[0].AbsAddr == 41674) * { * int i = 0; * } ***/ ushort[] inputs = master.ReadHoldingRegisters((byte)Constant.DefaultUnitId, (ushort)tDplcLst[0].AbsAddr, (ushort)(tDplcLst.Count)); // ushort[] inputs = master.ReadHoldingRegisters((byte)Constant.DefaultUnitId,200,20); if (inputs != null && inputs.Count() == tDplcLst.Count) { ErrorConnCount = 0; for (int i = 0; i < tDplcLst.Count(); i++) { if (IsRePackCmdReadDMDataOut) { return(true); } byte[] a = BitConverter.GetBytes(inputs[i]); tDplcLst[i].ByteValue[0] = a[1]; //低字节 tDplcLst[i].ByteValue[1] = a[0]; //低字节 } for (int i = 0; i < tDplcLst.Count(); i++) { if (IsRePackCmdReadDMDataOut) { return(true); } if (tDplcLst[i].Row >= dataForm.Rows.Count) { continue; } string sValue = tDplcLst[i].PlcValue.ToString(); int iValue = tDplcLst[i].PlcValue; if (!dataForm.Rows[tDplcLst[i].Row]["value"].ToString().Equals(sValue) && !tDplcLst[i].IsInEdit && (tDplcLst[i].BelongToDT != null)) { if (dataForm.Rows[tDplcLst[i].Row]["addr"].ToString().Contains(tDplcLst[i].RelAddr.ToString()) && dataForm.Rows[tDplcLst[i].Row]["addr"].ToString().Contains(tDplcLst[i].StrArea) ) { if (tDplcLst[i].BelongToDT != null) { dataForm.Rows[tDplcLst[i].Row]["value"] = sValue; double ration = 1; if (double.TryParse(dataForm.Rows[tDplcLst[i].Row][Constant.strParam7].ToString(), out ration)) { dataForm.Rows[tDplcLst[i].Row]["value"] = sValue; dataForm.Rows[tDplcLst[i].Row][Constant.strParam6] = (iValue / ration).ToString("0.00"); } } } } } return(true); } return(false); } catch (Exception ex) { return(false); } }