|
@@ -908,18 +908,21 @@ namespace NB_IOT_TCP_HP_SOCKET
|
|
|
|
|
|
string agreement = ""; // 设备协议
|
|
|
string agreementParam = ""; // 设备协议参数
|
|
|
+ string agreementAddress = ""; // 设备地址
|
|
|
Dictionary<string, string> trandevice = new Dictionary<string, string>(); // 通讯设备信息
|
|
|
for (int i = 0; i < dt.Rows.Count; i++)
|
|
|
{
|
|
|
|
|
|
string agreementTmp = dt.Rows[i]["设备协议"].ToString();
|
|
|
string agreementParamTmp = dt.Rows[i]["设备协议参数"].ToString();
|
|
|
+ string agreementAddressTmp = dt.Rows[i]["设备地址"].ToString();
|
|
|
trandevice[dt.Rows[i]["transId"].ToString()] = dt.Rows[i]["名称"].ToString();
|
|
|
// 如果一个通讯设备下挂载多个设备,判断多个设备的传输协议是否一致,如果不一致则配置错误,无法进行数据转换
|
|
|
if ("".Equals(agreement) && "".Equals(agreementParam))
|
|
|
{
|
|
|
agreement = agreementTmp;
|
|
|
agreementParam = agreementParamTmp;
|
|
|
+ agreementAddress = agreementAddressTmp;
|
|
|
}
|
|
|
else if (!string.IsNullOrEmpty(agreement) && !string.IsNullOrEmpty(agreementParam) && (!agreement.Equals(agreementTmp) || !agreementParam.Equals(agreementParamTmp)))
|
|
|
{
|
|
@@ -1110,7 +1113,17 @@ namespace NB_IOT_TCP_HP_SOCKET
|
|
|
sendGetParamComm.Remove(maxKey);
|
|
|
}
|
|
|
}
|
|
|
- else
|
|
|
+ // 设备主动上报抄表数据
|
|
|
+ else if (code == Modbus.FunctionCode.F3A)
|
|
|
+ {
|
|
|
+ //msg = new ResMsg();
|
|
|
+ //msg.Result = false;
|
|
|
+ //msg.Message = "不能识别的数据";
|
|
|
+ modbus.Id = Convert.ToUInt16(agreementAddress);
|
|
|
+ modbus.FunCode = Modbus.FunctionCode.F3A;
|
|
|
+ msg = Modbus.UnPack(psp.Data, modbus);
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
modbus = sendComm[keyValuePair.Key][code.ToString()];
|
|
|
msg = Modbus.UnPack(psp.Data, modbus);
|
|
@@ -1363,6 +1376,8 @@ namespace NB_IOT_TCP_HP_SOCKET
|
|
|
// 上报抄表数据
|
|
|
else if ("1".Equals(insourcingData.DataType))
|
|
|
{
|
|
|
+ List<HistoryRecord> list = new List<HistoryRecord>();
|
|
|
+
|
|
|
Modbus modbus = insourcingData.Modbus;
|
|
|
// 获取配置的上报抄表数据的数据信息CONF/DataCellConfig.xml中CD_PSController节点,根据传输设备中的设备协议参数关联取那些字段
|
|
|
ModBusDeviceType modBusDeviceType = new ModBusDeviceType(insourcingData.AgreementParam);
|
|
@@ -1375,18 +1390,49 @@ namespace NB_IOT_TCP_HP_SOCKET
|
|
|
if (modbus.FunCode == Modbus.FunctionCode.F04)
|
|
|
{
|
|
|
ProtocolAnalysisTools.OrganizeAnalogData(modbus.UpDataArea, _analogData, Convert.ToInt32(modBusDeviceType.AnalogStartAddress));
|
|
|
+
|
|
|
+ // 将数据进行封装,一条数据可能对于多个设备的数据,通过[设备信息表]中设备的[用户站参数]与CONF\UserStation_Config.xml进行匹配拆分
|
|
|
+ List<HistoryRecord> item = this.UpdateHistoryData(insourcingData.Recordtime, null, dt, _analogData, _switchData);
|
|
|
+
|
|
|
+ if (item != null && item.Count > 0)
|
|
|
+ {
|
|
|
+ list.AddRange(item);
|
|
|
+ }
|
|
|
}
|
|
|
else if (modbus.FunCode == Modbus.FunctionCode.F02)
|
|
|
{
|
|
|
ProtocolAnalysisTools.OrganizeSwitchData(modbus.UpDataArea, _switchData, Convert.ToInt32(modBusDeviceType.SwitchStartAddress));
|
|
|
+
|
|
|
+ // 将数据进行封装,一条数据可能对于多个设备的数据,通过[设备信息表]中设备的[用户站参数]与CONF\UserStation_Config.xml进行匹配拆分
|
|
|
+ List<HistoryRecord> item = this.UpdateHistoryData(insourcingData.Recordtime, null, dt, _analogData, _switchData);
|
|
|
+ if (item != null && item.Count > 0)
|
|
|
+ {
|
|
|
+ list.AddRange(item);
|
|
|
+ }
|
|
|
}
|
|
|
- #endregion
|
|
|
+ else if (modbus.FunCode == Modbus.FunctionCode.F3A)
|
|
|
+ {
|
|
|
+ TimeSpan ts = modbus.HistoryRecordEnd - modbus.HistoryRecordStart; //计算时间差
|
|
|
+ int invertSecond = modbus.HistoryRecordNum == 1 ? 0 : (Int32) ts.TotalSeconds / (modbus.HistoryRecordNum - 1);
|
|
|
+ for (int i = 0; i < modbus.HistoryRecordNum; i++)
|
|
|
+ {
|
|
|
+ byte[] ReturnData = new byte[modbus.BytNumPerRecord - 6];
|
|
|
+ DateTime recordTime = modbus.HistoryRecordStart.AddSeconds(invertSecond * i);
|
|
|
+ Array.ConstrainedCopy(modbus.UpDataArea, i * modbus.BytNumPerRecord + 6, ReturnData, 0, modbus.BytNumPerRecord - 6);
|
|
|
+ ProtocolAnalysisTools.OrganizeAnalogData(ReturnData, _analogData, Convert.ToInt32(modBusDeviceType.AnalogStartAddress));
|
|
|
+ // 将数据进行封装,一条数据可能对于多个设备的数据,通过[设备信息表]中设备的[用户站参数]与CONF\UserStation_Config.xml进行匹配拆分
|
|
|
+ List<HistoryRecord> item = this.UpdateHistoryData(recordTime, null, dt, _analogData, _switchData);
|
|
|
+ if (item != null && item.Count > 0)
|
|
|
+ {
|
|
|
+ list.AddRange(item);
|
|
|
+ }
|
|
|
|
|
|
- // 将数据进行封装,一条数据可能对于多个设备的数据,通过[设备信息表]中设备的[用户站参数]与CONF\UserStation_Config.xml进行匹配拆分
|
|
|
- List<HistoryRecord> item = this.UpdateHistoryData(insourcingData.Recordtime, null, dt, _analogData, _switchData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
|
|
|
// 保存抄表数据
|
|
|
- ProtocolAnalysisTools.SaveRecord(item);
|
|
|
+ ProtocolAnalysisTools.SaveRecord(list);
|
|
|
}
|
|
|
}
|
|
|
|