Fix a bug in controller
This commit is contained in:
@@ -19,7 +19,7 @@ namespace Modbus.Net.Siemens
|
||||
public SiemensPpiProtocolLinker(string com, int 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>
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace Modbus.Net.Siemens
|
||||
public SiemensTcpProtocolLinker(string ip, int 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>
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Modbus.Net
|
||||
|
||||
private bool _taskCancel = false;
|
||||
|
||||
private int _waitingListMaxCount = 10000;
|
||||
private int _waitingListMaxCount;
|
||||
|
||||
private readonly Semaphore _taskCycleSema;
|
||||
|
||||
@@ -30,14 +30,16 @@ namespace Modbus.Net
|
||||
/// <param name="acquireTime">间隔时间</param>
|
||||
/// <param name="activateSema">是否开启信号量</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)
|
||||
{
|
||||
_waitingListMaxCount = waitingListMaxCount;
|
||||
if (activateSema)
|
||||
{
|
||||
_taskCycleSema = new Semaphore(0, _waitingListMaxCount);
|
||||
}
|
||||
AcquireTime = acquireTime;
|
||||
AcquireTime = acquireTime;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -21,8 +21,9 @@ namespace Modbus.Net
|
||||
/// <param name="acquireTime">获取间隔</param>
|
||||
/// <param name="activateSema">是否开启信号量</param>
|
||||
/// <param name="duplicateFunc">包切分函数</param>
|
||||
/// <param name="waitingListMaxCount">包切分函数</param>
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@ namespace Modbus.Net
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public MatchDirectlySendController(ICollection<(int, int)>[] keyMatches,
|
||||
Func<byte[], ICollection<byte[]>> duplicateFunc = null) : base(keyMatches,
|
||||
0, false, duplicateFunc)
|
||||
Func<byte[], ICollection<byte[]>> duplicateFunc = null, int waitingListMaxCount = 1) : base(keyMatches,
|
||||
0, false, duplicateFunc, waitingListMaxCount)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -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!< H§Š¯ÀS÷'J[•N7˜°ã}m®Â)z`æP °Y@QÔ¢€}«3ƒh¹1LKžà
|
||||
ž©ÂadòÆÝÿoâþÿuýV…dPKZ¬ê©Ç-Á™HðÍrÌz»‰ƒÌµ¸¯<C2B8>öÏiñö<03>:X<>ÎwQ ÍJ<®øJ¸È¯†‹<E280A0>y”>ó("ûzþüºt’g§'öõ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¸šñÁæ¡ê!÷E3?&—Ï~Ÿu§RAà`‰IòA:;À!Ô/õ)<29>;H8}ÔØÛKv¹ºÖ¨Z<C2A8>ôDÈèèâ6œþ^LØèæMrÝ»~£~ûÚÔnÝT÷–`î(OUëUl_ƒÁ½%Þ·O(‡Ñ™U&ó"fدz¯S½—äáÐ(£<>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º¬?ëè¬
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1 @@
|
||||
༥ԣ⌣楤ᄞ⌣⍖楳畬楺慴楯湒潯瑂牯睳慢汥䥤ᄋ⌣⍔慲来瑉搑ю慭攟ୄ楳灬慹乡浥Ἥ⌣⍓敡牣桡扬敎潮呥捨湩捡汆楥汤乡浥獏晄潣畭敮琐ణ⌣偡牥湴䥤猑ᐣ⌣䥭浥摩慴敐慲敮瑉搑ᐣ⌣剥晥牥湣敆楥汤䥤猑ሣ⌣卥慲捨䙩汴敲䥤猑Ք楴汥Ἀ䱡湧畡来ἇ噥牳楯渟ൃ潮獴慮琠湡浥Ἃ䕶敮琠捬慳猟ᐣ⌣啰摡瑡扬敐慲敮瑉搑ᑉ湴敲晡捥䵥浢敲彎慭攟ᡉ湴敲晡捥䵥浢敲彄慴慴祰攟ᕉ湴敲晡捥䵥浢敲彖慬略䥮瑥牦慣敍敭扥牟䍯浭敮琟ൎ整睯牫⁴楴汥Ἃ䱁䑆䉄⁃潤攟ࡓ䍌⁃潤攟݃潭浥湴Ἀ䑡瑡瑹灥ἇ䅤摲敳猟Ֆ慬略ἆ䅵瑨潲ἆ䙡浩汹Ἃ䥮獴慮捥⁄䈟ᜣ⌣剥捯湳瑩瑵瑩潮䑡瑡䥄ᄘ䅳獯捩慴敤䍵汴畲敆楥汤䥤ဘ䅳獯捩慴敤偲潪散瑖敲獩潮အ䅳獯捩慴敤䥮摥硄慴慖敲獩潮䙩敬摉搐ⱁ獳潣楡瑥摔散桮楣慬䙩敬摎慭敳䡡獨䍯摥䙩敬摉搐ⵁ獳潣楡瑥摔散桮楣慬䙩敬摃潮瑥湴噥牳楯湆楥汤䥤ဎ䥮摥硁瑯浓瑯牥<EFBFBD>
|
||||
@@ -0,0 +1,3 @@
|
||||
Ť“™‡ź
|
||||
uW]cio{<03>Ť“™‡ź
|
||||
uW]cio{<03>Ł‘‹wU8E
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
BIN
Samples/Automation Projects/Automation/MachineJob/Vci/Vci.db
Normal file
BIN
Samples/Automation Projects/Automation/MachineJob/Vci/Vci.db
Normal file
Binary file not shown.
BIN
Samples/Automation Projects/Automation/MachineJob/XRef/XRef.db
Normal file
BIN
Samples/Automation Projects/Automation/MachineJob/XRef/XRef.db
Normal file
Binary file not shown.
@@ -19,6 +19,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<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" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Modbus.Net;
|
||||
using Modbus.Net.Modbus;
|
||||
using Modbus.Net.Siemens;
|
||||
|
||||
namespace MachineJob.Service
|
||||
{
|
||||
@@ -14,6 +15,7 @@ namespace MachineJob.Service
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
|
||||
List<AddressUnit> _addresses = new List<AddressUnit>
|
||||
{
|
||||
new AddressUnit() { Area = "4X", Address = 1, DataType = typeof(short), Id = "1", Name = "Test1" },
|
||||
@@ -27,12 +29,27 @@ namespace MachineJob.Service
|
||||
new AddressUnit() { Area = "4X", Address = 9, DataType = typeof(short), Id = "9", Name = "Test9" },
|
||||
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("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)
|
||||
@@ -59,7 +76,7 @@ namespace MachineJob.Service
|
||||
{
|
||||
Console.WriteLine(dataReturnDef.MachineId + " " + value.Key + " " + value.Value.DeviceValue);
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
using (var context = new DatabaseWriteContext())
|
||||
@@ -85,7 +102,7 @@ namespace MachineJob.Service
|
||||
{
|
||||
//ignore
|
||||
}
|
||||
|
||||
|
||||
Random r = new Random();
|
||||
foreach (var value in values)
|
||||
{
|
||||
@@ -94,45 +111,5 @@ namespace MachineJob.Service
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user