public override bool InsertData(DataEntity data, out string errMsg) { errMsg = string.Empty; try { this.m_sqlHelper.Connected = true; } catch (Exception) { } if (!this.m_sqlHelper.Connected) { errMsg = "未连接到数据库"; return(false); } ModbusTcpDataEntity mbTcpData = (ModbusTcpDataEntity)data; string insertSql = string.Format(@"INSERT INTO {0}(RID, STATION,DEVICE_ADDR,SENSOR_TYPE,SENSOR_NAME,ORI_VALUE, VALUE, UNIT, DTIME) VALUES('{1}','{2}','{3}','{4}','{5}',{6},{7},'{8}','{9}')", "appuser.dbo.MODBUSTCP_DATA_HISTORY", mbTcpData.RID, mbTcpData.Station, mbTcpData.Device_Addr, mbTcpData.Sensor_Type, mbTcpData.Sensor_Name, mbTcpData.Ori_Value, mbTcpData.Trans_Value, mbTcpData.Trans_Unit, mbTcpData.DataAcqTime.ToString()); return(false); }
private List <ModbusTcpDataEntity> GetModbusTcpData(ModbusTcpResult mbTcpResult) { List <ModbusTcpDataEntity> mbTcpDataList = new List <ModbusTcpDataEntity>(); //查找对应的operation var ops = from n in m_config.ModbusOperations where n.Identifier == mbTcpResult.Identifier select n; ModbusTcpOperation mbTcpOp = null; foreach (ModbusTcpOperation op in ops) { mbTcpOp = op; } if (mbTcpOp != null) { for (int i = 0; i < mbTcpOp.RegCount; i++) { ushort currentAddr = (ushort)(mbTcpOp.StartAddr + i); ModbusTcpConfigItem mbTcpCfgItem = GetModbusTcpConfigItemByRegAddr(currentAddr); if (mbTcpCfgItem != null) { ModbusTcpDataEntity dataEntity = new ModbusTcpDataEntity(); dataEntity.RID = Guid.NewGuid().ToString(); dataEntity.Device_Addr = mbTcpCfgItem.DeviceAddr.ToString(); dataEntity.Station = m_config.ServerName; dataEntity.Sensor_Type = "-1"; dataEntity.Sensor_Name = mbTcpCfgItem.Name; dataEntity.Ori_Value = mbTcpResult.ResultData[i]; dataEntity.Trans_Value = dataEntity.Ori_Value * mbTcpCfgItem.Multiplier; dataEntity.Trans_Unit = mbTcpCfgItem.Unit; dataEntity.DataAcqTime = mbTcpResult.DataAcqTime; mbTcpDataList.Add(dataEntity); } } } return(mbTcpDataList); }