Fix a bug in controller

This commit is contained in:
luosheng
2023-02-22 15:58:21 +08:00
parent 5095205f19
commit d7a9156455
35 changed files with 48 additions and 54 deletions

View File

@@ -19,7 +19,7 @@ namespace Modbus.Net.Siemens
public SiemensPpiProtocolLinker(string com, int slaveAddress) public SiemensPpiProtocolLinker(string com, int slaveAddress)
: base(com, 9600, Parity.Even, StopBits.One, 8, slaveAddress) : base(com, 9600, Parity.Even, StopBits.One, 8, slaveAddress)
{ {
((BaseConnector)BaseConnector).AddController(new FifoController(int.Parse(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["FetchSleepTime"] ?? "0"))); ((BaseConnector)BaseConnector).AddController(new FifoController(int.Parse(new ConfigurationBuilder().AddJsonFile($"appsettings.json").Build().GetSection("Config")["FetchSleepTime"] ?? "0"), true, null, 100));
} }
/// <summary> /// <summary>

View File

@@ -26,7 +26,7 @@ namespace Modbus.Net.Siemens
public SiemensTcpProtocolLinker(string ip, int port) public SiemensTcpProtocolLinker(string ip, int port)
: base(ip, port) : base(ip, port)
{ {
((BaseConnector)BaseConnector).AddController(new MatchDirectlySendController(new ICollection<(int,int)>[] { new List<(int,int)> { (11,11), (12,12) } }, DuplicateWithCount.GetDuplcateFunc(new List<int>{2, 3}, 0))); ((BaseConnector)BaseConnector).AddController(new MatchDirectlySendController(new ICollection<(int,int)>[] { new List<(int,int)> { (11,11), (12,12) } }, DuplicateWithCount.GetDuplcateFunc(new List<int>{2, 3}, 0), 100));
} }
/// <summary> /// <summary>

View File

@@ -15,7 +15,7 @@ namespace Modbus.Net
private bool _taskCancel = false; private bool _taskCancel = false;
private int _waitingListMaxCount = 10000; private int _waitingListMaxCount;
private readonly Semaphore _taskCycleSema; private readonly Semaphore _taskCycleSema;
@@ -30,9 +30,11 @@ namespace Modbus.Net
/// <param name="acquireTime">间隔时间</param> /// <param name="acquireTime">间隔时间</param>
/// <param name="activateSema">是否开启信号量</param> /// <param name="activateSema">是否开启信号量</param>
/// <param name="duplicateFunc">包切分函数</param> /// <param name="duplicateFunc">包切分函数</param>
public FifoController(int acquireTime, bool activateSema = true, Func<byte[], ICollection<byte[]>> duplicateFunc = null) /// <param name="waitingListMaxCount">包等待队列长度</param>
public FifoController(int acquireTime, bool activateSema = true, Func<byte[], ICollection<byte[]>> duplicateFunc = null, int waitingListMaxCount = 1)
: base(duplicateFunc) : base(duplicateFunc)
{ {
_waitingListMaxCount = waitingListMaxCount;
if (activateSema) if (activateSema)
{ {
_taskCycleSema = new Semaphore(0, _waitingListMaxCount); _taskCycleSema = new Semaphore(0, _waitingListMaxCount);

View File

@@ -21,8 +21,9 @@ namespace Modbus.Net
/// <param name="acquireTime">获取间隔</param> /// <param name="acquireTime">获取间隔</param>
/// <param name="activateSema">是否开启信号量</param> /// <param name="activateSema">是否开启信号量</param>
/// <param name="duplicateFunc">包切分函数</param> /// <param name="duplicateFunc">包切分函数</param>
/// <param name="waitingListMaxCount">包切分函数</param>
public MatchController(ICollection<(int, int)>[] keyMatches, int acquireTime, bool activateSema = true, public MatchController(ICollection<(int, int)>[] keyMatches, int acquireTime, bool activateSema = true,
Func<byte[], ICollection<byte[]>> duplicateFunc = null) : base(acquireTime, activateSema, duplicateFunc) Func<byte[], ICollection<byte[]>> duplicateFunc = null, int waitingListMaxCount = 1) : base(acquireTime, activateSema, duplicateFunc, waitingListMaxCount)
{ {
KeyMatches = keyMatches; KeyMatches = keyMatches;
} }

View File

@@ -10,8 +10,8 @@ namespace Modbus.Net
{ {
/// <inheritdoc /> /// <inheritdoc />
public MatchDirectlySendController(ICollection<(int, int)>[] keyMatches, public MatchDirectlySendController(ICollection<(int, int)>[] keyMatches,
Func<byte[], ICollection<byte[]>> duplicateFunc = null) : base(keyMatches, Func<byte[], ICollection<byte[]>> duplicateFunc = null, int waitingListMaxCount = 1) : base(keyMatches,
0, false, duplicateFunc) 0, false, duplicateFunc, waitingListMaxCount)
{ {
} }

View File

@@ -0,0 +1,4 @@
x^íWÝrÛD–ÿ­Ô-<2D><>´3!.¸q…í¦CœÒ;xj¨§¢¹Éxܵtš.^íí*­y ž¦ð<À
3ü<ìä<E28098>˜Œ ±ÛéEäÑYyÏîwt¾³çìÊȆñ—¾°Å«ÕÂw)À¥ãÒ€(ê9=Â÷<C382>m&¼qÛ§J„<4A><E2809E>Pµv!”TðfýV­æÔõ½Ñ¨Õ<C2A8>zÕjELE!49D*$¬jõ££Þ=˜~)ÆÀ›<b¬DÇ»{¢ÍðÁq!< НÀS÷'J[•N7˜°ã}m®Â)z`æP °Y@QÔ¢€}«3ƒh¹1LKžà
ž©ÂadòÆÝÿoâþÿuýVdPKZ¬ê©Ç-Á™HðÍrÌz»‰ƒÌµ¸¯<C2B8>öÏiñö<03>:X<>ÎwQ ÍJ<®øJ¸È¯†<E280A0>y”>ó("ûzþüºtg§'öõP$®ÑØyÄŠi=¯E§G¤r<C2A4>icZÿÉBý^¼M$=ìN̘<17>ý7´¨¬k1šáÜ<C3A1>”@$ÁS<C381>„ÏA%§€á_žX̼l×Ïø7žM[OÉ+ü©ËÅ<C385>Ö(—Špº~QM'ºÑ„•îùÇF|]\·<> .`ô,ó‡ÆG?ÕVfÚßSíw©6ƒÚ 3ío'h+ïèïD¾:½<><C2BD>LžP/‰å²<C3A5>ÁU°ªµŠ)ueóXên<C3AA>‡Ãmâ<6D>)ßïP`þû›áEº ´D0¸šñÁæ¡ê!÷E 3?&—Ï~Ÿu§RAà`‰IòA:;À!Ô/õ)<29>;H8}ÔØÛKv¹ºÖ¨Z<C2A8>ôDÈèèâ6œþ^LØèæMrÝ»~£~ûÚÔnÝ`î(OUëUl_ƒÁ½%Þ·O(‡Ñ™U&ó"fدz¯—äáÐ(£<>xg|ÐàYüOä°”b”kBXþŒÈ'.ýÎëÑ»HyŸÐPêM9Wþ6³€æ´mFÕt†÷¨þ29”\ú£.œÿXð÷˜Tæ{Fz»„y Õ^èÈ܆ãìRxŠ<78>ØÎŸTÞ
†Éñü6CL%u×Ýu@¸>¹(¥K¸,æ~Z´¬NÌ^W…zêÊ#øòÀ¸—µXË#å¯a&ái£t)>s¤wîùYn<59>*·ò¿èýӑ‡•O0#_^æ@zÔ<7A>lº¬ ?ëè¬

View File

@@ -0,0 +1 @@
￿༥ԣ⌣楤ᄞ⌣⍖楳畬楺慴楯湒潯瑂牯睳慢汥䥤ᄋ⌣⍔慲来瑉搑ю慭攟ୄ楳灬慹乡浥Ἥ⌣⍓敡牣桡扬敎潮呥捨湩捡汆楥汤乡浥獏晄潣畭敮琐ణ⌣偡牥湴䥤猑ᐣ⌣䥭浥摩慴敐慲敮瑉搑ᐣ⌣剥晥牥湣敆楥汤䥤猑ሣ⌣卥慲捨䙩汴敲䥤猑Ք楴汥Ἀ䱡湧畡来ἇ噥牳楯渟ൃ潮獴慮琠湡浥Ἃ䕶敮琠捬慳猟ᐣ⌣啰摡瑡扬敐慲敮瑉搑ᑉ湴敲晡捥䵥浢敲彎慭攟ᡉ湴敲晡捥䵥浢敲彄慴慴祰攟ᕉ湴敲晡捥䵥浢敲彖慬略἗䥮瑥牦慣敍敭扥牟䍯浭敮琟ൎ整睯牫⁴楴汥Ἃ䱁䑆䉄潤攟ࡓ䍌潤攟݃潭浥湴Ἀ䑡瑡瑹灥ἇ䅤摲敳猟Ֆ慬略ἆ䅵瑨潲ἆ䙡浩汹Ἃ䥮獴慮捥䈟ᜣ⌣剥捯湳瑩瑵瑩潮䑡瑡䥄ᄘ䅳獯捩慴敤䍵汴畲敆楥汤䥤ဘ䅳獯捩慴敤偲潪散瑖敲獩潮အ䅳獯捩慴敤䥮摥硄慴慖敲獩潮䙩敬摉搐ⱁ獳潣楡瑥摔散桮楣慬䙩敬摎慭敳䡡獨䍯摥䙩敬摉搐ⵁ獳潣楡瑥摔散桮楣慬䙩敬摃潮瑥湴噥牳楯湆楥汤䥤ဎ䥮摥硁瑯浓瑯牥<EFBFBD>

View File

@@ -0,0 +1,3 @@
Ťź
uW]cio{<03>Ťź
uW]cio{<03>Ł wU8 E

File diff suppressed because one or more lines are too long

View File

@@ -19,6 +19,7 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\Modbus.Net\Modbus.Net.Modbus\Modbus.Net.Modbus.csproj" /> <ProjectReference Include="..\..\Modbus.Net\Modbus.Net.Modbus\Modbus.Net.Modbus.csproj" />
<ProjectReference Include="..\..\Modbus.Net\Modbus.Net.Siemens\Modbus.Net.Siemens.csproj" />
<ProjectReference Include="..\..\Modbus.Net\Modbus.Net\Modbus.Net.csproj" /> <ProjectReference Include="..\..\Modbus.Net\Modbus.Net\Modbus.Net.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -1,5 +1,6 @@
using Modbus.Net; using Modbus.Net;
using Modbus.Net.Modbus; using Modbus.Net.Modbus;
using Modbus.Net.Siemens;
namespace MachineJob.Service namespace MachineJob.Service
{ {
@@ -14,6 +15,7 @@ namespace MachineJob.Service
protected override async Task ExecuteAsync(CancellationToken stoppingToken) protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{ {
List<AddressUnit> _addresses = new List<AddressUnit> List<AddressUnit> _addresses = new List<AddressUnit>
{ {
new AddressUnit() { Area = "4X", Address = 1, DataType = typeof(short), Id = "1", Name = "Test1" }, new AddressUnit() { Area = "4X", Address = 1, DataType = typeof(short), Id = "1", Name = "Test1" },
@@ -28,11 +30,26 @@ namespace MachineJob.Service
new AddressUnit() { Area = "4X", Address = 10, DataType = typeof(short), Id = "10", Name = "Test10" } new AddressUnit() { Area = "4X", Address = 10, DataType = typeof(short), Id = "10", Name = "Test10" }
}; };
IMachine<string> machine = new ModbusMachine<string, string>("ModbusMachine1", ModbusType.Tcp, "192.168.0.172", _addresses, true, 1, 2, Endian.BigEndianLsb); /*
//IMachine<string> machine2 = new ModbusMachine<string, string>("ModbusMachine2", ModbusType.Tcp, "192.168.0.172", _addresses, true, 3, 2, Endian.BigEndianLsb); List<AddressUnit> _addresses2 = new List<AddressUnit>
{
new AddressUnit() { Area = "DB1", Address = 0, DataType = typeof(short), Id = "1", Name = "Test1" },
new AddressUnit() { Area = "DB1", Address = 2, DataType = typeof(short), Id = "2", Name = "Test2" },
new AddressUnit() { Area = "DB1", Address = 4, DataType = typeof(short), Id = "3", Name = "Test3" },
new AddressUnit() { Area = "DB1", Address = 6, DataType = typeof(short), Id = "4", Name = "Test4" },
new AddressUnit() { Area = "DB1", Address = 8, DataType = typeof(short), Id = "5", Name = "Test5" },
new AddressUnit() { Area = "DB1", Address = 10, DataType = typeof(short), Id = "6", Name = "Test6" },
new AddressUnit() { Area = "DB1", Address = 12, DataType = typeof(short), Id = "7", Name = "Test7" },
new AddressUnit() { Area = "DB1", Address = 14, DataType = typeof(short), Id = "8", Name = "Test8" },
new AddressUnit() { Area = "DB1", Address = 16, DataType = typeof(short), Id = "9", Name = "Test9" },
new AddressUnit() { Area = "DB1", Address = 18, DataType = typeof(short), Id = "10", Name = "Test10" }
};
*/
IMachine<string> machine = new ModbusMachine<string, string>("ModbusMachine1", ModbusType.Tcp, "192.168.0.161", _addresses, true, 1, 2, Endian.BigEndianLsb);
//IMachine<string> machine2 = new SiemensMachine<string, string>("SiemensMachine1", SiemensType.Tcp, "192.168.0.161", SiemensMachineModel.S7_1200, _addresses2, true, 1, 2);
await MachineJobSchedulerCreator.CreateScheduler("Trigger1", -1, 5).Result.From(machine.Id, machine, MachineDataType.Name).Result.Query(machine.Id + ".ConsoleQuery", QueryConsole).Result.To(machine.Id + ".To", machine).Result.Deal(machine.Id+".Deal", OnSuccess, OnFailure).Result.Run(); await MachineJobSchedulerCreator.CreateScheduler("Trigger1", -1, 5).Result.From(machine.Id, machine, MachineDataType.Name).Result.Query(machine.Id + ".ConsoleQuery", QueryConsole).Result.To(machine.Id + ".To", machine).Result.Deal(machine.Id+".Deal", OnSuccess, OnFailure).Result.Run();
//await MachineJobSchedulerCreator.CreateScheduler("Trigger2", -1, 5).Result.Apply(machine2.Id + ".Apply", null, MachineDataType.Name).Result.Query(machine2.Id + ".ConsoleQuery", QueryConsole2).Result.To(machine2.Id + ".To", machine2).Result.Deal(machine.Id + ".Deal", OnSuccess, OnFailure).Result.From(machine2.Id, machine2, MachineDataType.Name).Result.Query(machine2.Id + ".ConsoleQuery2", QueryConsole).Result.Run(); //await MachineJobSchedulerCreator.CreateScheduler("Trigger2", -1, 5).Result.From(machine2.Id, machine2, MachineDataType.Name).Result.Query(machine2.Id + ".ConsoleQuery", QueryConsole).Result.To(machine2.Id + ".To", machine2).Result.Deal(machine2.Id + ".Deal", OnSuccess, OnFailure).Result.Run();
} }
public override async Task StopAsync(CancellationToken cancellationToken) public override async Task StopAsync(CancellationToken cancellationToken)
@@ -94,45 +111,5 @@ namespace MachineJob.Service
return values.MapGetValuesToSetValues(); return values.MapGetValuesToSetValues();
} }
private Dictionary<string, double> QueryConsole2(DataReturnDef dataReturnDef)
{
Random r = new Random();
var datas = new Dictionary<string, double>()
{
{
"Test1", r.Next(65536) - 32768
},
{
"Test2", r.Next(65536) - 32768
},
{
"Test3", r.Next(65536) - 32768
},
{
"Test4", r.Next(65536) - 32768
},
{
"Test5", r.Next(65536) - 32768
},
{
"Test6", r.Next(65536) - 32768
},
{
"Test7", r.Next(65536) - 32768
},
{
"Test8", r.Next(65536) - 32768
},
{
"Test9", r.Next(65536) - 32768
},
{
"Test10", r.Next(65536) - 32768
}
};
return datas;
}
} }
} }