Add "nodata" process code.

This commit is contained in:
罗圣
2016-08-23 12:27:47 +08:00
parent 8db2dce585
commit 5d3fe794f9

View File

@@ -163,14 +163,26 @@ namespace Modbus.Net
Math.Ceiling(communicateAddress.GetCount* Math.Ceiling(communicateAddress.GetCount*
BigEndianValueHelper.Instance.ByteLength[ BigEndianValueHelper.Instance.ByteLength[
communicateAddress.DataType.FullName])); communicateAddress.DataType.FullName]));
var datas = datasReturn.ReturnValue;
//如果没有数据,终止 byte[] datas;
if (datas == null || datas.Length == 0 || datas.Length !=
(int) //如果设备本身能获取到数据但是没有数据
Math.Ceiling(communicateAddress.GetCount * if (datasReturn == null)
BigEndianValueHelper.Instance.ByteLength[ {
communicateAddress.DataType.FullName])) return null; datas = null;
}
else
{
datas = datasReturn.ReturnValue;
//如果没有数据,终止
if (datas == null || datas.Length == 0 || datas.Length !=
(int)
Math.Ceiling(communicateAddress.GetCount *
BigEndianValueHelper.Instance.ByteLength[
communicateAddress.DataType.FullName])) return null;
}
int pos = 0; int pos = 0;
//解码数据 //解码数据
while (pos < communicateAddress.GetCount) while (pos < communicateAddress.GetCount)
@@ -200,18 +212,33 @@ namespace Modbus.Net
break; break;
} }
} }
//将获取的数据和对应的通讯标识对应 if (datas == null)
ans.Add(key, {
new ReturnUnit ans.Add(key, new ReturnUnit
{ {
PlcValue = PlcValue = null,
Double.Parse(
datasReturn.IsLittleEndian ? ValueHelper.Instance.GetValue(datas, ref pos, address.DataType)
.ToString() : BigEndianValueHelper.Instance.GetValue(datas, ref pos, address.DataType)
.ToString()) *address.Zoom,
UnitExtend = address.UnitExtend UnitExtend = address.UnitExtend
}); });
pos += (int)ValueHelper.Instance.ByteLength[address.DataType.ToString()];
}
else
{
//将获取的数据和对应的通讯标识对应
ans.Add(key,
new ReturnUnit
{
PlcValue =
Double.Parse(
datasReturn.IsLittleEndian
? ValueHelper.Instance.GetValue(datas, ref pos, address.DataType)
.ToString()
: BigEndianValueHelper.Instance.GetValue(datas, ref pos,
address.DataType)
.ToString())*address.Zoom,
UnitExtend = address.UnitExtend
});
}
} }
else else
{ {
@@ -398,8 +425,8 @@ namespace Modbus.Net
public static Dictionary<string, double> MapGetValuesToSetValues(Dictionary<string, ReturnUnit> getValues) public static Dictionary<string, double> MapGetValuesToSetValues(Dictionary<string, ReturnUnit> getValues)
{ {
if (getValues == null) return null; if (getValues == null) return null;
return (from getValue in getValues return (from getValue in getValues where getValue.Value.PlcValue != null
select new KeyValuePair<string, double>(getValue.Key, getValue.Value.PlcValue)).ToDictionary(p=>p.Key,p=>p.Value); select new KeyValuePair<string, double>(getValue.Key, getValue.Value.PlcValue.Value)).ToDictionary(p=>p.Key,p=>p.Value);
} }
} }
@@ -455,7 +482,7 @@ namespace Modbus.Net
/// <summary> /// <summary>
/// 返回的数据 /// 返回的数据
/// </summary> /// </summary>
public double PlcValue { get; set; } public double? PlcValue { get; set; }
/// <summary> /// <summary>
/// 数据的扩展 /// 数据的扩展
/// </summary> /// </summary>