2016-01-07 update 1 version 1.1 support little endian protocal and change the description of TaskManager ReturnValue and AddressTranslator.
This commit is contained in:
@@ -39,7 +39,7 @@ namespace Modbus.Net.FBox
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public override KeyValuePair<int, int> AddressTranslate(string address, bool isRead)
|
public override AddressDef AddressTranslate(string address, bool isRead)
|
||||||
{
|
{
|
||||||
var tmpAddress = address.Trim().ToUpper();
|
var tmpAddress = address.Trim().ToUpper();
|
||||||
if (tmpAddress.Substring(0, 2) == "DB")
|
if (tmpAddress.Substring(0, 2) == "DB")
|
||||||
@@ -47,15 +47,21 @@ namespace Modbus.Net.FBox
|
|||||||
var addressSplit = tmpAddress.Split(' ');
|
var addressSplit = tmpAddress.Split(' ');
|
||||||
if (addressSplit.Length != 2) throw new FormatException();
|
if (addressSplit.Length != 2) throw new FormatException();
|
||||||
addressSplit[0] = addressSplit[0].Substring(2);
|
addressSplit[0] = addressSplit[0].Substring(2);
|
||||||
return new KeyValuePair<int, int>(int.Parse(addressSplit[1]),
|
return new AddressDef()
|
||||||
int.Parse(addressSplit[0]) + AreaCodeDictionary["DB"]);
|
{
|
||||||
|
Area = int.Parse(addressSplit[0]) + AreaCodeDictionary["DB"],
|
||||||
|
Address = int.Parse(addressSplit[1])
|
||||||
|
};
|
||||||
}
|
}
|
||||||
var tmpAddressArray = (tmpAddress.Split(' '));
|
var tmpAddressArray = (tmpAddress.Split(' '));
|
||||||
string head = tmpAddressArray[0];
|
string head = tmpAddressArray[0];
|
||||||
string tail = tmpAddressArray[1];
|
string tail = tmpAddressArray[1];
|
||||||
return
|
return
|
||||||
new KeyValuePair<int, int>(int.Parse(tail),
|
new AddressDef()
|
||||||
AreaCodeDictionary[head]);
|
{
|
||||||
|
Area = AreaCodeDictionary[head],
|
||||||
|
Address = int.Parse(tail)
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetAreaName(int code)
|
public string GetAreaName(int code)
|
||||||
|
|||||||
@@ -26,8 +26,8 @@ namespace Modbus.Net.FBox
|
|||||||
public ReadRequestFBoxInputStruct(string startAddress, ushort getCount, AddressTranslator addressTranslator)
|
public ReadRequestFBoxInputStruct(string startAddress, ushort getCount, AddressTranslator addressTranslator)
|
||||||
{
|
{
|
||||||
var address = addressTranslator.AddressTranslate(startAddress, true);
|
var address = addressTranslator.AddressTranslate(startAddress, true);
|
||||||
Address = address.Key;
|
Address = address.Address;
|
||||||
Area = address.Value;
|
Area = address.Area;
|
||||||
GetCount = getCount;
|
GetCount = getCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ namespace Modbus.Net.FBox
|
|||||||
ConnectionType = (FBoxType) connectionType;
|
ConnectionType = (FBoxType) connectionType;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async Task<byte[]> GetDatasAsync(byte belongAddress, byte masterAddress, string startAddress, int getByteCount)
|
public override async Task<GetDataReturnDef> GetDatasAsync(byte belongAddress, byte masterAddress, string startAddress, int getByteCount)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -68,7 +68,11 @@ namespace Modbus.Net.FBox
|
|||||||
var readRequestSiemensOutputStruct =
|
var readRequestSiemensOutputStruct =
|
||||||
await
|
await
|
||||||
Wrapper.SendReceiveAsync(Wrapper[typeof(ReadRequestFBoxProtocal)], readRequestFBoxInputStruct) as ReadRequestFBoxOutputStruct;
|
Wrapper.SendReceiveAsync(Wrapper[typeof(ReadRequestFBoxProtocal)], readRequestFBoxInputStruct) as ReadRequestFBoxOutputStruct;
|
||||||
return readRequestSiemensOutputStruct?.GetValue;
|
return new GetDataReturnDef()
|
||||||
|
{
|
||||||
|
ReturnValue = readRequestSiemensOutputStruct?.GetValue,
|
||||||
|
IsLittleEndian = Wrapper[typeof (ReadRequestFBoxProtocal)].IsLittleEndian
|
||||||
|
};
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<package >
|
<package >
|
||||||
<metadata>
|
<metadata>
|
||||||
<id>Modbus.Net.FBox</id>
|
<id>Modbus.Net.FBox</id>
|
||||||
<version>1.0.0</version>
|
<version>1.0.1</version>
|
||||||
<title>Modbus.Net.FBox</title>
|
<title>Modbus.Net.FBox</title>
|
||||||
<authors>Chris L.(Luo Sheng)</authors>
|
<authors>Chris L.(Luo Sheng)</authors>
|
||||||
<owners>Hangzhou Delian Information and Science Technology Co., Ltd.</owners>
|
<owners>Hangzhou Delian Information and Science Technology Co., Ltd.</owners>
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
<copyright>Copyright 2015 Hangzhou Delian Science and Technology Co.,Ltd.</copyright>
|
<copyright>Copyright 2015 Hangzhou Delian Science and Technology Co.,Ltd.</copyright>
|
||||||
<tags>hardware communicate protocal fbox Delian</tags>
|
<tags>hardware communicate protocal fbox Delian</tags>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency id="Modbus.Net" version="1.0.0"></dependency>
|
<dependency id="Modbus.Net" version="1.1.0"></dependency>
|
||||||
<dependency id="Thinktecture.IdentityModel.Client" version="4.0.0"></dependency>
|
<dependency id="Thinktecture.IdentityModel.Client" version="4.0.0"></dependency>
|
||||||
<dependency id="Microsoft.AspNet.SignalR.Client" version="2.2.0"></dependency>
|
<dependency id="Microsoft.AspNet.SignalR.Client" version="2.2.0"></dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|||||||
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
|||||||
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
|
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
|
||||||
// 方法是按如下所示使用“*”: :
|
// 方法是按如下所示使用“*”: :
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("1.0.0.0")]
|
[assembly: AssemblyVersion("1.0.1")]
|
||||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
[assembly: AssemblyFileVersion("1.0.1")]
|
||||||
|
|||||||
@@ -54,17 +54,23 @@ namespace Modbus.Net.Modbus
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public override KeyValuePair<int, int> AddressTranslate(string address, bool isRead)
|
public override AddressDef AddressTranslate(string address, bool isRead)
|
||||||
{
|
{
|
||||||
address = address.ToUpper();
|
address = address.ToUpper();
|
||||||
string[] splitString = address.Split(' ');
|
string[] splitString = address.Split(' ');
|
||||||
string head = splitString[0];
|
string head = splitString[0];
|
||||||
string tail = splitString[1];
|
string tail = splitString[1];
|
||||||
return isRead
|
return isRead
|
||||||
? new KeyValuePair<int, int>(TransDictionary[head] + int.Parse(tail) - 1,
|
? new AddressDef()
|
||||||
ReadFunctionCodeDictionary[head])
|
{
|
||||||
: new KeyValuePair<int, int>(TransDictionary[head] + int.Parse(tail) - 1,
|
Area = ReadFunctionCodeDictionary[head],
|
||||||
WriteFunctionCodeDictionary[head]);
|
Address = TransDictionary[head] + int.Parse(tail) - 1,
|
||||||
|
}
|
||||||
|
: new AddressDef()
|
||||||
|
{
|
||||||
|
Area = WriteFunctionCodeDictionary[head],
|
||||||
|
Address = TransDictionary[head] + int.Parse(tail) - 1,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,17 +98,23 @@ namespace Modbus.Net.Modbus
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public override KeyValuePair<int, int> AddressTranslate(string address, bool isRead)
|
public override AddressDef AddressTranslate(string address, bool isRead)
|
||||||
{
|
{
|
||||||
address = address.ToUpper();
|
address = address.ToUpper();
|
||||||
string[] splitString = address.Split(' ');
|
string[] splitString = address.Split(' ');
|
||||||
string head = splitString[0];
|
string head = splitString[0];
|
||||||
string tail = splitString[1];
|
string tail = splitString[1];
|
||||||
return isRead
|
return isRead
|
||||||
? new KeyValuePair<int, int>(int.Parse(tail) - 1,
|
? new AddressDef()
|
||||||
ReadFunctionCodeDictionary[head])
|
{
|
||||||
: new KeyValuePair<int, int>(int.Parse(tail) - 1,
|
Area = ReadFunctionCodeDictionary[head],
|
||||||
WriteFunctionCodeDictionary[head]);
|
Address = int.Parse(tail) - 1,
|
||||||
|
}
|
||||||
|
: new AddressDef()
|
||||||
|
{
|
||||||
|
Area = WriteFunctionCodeDictionary[head],
|
||||||
|
Address = int.Parse(tail) - 1,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
|
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
|
||||||
<metadata>
|
<metadata>
|
||||||
<id>Modbus.Net.Modbus</id>
|
<id>Modbus.Net.Modbus</id>
|
||||||
<version>1.0.0</version>
|
<version>1.1.0</version>
|
||||||
<title>Modbus.Net.Modbus</title>
|
<title>Modbus.Net.Modbus</title>
|
||||||
<authors>Chris L.(Luo Sheng)</authors>
|
<authors>Chris L.(Luo Sheng)</authors>
|
||||||
<owners>Hangzhou Delian Information and Science Technology Co.,Ltd.</owners>
|
<owners>Hangzhou Delian Information and Science Technology Co.,Ltd.</owners>
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
<copyright>Copyright 2015 Hangzhou Delian Science and Technology Co.,Ltd.</copyright>
|
<copyright>Copyright 2015 Hangzhou Delian Science and Technology Co.,Ltd.</copyright>
|
||||||
<tags>hardware communicate protocal modbus Delian</tags>
|
<tags>hardware communicate protocal modbus Delian</tags>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency id="Modbus.Net" version="1.0.0" />
|
<dependency id="Modbus.Net" version="1.1.0" />
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</metadata>
|
</metadata>
|
||||||
<files>
|
<files>
|
||||||
|
|||||||
@@ -58,9 +58,9 @@ namespace Modbus.Net.Modbus
|
|||||||
public ReadDataModbusInputStruct(byte belongAddress, string startAddress, ushort getCount, AddressTranslator addressTranslator)
|
public ReadDataModbusInputStruct(byte belongAddress, string startAddress, ushort getCount, AddressTranslator addressTranslator)
|
||||||
{
|
{
|
||||||
BelongAddress = belongAddress;
|
BelongAddress = belongAddress;
|
||||||
KeyValuePair<int, int> translateAddress = addressTranslator.AddressTranslate(startAddress, true);
|
var translateAddress = addressTranslator.AddressTranslate(startAddress, true);
|
||||||
FunctionCode = (byte)translateAddress.Value;
|
FunctionCode = (byte)translateAddress.Area;
|
||||||
StartAddress = (ushort)translateAddress.Key;
|
StartAddress = (ushort)translateAddress.Address;
|
||||||
GetCount = getCount;
|
GetCount = getCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,9 +121,9 @@ namespace Modbus.Net.Modbus
|
|||||||
public WriteDataModbusInputStruct(byte belongAddress, string startAddress, object[] writeValue, AddressTranslator addressTranslator)
|
public WriteDataModbusInputStruct(byte belongAddress, string startAddress, object[] writeValue, AddressTranslator addressTranslator)
|
||||||
{
|
{
|
||||||
BelongAddress = belongAddress;
|
BelongAddress = belongAddress;
|
||||||
KeyValuePair<int, int> translateAddress = addressTranslator.AddressTranslate(startAddress, false);
|
var translateAddress = addressTranslator.AddressTranslate(startAddress, false);
|
||||||
FunctionCode = (byte)translateAddress.Value;
|
FunctionCode = (byte)translateAddress.Area;
|
||||||
StartAddress = (ushort)translateAddress.Key;
|
StartAddress = (ushort)translateAddress.Address;
|
||||||
WriteCount = (ushort)writeValue.Length;
|
WriteCount = (ushort)writeValue.Length;
|
||||||
WriteByteCount = 0;
|
WriteByteCount = 0;
|
||||||
WriteValue = writeValue;
|
WriteValue = writeValue;
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ namespace Modbus.Net.Modbus
|
|||||||
ModbusType = (ModbusType) connectionType;
|
ModbusType = (ModbusType) connectionType;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async Task<byte[]> GetDatasAsync(byte belongAddress, byte masterAddress, string startAddress, int getByteCount)
|
public override async Task<GetDataReturnDef> GetDatasAsync(byte belongAddress, byte masterAddress, string startAddress, int getByteCount)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -74,7 +74,11 @@ namespace Modbus.Net.Modbus
|
|||||||
var outputStruct = await
|
var outputStruct = await
|
||||||
Wrapper.SendReceiveAsync(Wrapper[typeof (ReadDataModbusProtocal)], inputStruct) as
|
Wrapper.SendReceiveAsync(Wrapper[typeof (ReadDataModbusProtocal)], inputStruct) as
|
||||||
ReadDataModbusOutputStruct;
|
ReadDataModbusOutputStruct;
|
||||||
return outputStruct?.DataValue;
|
return new GetDataReturnDef()
|
||||||
|
{
|
||||||
|
ReturnValue = outputStruct?.DataValue,
|
||||||
|
IsLittleEndian = Wrapper[typeof(ReadDataModbusProtocal)].IsLittleEndian,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
|||||||
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
|
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
|
||||||
// 方法是按如下所示使用“*”: :
|
// 方法是按如下所示使用“*”: :
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("1.0.0.0")]
|
[assembly: AssemblyVersion("1.1.0")]
|
||||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
[assembly: AssemblyFileVersion("1.1.0")]
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
|
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
|
||||||
<metadata>
|
<metadata>
|
||||||
<id>Modbus.Net.OPC</id>
|
<id>Modbus.Net.OPC</id>
|
||||||
<version>1.0.0</version>
|
<version>1.1.0</version>
|
||||||
<title>Modbus.Net.OPC</title>
|
<title>Modbus.Net.OPC</title>
|
||||||
<authors>Chris L.(Luo Sheng)</authors>
|
<authors>Chris L.(Luo Sheng)</authors>
|
||||||
<owners>Hangzhou Delian Information and Science Technology</owners>
|
<owners>Hangzhou Delian Information and Science Technology</owners>
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
<copyright>Copyright 2015 Hangzhou Delian Science and Technology Co.,Ltd.</copyright>
|
<copyright>Copyright 2015 Hangzhou Delian Science and Technology Co.,Ltd.</copyright>
|
||||||
<tags>hardware communicate protocal OPC DA Delian</tags>
|
<tags>hardware communicate protocal OPC DA Delian</tags>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency id="Modbus.Net" version="1.0.0" />
|
<dependency id="Modbus.Net" version="1.1.0" />
|
||||||
<dependency id="Modbus.Net.h-opc" version="0.4.0" />
|
<dependency id="Modbus.Net.h-opc" version="0.4.0" />
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</metadata>
|
</metadata>
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace Modbus.Net.OPC
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async Task<byte[]> GetDatasAsync(byte belongAddress, byte masterAddress, string startAddress, int getByteCount)
|
public override async Task<GetDataReturnDef> GetDatasAsync(byte belongAddress, byte masterAddress, string startAddress, int getByteCount)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -27,7 +27,11 @@ namespace Modbus.Net.OPC
|
|||||||
var readRequestOpcOutputStruct =
|
var readRequestOpcOutputStruct =
|
||||||
await
|
await
|
||||||
Wrapper.SendReceiveAsync(Wrapper[typeof(ReadRequestOpcProtocal)], readRequestOpcInputStruct) as ReadRequestOpcOutputStruct;
|
Wrapper.SendReceiveAsync(Wrapper[typeof(ReadRequestOpcProtocal)], readRequestOpcInputStruct) as ReadRequestOpcOutputStruct;
|
||||||
return readRequestOpcOutputStruct?.GetValue;
|
return new GetDataReturnDef()
|
||||||
|
{
|
||||||
|
ReturnValue = readRequestOpcOutputStruct?.GetValue,
|
||||||
|
IsLittleEndian = Wrapper[typeof (ReadRequestOpcProtocal)].IsLittleEndian
|
||||||
|
};
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
|||||||
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
|
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
|
||||||
// 方法是按如下所示使用“*”: :
|
// 方法是按如下所示使用“*”: :
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("1.0.0.0")]
|
[assembly: AssemblyVersion("1.1.0")]
|
||||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
[assembly: AssemblyFileVersion("1.1.0")]
|
||||||
|
|||||||
@@ -26,9 +26,10 @@ namespace Modbus.Net.Siemens
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public override KeyValuePair<int, int> AddressTranslate(string address, bool isRead)
|
public override AddressDef AddressTranslate(string address, bool isRead)
|
||||||
{
|
{
|
||||||
/*address = address.ToUpper();
|
/*
|
||||||
|
address = address.ToUpper();
|
||||||
if (address.Substring(0, 2) == "DB")
|
if (address.Substring(0, 2) == "DB")
|
||||||
{
|
{
|
||||||
var addressSplit = address.Split('.');
|
var addressSplit = address.Split('.');
|
||||||
@@ -36,8 +37,11 @@ namespace Modbus.Net.Siemens
|
|||||||
addressSplit[0] = addressSplit[0].Substring(2);
|
addressSplit[0] = addressSplit[0].Substring(2);
|
||||||
if (addressSplit[1].Substring(0, 2) == "DB")
|
if (addressSplit[1].Substring(0, 2) == "DB")
|
||||||
addressSplit[1] = addressSplit[1].Substring(2);
|
addressSplit[1] = addressSplit[1].Substring(2);
|
||||||
return new KeyValuePair<int, int>(int.Parse(addressSplit[1]),
|
return new AddressDef()
|
||||||
int.Parse(addressSplit[0])*256 + AreaCodeDictionary["DB"]);
|
{
|
||||||
|
Area = int.Parse(addressSplit[0])*256 + AreaCodeDictionary["DB"],
|
||||||
|
Address = int.Parse(addressSplit[1])
|
||||||
|
};
|
||||||
}
|
}
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int t;
|
int t;
|
||||||
@@ -49,8 +53,11 @@ namespace Modbus.Net.Siemens
|
|||||||
string head = address.Substring(0, i);
|
string head = address.Substring(0, i);
|
||||||
string tail = address.Substring(i);
|
string tail = address.Substring(i);
|
||||||
return
|
return
|
||||||
new KeyValuePair<int, int>(int.Parse(tail),
|
new AddressDef()
|
||||||
AreaCodeDictionary[head]);
|
{
|
||||||
|
Area = AreaCodeDictionary[head],
|
||||||
|
Address = int.Parse(tail)
|
||||||
|
};
|
||||||
*/
|
*/
|
||||||
string[] splitString = address.Split(' ');
|
string[] splitString = address.Split(' ');
|
||||||
string head = splitString[0];
|
string head = splitString[0];
|
||||||
@@ -58,12 +65,18 @@ namespace Modbus.Net.Siemens
|
|||||||
if (head.Length > 1 && head.Substring(0, 2) == "DB")
|
if (head.Length > 1 && head.Substring(0, 2) == "DB")
|
||||||
{
|
{
|
||||||
head = head.Substring(2);
|
head = head.Substring(2);
|
||||||
return new KeyValuePair<int, int>(int.Parse(tail),
|
return new AddressDef()
|
||||||
int.Parse(head)*256 + AreaCodeDictionary["DB"]);
|
{
|
||||||
|
Area = int.Parse(head)*256 + AreaCodeDictionary["DB"],
|
||||||
|
Address = int.Parse(tail)
|
||||||
|
};
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
new KeyValuePair<int, int>(int.Parse(tail),
|
new AddressDef()
|
||||||
AreaCodeDictionary[head]);
|
{
|
||||||
|
Area = AreaCodeDictionary[head],
|
||||||
|
Address = int.Parse(tail)
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
|
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
|
||||||
<metadata>
|
<metadata>
|
||||||
<id>Modbus.Net.Siemens</id>
|
<id>Modbus.Net.Siemens</id>
|
||||||
<version>1.0.0</version>
|
<version>1.1.0</version>
|
||||||
<title>Modbus.Net.Siemens</title>
|
<title>Modbus.Net.Siemens</title>
|
||||||
<authors>Chris L.(Luo Sheng)</authors>
|
<authors>Chris L.(Luo Sheng)</authors>
|
||||||
<owners>Hangzhou Delian Information and Science Technology Co.,Ltd.</owners>
|
<owners>Hangzhou Delian Information and Science Technology Co.,Ltd.</owners>
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
<copyright>Copyright 2015 Hangzhou Delian Science and Technology Co.,Ltd.</copyright>
|
<copyright>Copyright 2015 Hangzhou Delian Science and Technology Co.,Ltd.</copyright>
|
||||||
<tags>hardware communicate protocal Siemens profinet Delian</tags>
|
<tags>hardware communicate protocal Siemens profinet Delian</tags>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency id="Modbus.Net" version="1.0.0" />
|
<dependency id="Modbus.Net" version="1.1.0" />
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</metadata>
|
</metadata>
|
||||||
<files>
|
<files>
|
||||||
|
|||||||
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
|||||||
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
|
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
|
||||||
// 方法是按如下所示使用“*”: :
|
// 方法是按如下所示使用“*”: :
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("1.0.0.0")]
|
[assembly: AssemblyVersion("1.1.0")]
|
||||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
[assembly: AssemblyFileVersion("1.1.0")]
|
||||||
|
|||||||
@@ -190,8 +190,8 @@ namespace Modbus.Net.Siemens
|
|||||||
PduRef = pduRef;
|
PduRef = pduRef;
|
||||||
TypeCode = (byte) getType;
|
TypeCode = (byte) getType;
|
||||||
var address = addressTranslator.AddressTranslate(startAddress, true);
|
var address = addressTranslator.AddressTranslate(startAddress, true);
|
||||||
Offset = address.Key;
|
Offset = address.Address;
|
||||||
int area = address.Value;
|
int area = address.Area;
|
||||||
Area = (byte)(area%256);
|
Area = (byte)(area%256);
|
||||||
DbBlock = Area == 0x84 ? (ushort)(area/256) : (ushort)0;
|
DbBlock = Area == 0x84 ? (ushort)(area/256) : (ushort)0;
|
||||||
NumberOfElements = getCount;
|
NumberOfElements = getCount;
|
||||||
@@ -272,8 +272,8 @@ namespace Modbus.Net.Siemens
|
|||||||
{
|
{
|
||||||
PduRef = pduRef;
|
PduRef = pduRef;
|
||||||
var address = addressTranslator.AddressTranslate(startAddress, true);
|
var address = addressTranslator.AddressTranslate(startAddress, true);
|
||||||
Offset = address.Key;
|
Offset = address.Address;
|
||||||
int area = address.Value;
|
int area = address.Area;
|
||||||
Area = (byte)(area % 256);
|
Area = (byte)(area % 256);
|
||||||
DbBlock = Area == 0x84 ? (ushort)(area / 256) : (ushort)0;
|
DbBlock = Area == 0x84 ? (ushort)(area / 256) : (ushort)0;
|
||||||
WriteValue = writeValue;
|
WriteValue = writeValue;
|
||||||
|
|||||||
@@ -30,18 +30,18 @@ namespace Modbus.Net.Siemens
|
|||||||
_connectTryCount = 0;
|
_connectTryCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] SendReceive(params object[] content)
|
public override byte[] SendReceive(bool isLittleEndian, params object[] content)
|
||||||
{
|
{
|
||||||
return AsyncHelper.RunSync(() => SendReceiveAsync(content));
|
return AsyncHelper.RunSync(() => SendReceiveAsync(isLittleEndian, content));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<byte[]> SendReceiveAsync(params object[] content)
|
public override async Task<byte[]> SendReceiveAsync(bool isLittleEndian, params object[] content)
|
||||||
{
|
{
|
||||||
if (ProtocalLinker == null || !ProtocalLinker.IsConnected)
|
if (ProtocalLinker == null || !ProtocalLinker.IsConnected)
|
||||||
{
|
{
|
||||||
await ConnectAsync();
|
await ConnectAsync();
|
||||||
}
|
}
|
||||||
return await base.SendReceiveAsync(content);
|
return await base.SendReceiveAsync(isLittleEndian, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override OutputStruct SendReceive(ProtocalUnit unit, InputStruct content)
|
public override OutputStruct SendReceive(ProtocalUnit unit, InputStruct content)
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ namespace Modbus.Net.Siemens
|
|||||||
ConnectionType = (SiemensType) connectionType;
|
ConnectionType = (SiemensType) connectionType;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async Task<byte[]> GetDatasAsync(byte belongAddress, byte materAddress, string startAddress, int getByteCount)
|
public override async Task<GetDataReturnDef> GetDatasAsync(byte belongAddress, byte materAddress, string startAddress, int getByteCount)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -130,7 +130,11 @@ namespace Modbus.Net.Siemens
|
|||||||
await
|
await
|
||||||
Wrapper.SendReceiveAsync(Wrapper[typeof (ReadRequestSiemensProtocal)],
|
Wrapper.SendReceiveAsync(Wrapper[typeof (ReadRequestSiemensProtocal)],
|
||||||
readRequestSiemensInputStruct) as ReadRequestSiemensOutputStruct;
|
readRequestSiemensInputStruct) as ReadRequestSiemensOutputStruct;
|
||||||
return readRequestSiemensOutputStruct?.GetValue;
|
return new GetDataReturnDef()
|
||||||
|
{
|
||||||
|
ReturnValue = readRequestSiemensOutputStruct?.GetValue,
|
||||||
|
IsLittleEndian = Wrapper[typeof (ReadRequestSiemensProtocal)].IsLittleEndian
|
||||||
|
};
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,6 +3,12 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace Modbus.Net
|
namespace Modbus.Net
|
||||||
{
|
{
|
||||||
|
public class AddressDef
|
||||||
|
{
|
||||||
|
public int Area { get; set; }
|
||||||
|
public int Address { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 地址翻译器
|
/// 地址翻译器
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -14,7 +20,7 @@ namespace Modbus.Net
|
|||||||
/// <param name="address">地址前地址</param>
|
/// <param name="address">地址前地址</param>
|
||||||
/// <param name="isRead">是否为读取,是为读取,否为写入</param>
|
/// <param name="isRead">是否为读取,是为读取,否为写入</param>
|
||||||
/// <returns>Key为转换后的地址,Value为辅助码</returns>
|
/// <returns>Key为转换后的地址,Value为辅助码</returns>
|
||||||
public abstract KeyValuePair<int,int> AddressTranslate(string address, bool isRead);
|
public abstract AddressDef AddressTranslate(string address, bool isRead);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -22,14 +28,18 @@ namespace Modbus.Net
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class AddressTranslatorBase : AddressTranslator
|
public class AddressTranslatorBase : AddressTranslator
|
||||||
{
|
{
|
||||||
public override KeyValuePair<int, int> AddressTranslate(string address, bool isRead)
|
public override AddressDef AddressTranslate(string address, bool isRead)
|
||||||
{
|
{
|
||||||
int num1,num2;
|
int num1,num2;
|
||||||
string[] split = address.Split(':');
|
string[] split = address.Split(':');
|
||||||
if (split.Length != 2) throw new FormatException();
|
if (split.Length != 2) throw new FormatException();
|
||||||
if (int.TryParse(split[0], out num1) && int.TryParse(split[1], out num2))
|
if (int.TryParse(split[0], out num1) && int.TryParse(split[1], out num2))
|
||||||
{
|
{
|
||||||
return new KeyValuePair<int, int>(num2, num1);
|
return new AddressDef()
|
||||||
|
{
|
||||||
|
Area = num1,
|
||||||
|
Address = num2
|
||||||
|
};
|
||||||
}
|
}
|
||||||
throw new FormatException();
|
throw new FormatException();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -135,14 +135,16 @@ namespace Modbus.Net
|
|||||||
foreach (var communicateAddress in CommunicateAddresses)
|
foreach (var communicateAddress in CommunicateAddresses)
|
||||||
{
|
{
|
||||||
//获取数据
|
//获取数据
|
||||||
var datas =
|
var datasReturn =
|
||||||
await
|
await
|
||||||
BaseUtility.GetDatasAsync<byte>(2, 0,
|
BaseUtility.GetDatasAsync(2, 0,
|
||||||
AddressFormater.FormatAddress(communicateAddress.Area, communicateAddress.Address),
|
AddressFormater.FormatAddress(communicateAddress.Area, communicateAddress.Address),
|
||||||
(int)
|
(int)
|
||||||
Math.Ceiling(communicateAddress.GetCount*
|
Math.Ceiling(communicateAddress.GetCount*
|
||||||
BigEndianValueHelper.Instance.ByteLength[
|
BigEndianValueHelper.Instance.ByteLength[
|
||||||
communicateAddress.DataType.FullName]));
|
communicateAddress.DataType.FullName]));
|
||||||
|
var datas = datasReturn.ReturnValue;
|
||||||
|
|
||||||
//如果没有数据,终止
|
//如果没有数据,终止
|
||||||
if (datas == null || datas.Length == 0 || datas.Length !=
|
if (datas == null || datas.Length == 0 || datas.Length !=
|
||||||
(int)
|
(int)
|
||||||
@@ -165,8 +167,9 @@ namespace Modbus.Net
|
|||||||
{
|
{
|
||||||
PlcValue =
|
PlcValue =
|
||||||
Double.Parse(
|
Double.Parse(
|
||||||
BigEndianValueHelper.Instance.GetValue(datas, ref pos, address.DataType)
|
datasReturn.IsLittleEndian ? ValueHelper.Instance.GetValue(datas, ref pos, address.DataType)
|
||||||
.ToString())*address.Zoom,
|
.ToString() : BigEndianValueHelper.Instance.GetValue(datas, ref pos, address.DataType)
|
||||||
|
.ToString()) *address.Zoom,
|
||||||
UnitExtend = address.UnitExtend
|
UnitExtend = address.UnitExtend
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,19 +64,21 @@ namespace Modbus.Net
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 发送协议内容并接收,一般方法
|
/// 发送协议内容并接收,一般方法
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="isLittleEndian">是否是小端格式</param>
|
||||||
/// <param name="content">写入的内容,使用对象数组描述</param>
|
/// <param name="content">写入的内容,使用对象数组描述</param>
|
||||||
/// <returns>从设备获取的字节流</returns>
|
/// <returns>从设备获取的字节流</returns>
|
||||||
public virtual byte[] SendReceive(params object[] content)
|
public virtual byte[] SendReceive(bool isLittleEndian, params object[] content)
|
||||||
{
|
{
|
||||||
return AsyncHelper.RunSync(() => SendReceiveAsync(content));
|
return AsyncHelper.RunSync(() => SendReceiveAsync(isLittleEndian, content));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 发送协议内容并接收,一般方法
|
/// 发送协议内容并接收,一般方法
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="isLittleEndian">是否是小端格式</param>
|
||||||
/// <param name="content">写入的内容,使用对象数组描述</param>
|
/// <param name="content">写入的内容,使用对象数组描述</param>
|
||||||
/// <returns>从设备获取的字节流</returns>
|
/// <returns>从设备获取的字节流</returns>
|
||||||
public virtual async Task<byte[]> SendReceiveAsync(params object[] content)
|
public virtual async Task<byte[]> SendReceiveAsync(bool isLittleEndian, params object[] content)
|
||||||
{
|
{
|
||||||
if (ProtocalLinker == null || !ProtocalLinker.IsConnected)
|
if (ProtocalLinker == null || !ProtocalLinker.IsConnected)
|
||||||
{
|
{
|
||||||
@@ -84,7 +86,7 @@ namespace Modbus.Net
|
|||||||
}
|
}
|
||||||
if (ProtocalLinker != null)
|
if (ProtocalLinker != null)
|
||||||
{
|
{
|
||||||
return await ProtocalLinker.SendReceiveAsync(ProtocalUnit.TranslateContent(content));
|
return await ProtocalLinker.SendReceiveAsync(ProtocalUnit.TranslateContent(isLittleEndian, content));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,6 +5,12 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Modbus.Net
|
namespace Modbus.Net
|
||||||
{
|
{
|
||||||
|
public class GetDataReturnDef
|
||||||
|
{
|
||||||
|
public byte[] ReturnValue { get; set; }
|
||||||
|
public bool IsLittleEndian { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
public abstract class BaseUtility
|
public abstract class BaseUtility
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -50,7 +56,7 @@ namespace Modbus.Net
|
|||||||
/// <param name="startAddress">开始地址</param>
|
/// <param name="startAddress">开始地址</param>
|
||||||
/// <param name="getByteCount">获取字节数个数</param>
|
/// <param name="getByteCount">获取字节数个数</param>
|
||||||
/// <returns>接收到的byte数据</returns>
|
/// <returns>接收到的byte数据</returns>
|
||||||
protected virtual byte[] GetDatas(byte belongAddress, byte masterAddress, string startAddress, int getByteCount)
|
public virtual GetDataReturnDef GetDatas(byte belongAddress, byte masterAddress, string startAddress, int getByteCount)
|
||||||
{
|
{
|
||||||
return AsyncHelper.RunSync(() => GetDatasAsync(belongAddress, masterAddress, startAddress, getByteCount));
|
return AsyncHelper.RunSync(() => GetDatasAsync(belongAddress, masterAddress, startAddress, getByteCount));
|
||||||
}
|
}
|
||||||
@@ -63,7 +69,7 @@ namespace Modbus.Net
|
|||||||
/// <param name="startAddress">开始地址</param>
|
/// <param name="startAddress">开始地址</param>
|
||||||
/// <param name="getByteCount">获取字节数个数</param>
|
/// <param name="getByteCount">获取字节数个数</param>
|
||||||
/// <returns>接收到的byte数据</returns>
|
/// <returns>接收到的byte数据</returns>
|
||||||
protected abstract Task<byte[]> GetDatasAsync(byte belongAddress, byte masterAddress, string startAddress, int getByteCount);
|
public abstract Task<GetDataReturnDef> GetDatasAsync(byte belongAddress, byte masterAddress, string startAddress, int getByteCount);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取数据
|
/// 获取数据
|
||||||
@@ -94,9 +100,12 @@ namespace Modbus.Net
|
|||||||
{
|
{
|
||||||
string typeName = getTypeAndCount.Key.FullName;
|
string typeName = getTypeAndCount.Key.FullName;
|
||||||
double bCount = BigEndianValueHelper.Instance.ByteLength[typeName];
|
double bCount = BigEndianValueHelper.Instance.ByteLength[typeName];
|
||||||
byte[] getBytes = await GetDatasAsync(belongAddress, masterAddress, startAddress,
|
var getReturnValue = await GetDatasAsync(belongAddress, masterAddress, startAddress,
|
||||||
(int) Math.Ceiling(bCount*getTypeAndCount.Value));
|
(int)Math.Ceiling(bCount * getTypeAndCount.Value));
|
||||||
return BigEndianValueHelper.Instance.ByteArrayToObjectArray(getBytes, getTypeAndCount);
|
var getBytes = getReturnValue.ReturnValue;
|
||||||
|
return getReturnValue.IsLittleEndian
|
||||||
|
? ValueHelper.Instance.ByteArrayToObjectArray(getBytes, getTypeAndCount)
|
||||||
|
: BigEndianValueHelper.Instance.ByteArrayToObjectArray(getBytes, getTypeAndCount);
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
@@ -177,8 +186,11 @@ namespace Modbus.Net
|
|||||||
let typeName = getTypeAndCount.Key.FullName
|
let typeName = getTypeAndCount.Key.FullName
|
||||||
let bCount = BigEndianValueHelper.Instance.ByteLength[typeName]
|
let bCount = BigEndianValueHelper.Instance.ByteLength[typeName]
|
||||||
select (int) Math.Ceiling(bCount*getTypeAndCount.Value)).Sum();
|
select (int) Math.Ceiling(bCount*getTypeAndCount.Value)).Sum();
|
||||||
byte[] getBytes = await GetDatasAsync(belongAddress, masterAddress, startAddress, bAllCount);
|
var getReturnValue = await GetDatasAsync(belongAddress, masterAddress, startAddress, bAllCount);
|
||||||
return BigEndianValueHelper.Instance.ByteArrayToObjectArray(getBytes, translateTypeAndCount);
|
byte[] getBytes = getReturnValue.ReturnValue;
|
||||||
|
return getReturnValue.IsLittleEndian
|
||||||
|
? ValueHelper.Instance.ByteArrayToObjectArray(getBytes, translateTypeAndCount)
|
||||||
|
: BigEndianValueHelper.Instance.ByteArrayToObjectArray(getBytes, translateTypeAndCount);
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
|
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
|
||||||
<metadata>
|
<metadata>
|
||||||
<id>Modbus.Net</id>
|
<id>Modbus.Net</id>
|
||||||
<version>1.0.0</version>
|
<version>1.1.0</version>
|
||||||
<title>Modbus.Net</title>
|
<title>Modbus.Net</title>
|
||||||
<authors>Chris L.(Luo Sheng)</authors>
|
<authors>Chris L.(Luo Sheng)</authors>
|
||||||
<owners>Hangzhou Delian Information and Science Technology Co.,Ltd.</owners>
|
<owners>Hangzhou Delian Information and Science Technology Co.,Ltd.</owners>
|
||||||
|
|||||||
@@ -35,5 +35,5 @@ using System.Runtime.InteropServices;
|
|||||||
// 方法是按如下所示使用“*”:
|
// 方法是按如下所示使用“*”:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
|
|
||||||
[assembly: AssemblyVersion("1.0.0")]
|
[assembly: AssemblyVersion("1.1.0")]
|
||||||
[assembly: AssemblyFileVersion("1.0.0")]
|
[assembly: AssemblyFileVersion("1.1.0")]
|
||||||
@@ -4,6 +4,8 @@ namespace Modbus.Net
|
|||||||
{
|
{
|
||||||
public abstract class ProtocalUnit : IProtocalFormatting
|
public abstract class ProtocalUnit : IProtocalFormatting
|
||||||
{
|
{
|
||||||
|
public bool IsLittleEndian { get; protected set; } = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 从输入结构格式化
|
/// 从输入结构格式化
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -18,7 +20,7 @@ namespace Modbus.Net
|
|||||||
/// <returns>格式化后的字节流</returns>
|
/// <returns>格式化后的字节流</returns>
|
||||||
public virtual byte[] Format(params object[] message)
|
public virtual byte[] Format(params object[] message)
|
||||||
{
|
{
|
||||||
return TranslateContent(message);
|
return TranslateContent(IsLittleEndian, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -32,17 +34,19 @@ namespace Modbus.Net
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 转换静态方法,把对象数组转换为字节数组。
|
/// 转换静态方法,把对象数组转换为字节数组。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="isLittleEndian">是否是小端格式</param>
|
||||||
/// <param name="contents">对象数组</param>
|
/// <param name="contents">对象数组</param>
|
||||||
/// <returns>字节数组</returns>
|
/// <returns>字节数组</returns>
|
||||||
public static byte[] TranslateContent(params object[] contents)
|
public static byte[] TranslateContent(bool isLittleEndian, params object[] contents)
|
||||||
{
|
{
|
||||||
return BigEndianValueHelper.Instance.ObjectArrayToByteArray(contents);
|
return isLittleEndian
|
||||||
|
? ValueHelper.Instance.ObjectArrayToByteArray(contents)
|
||||||
|
: BigEndianValueHelper.Instance.ObjectArrayToByteArray(contents);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class SpecialProtocalUnit : ProtocalUnit
|
public abstract class SpecialProtocalUnit : ProtocalUnit
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -7,6 +7,12 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Modbus.Net
|
namespace Modbus.Net
|
||||||
{
|
{
|
||||||
|
public class TaskReturnDef
|
||||||
|
{
|
||||||
|
public int MachineId { get; set; }
|
||||||
|
public Dictionary<string, ReturnUnit> ReturnValues { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
public static class TimeRestore
|
public static class TimeRestore
|
||||||
{
|
{
|
||||||
public static int Restore = 0;
|
public static int Restore = 0;
|
||||||
@@ -215,7 +221,7 @@ namespace Modbus.Net
|
|||||||
/// 返回数据代理
|
/// 返回数据代理
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="returnValue"></param>
|
/// <param name="returnValue"></param>
|
||||||
public delegate void ReturnValuesDelegate(KeyValuePair<int, Dictionary<string,ReturnUnit>> returnValue);
|
public delegate void ReturnValuesDelegate(TaskReturnDef returnValue);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 返回数据事件
|
/// 返回数据事件
|
||||||
@@ -559,7 +565,11 @@ namespace Modbus.Net
|
|||||||
{
|
{
|
||||||
MoveMachineToLinked(machine.Id);
|
MoveMachineToLinked(machine.Id);
|
||||||
}
|
}
|
||||||
ReturnValues?.Invoke(new KeyValuePair<int, Dictionary<string,ReturnUnit>>(machine.Id, ans));
|
ReturnValues?.Invoke(new TaskReturnDef()
|
||||||
|
{
|
||||||
|
MachineId = machine.Id,
|
||||||
|
ReturnValues = ans
|
||||||
|
});
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -567,7 +577,11 @@ namespace Modbus.Net
|
|||||||
{
|
{
|
||||||
MoveMachineToUnlinked(machine.Id);
|
MoveMachineToUnlinked(machine.Id);
|
||||||
}
|
}
|
||||||
ReturnValues?.Invoke(new KeyValuePair<int, Dictionary<string,ReturnUnit>>(machine.Id, null));
|
ReturnValues?.Invoke(new TaskReturnDef()
|
||||||
|
{
|
||||||
|
MachineId = machine.Id,
|
||||||
|
ReturnValues = null
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,10 +52,10 @@ namespace NA200H.UI.WPF
|
|||||||
//machine.AddressTranslator = new AddressTranslatorNA200H();
|
//machine.AddressTranslator = new AddressTranslatorNA200H();
|
||||||
machine = new SiemensMachine(SiemensType.Tcp, "192.168.3.11", SiemensMachineModel.S7_300, new List<AddressUnit>()
|
machine = new SiemensMachine(SiemensType.Tcp, "192.168.3.11", SiemensMachineModel.S7_300, new List<AddressUnit>()
|
||||||
{
|
{
|
||||||
new AddressUnit() {Id = 1, Area = "V", Address = 1, CommunicationTag = "Add1", DataType = typeof(ushort), Zoom = 1, DecimalPos = 0},
|
new AddressUnit() {Id = 1, Area = "V", Address = 0, CommunicationTag = "Add1", DataType = typeof(ushort), Zoom = 1, DecimalPos = 0},
|
||||||
new AddressUnit() {Id = 2, Area = "V", Address = 3, CommunicationTag = "Add2", DataType = typeof(ushort), Zoom = 1, DecimalPos = 0},
|
new AddressUnit() {Id = 2, Area = "V", Address = 2, CommunicationTag = "Add2", DataType = typeof(ushort), Zoom = 1, DecimalPos = 0},
|
||||||
new AddressUnit() {Id = 3, Area = "V", Address = 5, CommunicationTag = "Add3", DataType = typeof(ushort), Zoom = 1, DecimalPos = 0},
|
new AddressUnit() {Id = 3, Area = "V", Address = 4, CommunicationTag = "Add3", DataType = typeof(ushort), Zoom = 1, DecimalPos = 0},
|
||||||
new AddressUnit() {Id = 4, Area = "V", Address = 7, CommunicationTag = "Ans", DataType = typeof(ushort), Zoom = 1, DecimalPos = 0}
|
new AddressUnit() {Id = 4, Area = "V", Address = 6, CommunicationTag = "Ans", DataType = typeof(ushort), Zoom = 1, DecimalPos = 0}
|
||||||
});
|
});
|
||||||
var result = machine.GetDatas();
|
var result = machine.GetDatas();
|
||||||
var resultFormat = BaseMachine.MapGetValuesToSetValues(result);
|
var resultFormat = BaseMachine.MapGetValuesToSetValues(result);
|
||||||
|
|||||||
@@ -43,14 +43,14 @@ namespace Siemens_S7_200.UI.WPF.TaskTest
|
|||||||
{
|
{
|
||||||
//唯一的参数包含返回值,是一个唯一标识符(machine的第二个参数),返回值(类型ReturnUnit)的键值对。
|
//唯一的参数包含返回值,是一个唯一标识符(machine的第二个参数),返回值(类型ReturnUnit)的键值对。
|
||||||
value = new List<string>();
|
value = new List<string>();
|
||||||
if (returnValues.Value != null)
|
if (returnValues.ReturnValues != null)
|
||||||
{
|
{
|
||||||
value = from val in returnValues.Value select val.Key + " " + val.Value.PlcValue;
|
value = from val in returnValues.ReturnValues select val.Key + " " + val.Value.PlcValue;
|
||||||
siemensItems.Dispatcher.Invoke(() => siemensItems.ItemsSource = value);
|
siemensItems.Dispatcher.Invoke(() => siemensItems.ItemsSource = value);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Console.WriteLine($"ip {returnValues.Key} not return value");
|
Console.WriteLine($"ip {returnValues.MachineId} not return value");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
//启动任务
|
//启动任务
|
||||||
|
|||||||
Reference in New Issue
Block a user