Wrong COM default settings fix.
This commit is contained in:
@@ -1,8 +1,4 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Modbus.Net.Modbus
|
||||
namespace Modbus.Net.Modbus
|
||||
{
|
||||
/// <summary>
|
||||
/// Modbus/Ascii码协议Tcp透传
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Text;
|
||||
|
||||
namespace Modbus.Net.Modbus
|
||||
{
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Modbus.Net.Modbus
|
||||
namespace Modbus.Net.Modbus
|
||||
{
|
||||
/// <summary>
|
||||
/// Modbus/Ascii码协议Udp透传
|
||||
@@ -15,7 +11,7 @@ namespace Modbus.Net.Modbus
|
||||
/// <param name="slaveAddress">从站号</param>
|
||||
/// <param name="masterAddress">主站号</param>
|
||||
public ModbusAsciiInUdpProtocol(byte slaveAddress, byte masterAddress)
|
||||
: this(ConfigurationReader.GetValueDirect("UDP:Modbus","IP"), slaveAddress, masterAddress)
|
||||
: this(ConfigurationReader.GetValueDirect("UDP:Modbus", "IP"), slaveAddress, masterAddress)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Text;
|
||||
|
||||
namespace Modbus.Net.Modbus
|
||||
{
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Modbus.Net.Modbus
|
||||
namespace Modbus.Net.Modbus
|
||||
{
|
||||
/// <summary>
|
||||
/// Modbus/Ascii码协议
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Ports;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Modbus.Net.Modbus
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Modbus.Net.Modbus
|
||||
namespace Modbus.Net.Modbus
|
||||
{
|
||||
/// <summary>
|
||||
/// Modbus/Rtu协议tcp透传
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Modbus.Net.Modbus
|
||||
namespace Modbus.Net.Modbus
|
||||
{
|
||||
/// <summary>
|
||||
/// Modbus/Rtu协议连接器Tcp透传
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Modbus.Net.Modbus
|
||||
namespace Modbus.Net.Modbus
|
||||
{
|
||||
/// <summary>
|
||||
/// Modbus/Rtu协议udp透传
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Modbus.Net.Modbus
|
||||
namespace Modbus.Net.Modbus
|
||||
{
|
||||
/// <summary>
|
||||
/// Modbus/Rtu协议连接器Udp透传
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Modbus.Net.Modbus
|
||||
namespace Modbus.Net.Modbus
|
||||
{
|
||||
/// <summary>
|
||||
/// Modbus/Rtu协议
|
||||
/// </summary>
|
||||
public class ModbusRtuProtocol : ModbusProtocol
|
||||
{
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
/// <param name="slaveAddress">从站号</param>
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Ports;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Modbus.Net.Modbus
|
||||
{
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Modbus.Net.Modbus
|
||||
namespace Modbus.Net.Modbus
|
||||
{
|
||||
/// <summary>
|
||||
/// Modbus/Tcp协议
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace Modbus.Net.Modbus
|
||||
namespace Modbus.Net.Modbus
|
||||
{
|
||||
/// <summary>
|
||||
/// Modbus/Tcp协议连接器
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Modbus.Net.Modbus
|
||||
namespace Modbus.Net.Modbus
|
||||
{
|
||||
/// <summary>
|
||||
/// Modbus/Udp协议
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace Modbus.Net.Modbus
|
||||
namespace Modbus.Net.Modbus
|
||||
{
|
||||
/// <summary>
|
||||
/// Modbus/Udp协议连接器
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Nito.AsyncEx;
|
||||
using System;
|
||||
using System.IO;
|
||||
using Nito.AsyncEx;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Modbus.Net.Siemens
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.IO.Ports;
|
||||
using System.Threading;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Nito.AsyncEx;
|
||||
using System;
|
||||
using System.IO;
|
||||
using Nito.AsyncEx;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Modbus.Net.Siemens
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace Modbus.Net.Siemens
|
||||
{
|
||||
|
||||
@@ -202,9 +202,9 @@ namespace Modbus.Net.Siemens
|
||||
}
|
||||
//MPI
|
||||
//case SiemensType.Mpi:
|
||||
//{
|
||||
//throw new NotImplementedException();
|
||||
//}
|
||||
//{
|
||||
//throw new NotImplementedException();
|
||||
//}
|
||||
//Ethenet
|
||||
case SiemensType.Tcp:
|
||||
{
|
||||
@@ -306,7 +306,8 @@ namespace Modbus.Net.Siemens
|
||||
Wrapper.SendReceiveAsync<WriteRequestSiemensOutputStruct>(
|
||||
Wrapper[typeof(WriteRequestSiemensProtocol)],
|
||||
writeRequestSiemensInputStruct);
|
||||
return new ReturnStruct<bool> {
|
||||
return new ReturnStruct<bool>
|
||||
{
|
||||
Datas = writeRequestSiemensOutputStruct?.AccessResult == SiemensAccessResult.NoError,
|
||||
IsSuccess = writeRequestSiemensOutputStruct?.AccessResult == SiemensAccessResult.NoError,
|
||||
ErrorCode = writeRequestSiemensOutputStruct?.AccessResult == SiemensAccessResult.NoError ? 0 : (int)writeRequestSiemensOutputStruct?.AccessResult,
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Modbus.Net
|
||||
{
|
||||
@@ -56,7 +53,7 @@ namespace Modbus.Net
|
||||
var firstColon = path.IndexOf(":");
|
||||
while (firstColon != -1)
|
||||
{
|
||||
root = root?.GetSection(path.Substring(0,firstColon));
|
||||
root = root?.GetSection(path.Substring(0, firstColon));
|
||||
path = path.Substring(firstColon + 1);
|
||||
firstColon = path.IndexOf(":");
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
|
||||
@@ -38,7 +36,7 @@ namespace Modbus.Net
|
||||
public FifoController(int acquireTime, bool activateSema = true, Func<byte[], ICollection<byte[]>> duplicateFunc = null, int? waitingListMaxCount = null)
|
||||
: base(duplicateFunc)
|
||||
{
|
||||
_waitingListMaxCount = int.Parse(waitingListMaxCount != null ? waitingListMaxCount.ToString() : null ?? ConfigurationReader.GetValueDirect("Controller","WaitingListCount"));
|
||||
_waitingListMaxCount = int.Parse(waitingListMaxCount != null ? waitingListMaxCount.ToString() : null ?? ConfigurationReader.GetValueDirect("Controller", "WaitingListCount"));
|
||||
if (activateSema)
|
||||
{
|
||||
_taskCycleSema = new Semaphore(0, _waitingListMaxCount);
|
||||
|
||||
@@ -6,58 +6,58 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Modbus.Net
|
||||
{
|
||||
/// <summary>
|
||||
/// 多设备任务调度器
|
||||
/// </summary>
|
||||
public sealed class MultipleMachinesJobScheduler
|
||||
{
|
||||
private static int _machineCount = 0;
|
||||
/// <summary>
|
||||
/// 多设备任务调度器
|
||||
/// </summary>
|
||||
public sealed class MultipleMachinesJobScheduler
|
||||
{
|
||||
private static int _machineCount = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 创建设备调度器
|
||||
/// </summary>
|
||||
/// <param name="machines">设备的集合</param>
|
||||
/// <param name="machineJobTemplate">设备的运行模板</param>
|
||||
/// <param name="count">重复次数,负数为无限循环,0为执行一次</param>
|
||||
/// <param name="intervalSecond">间隔秒数</param>
|
||||
/// <returns></returns>
|
||||
public static ParallelLoopResult RunScheduler<TKey>(IEnumerable<IMachine<TKey>> machines, Func<IMachine<TKey>, MachineGetJobScheduler, Task> machineJobTemplate, int count = 0, int intervalSecond = 1) where TKey: IEquatable<TKey>
|
||||
{
|
||||
_machineCount = machines.Count();
|
||||
return Parallel.ForEach(machines, (machine, state, index) =>
|
||||
{
|
||||
Task.Factory.StartNew(async () =>
|
||||
{
|
||||
Thread.Sleep((int)(intervalSecond * 1000.0 / _machineCount * index));
|
||||
var getJobScheduler = await MachineJobSchedulerCreator.CreateScheduler("Trigger" + index, count, intervalSecond);
|
||||
await machineJobTemplate(machine, getJobScheduler);
|
||||
});
|
||||
});
|
||||
}
|
||||
/// <summary>
|
||||
/// 创建设备调度器
|
||||
/// </summary>
|
||||
/// <param name="machines">设备的集合</param>
|
||||
/// <param name="machineJobTemplate">设备的运行模板</param>
|
||||
/// <param name="count">重复次数,负数为无限循环,0为执行一次</param>
|
||||
/// <param name="intervalSecond">间隔秒数</param>
|
||||
/// <returns></returns>
|
||||
public static ParallelLoopResult RunScheduler<TKey>(IEnumerable<IMachine<TKey>> machines, Func<IMachine<TKey>, MachineGetJobScheduler, Task> machineJobTemplate, int count = 0, int intervalSecond = 1) where TKey : IEquatable<TKey>
|
||||
{
|
||||
_machineCount = machines.Count();
|
||||
return Parallel.ForEach(machines, (machine, state, index) =>
|
||||
{
|
||||
Task.Factory.StartNew(async () =>
|
||||
{
|
||||
Thread.Sleep((int)(intervalSecond * 1000.0 / _machineCount * index));
|
||||
var getJobScheduler = await MachineJobSchedulerCreator.CreateScheduler("Trigger" + index, count, intervalSecond);
|
||||
await machineJobTemplate(machine, getJobScheduler);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建设备调度器
|
||||
/// </summary>
|
||||
/// <param name="machines">设备的集合</param>
|
||||
/// <param name="machineJobTemplate">设备的运行模板</param>
|
||||
/// <param name="count">重复次数,负数为无限循环,0为执行一次</param>
|
||||
/// <param name="intervalSecond">间隔秒数</param>
|
||||
/// <returns></returns>
|
||||
public static ParallelLoopResult RunScheduler(IEnumerable<IMachine<string>> machines, Func<IMachine<string>, MachineGetJobScheduler, Task> machineJobTemplate, int count = 0, int intervalSecond = 1)
|
||||
{
|
||||
return RunScheduler<string>(machines, machineJobTemplate, count, intervalSecond);
|
||||
}
|
||||
/// <summary>
|
||||
/// 创建设备调度器
|
||||
/// </summary>
|
||||
/// <param name="machines">设备的集合</param>
|
||||
/// <param name="machineJobTemplate">设备的运行模板</param>
|
||||
/// <param name="count">重复次数,负数为无限循环,0为执行一次</param>
|
||||
/// <param name="intervalSecond">间隔秒数</param>
|
||||
/// <returns></returns>
|
||||
public static ParallelLoopResult RunScheduler(IEnumerable<IMachine<string>> machines, Func<IMachine<string>, MachineGetJobScheduler, Task> machineJobTemplate, int count = 0, int intervalSecond = 1)
|
||||
{
|
||||
return RunScheduler<string>(machines, machineJobTemplate, count, intervalSecond);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取消任务
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static ParallelLoopResult CancelJob()
|
||||
{
|
||||
return Parallel.For(0, _machineCount, async index =>
|
||||
{
|
||||
await MachineJobSchedulerCreator.CancelJob("Trigger" + index);
|
||||
});
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 取消任务
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static ParallelLoopResult CancelJob()
|
||||
{
|
||||
return Parallel.For(0, _machineCount, async index =>
|
||||
{
|
||||
await MachineJobSchedulerCreator.CancelJob("Trigger" + index);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System;
|
||||
using System.IO.Ports;
|
||||
|
||||
namespace Modbus.Net
|
||||
@@ -22,9 +20,9 @@ namespace Modbus.Net
|
||||
/// <param name="slaveAddress">从站地址</param>
|
||||
/// <param name="isFullDuplex">是否为全双工</param>
|
||||
protected ComProtocolLinker(string com, int slaveAddress, int? baudRate = null, Parity? parity = null, StopBits? stopBits = null, int? dataBits = null,
|
||||
int? connectionTimeout = null, bool? isFullDuplex = null)
|
||||
int? connectionTimeout = null, bool? isFullDuplex = null)
|
||||
{
|
||||
baudRate = int.Parse(baudRate != null ? baudRate.ToString() : null ?? ConfigurationReader.GetValue("COM:"+com, "BaudRate"));
|
||||
baudRate = int.Parse(baudRate != null ? baudRate.ToString() : null ?? ConfigurationReader.GetValue("COM:" + com, "BaudRate"));
|
||||
parity = Enum.Parse<Parity>(parity != null ? parity.ToString() : null ?? ConfigurationReader.GetValue("COM:" + com, "Parity"));
|
||||
stopBits = Enum.Parse<StopBits>(stopBits != null ? stopBits.ToString() : null ?? ConfigurationReader.GetValue("COM:" + com, "StopBits"));
|
||||
dataBits = int.Parse(dataBits != null ? dataBits.ToString() : null ?? ConfigurationReader.GetValue("COM:" + com, "DataBits"));
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.IO;
|
||||
|
||||
namespace Modbus.Net
|
||||
namespace Modbus.Net
|
||||
{
|
||||
/// <summary>
|
||||
/// Tcp连接对象
|
||||
@@ -19,7 +14,7 @@ namespace Modbus.Net
|
||||
/// <param name="isFullDuplex">是否为全双工</param>
|
||||
protected TcpProtocolLinker(string ip, int port, int? connectionTimeout = null, bool? isFullDuplex = null)
|
||||
{
|
||||
connectionTimeout = int.Parse(connectionTimeout != null ? connectionTimeout.ToString() : null ?? ConfigurationReader.GetValue("TCP:"+ip+":"+port, "ConnectionTimeout"));
|
||||
connectionTimeout = int.Parse(connectionTimeout != null ? connectionTimeout.ToString() : null ?? ConfigurationReader.GetValue("TCP:" + ip + ":" + port, "ConnectionTimeout"));
|
||||
isFullDuplex = bool.Parse(isFullDuplex != null ? isFullDuplex.ToString() : null ?? ConfigurationReader.GetValue("TCP:" + ip + ":" + port, "FullDuplex"));
|
||||
//初始化连接对象
|
||||
BaseConnector = new TcpConnector(ip, port, connectionTimeout.Value, isFullDuplex.Value);
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Modbus.Net
|
||||
namespace Modbus.Net
|
||||
{
|
||||
/// <summary>
|
||||
/// Udp连接对象
|
||||
|
||||
@@ -213,7 +213,8 @@ namespace Modbus.Net
|
||||
await BaseUtility.ConnectAsync();
|
||||
//如果无法连接,终止
|
||||
if (!BaseUtility.IsConnected) return
|
||||
new ReturnStruct<Dictionary<string, ReturnUnit>>() {
|
||||
new ReturnStruct<Dictionary<string, ReturnUnit>>()
|
||||
{
|
||||
Datas = null,
|
||||
IsSuccess = false,
|
||||
ErrorCode = -1,
|
||||
@@ -493,11 +494,11 @@ namespace Modbus.Net
|
||||
ErrorMsg = datas.ErrorMsg
|
||||
};
|
||||
}
|
||||
else if(datas.Datas.Length <
|
||||
(int)
|
||||
Math.Ceiling(communicateAddress.GetCount *
|
||||
BigEndianValueHelper.Instance.ByteLength[
|
||||
communicateAddress.DataType.FullName]))
|
||||
else if (datas.Datas.Length <
|
||||
(int)
|
||||
Math.Ceiling(communicateAddress.GetCount *
|
||||
BigEndianValueHelper.Instance.ByteLength[
|
||||
communicateAddress.DataType.FullName]))
|
||||
return new ReturnStruct<bool>()
|
||||
{
|
||||
Datas = false,
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Modbus.Net
|
||||
namespace Modbus.Net
|
||||
{
|
||||
/// <summary>
|
||||
/// 返回引用类型
|
||||
|
||||
@@ -2,9 +2,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Policy;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
/// <summary>
|
||||
/// 端格式
|
||||
|
||||
@@ -26,8 +26,8 @@
|
||||
"FetchSleepTime": "100",
|
||||
"ConnectionTimeout": "5000",
|
||||
"BaudRate": "9600",
|
||||
"Parity": "Parity.None",
|
||||
"StopBits": "StopBits.One",
|
||||
"Parity": "None",
|
||||
"StopBits": "One",
|
||||
"DataBits": "8",
|
||||
"FullDuplex": "False",
|
||||
"Modbus": {
|
||||
|
||||
@@ -26,8 +26,8 @@
|
||||
"FetchSleepTime": "100",
|
||||
"ConnectionTimeout": "5000",
|
||||
"BaudRate": "9600",
|
||||
"Parity": "Parity.None",
|
||||
"StopBits": "StopBits.One",
|
||||
"Parity": "None",
|
||||
"StopBits": "One",
|
||||
"DataBits": "8",
|
||||
"FullDuplex": "False",
|
||||
"Modbus": {
|
||||
|
||||
@@ -26,8 +26,8 @@
|
||||
"FetchSleepTime": "100",
|
||||
"ConnectionTimeout": "5000",
|
||||
"BaudRate": "9600",
|
||||
"Parity": "Parity.None",
|
||||
"StopBits": "StopBits.One",
|
||||
"Parity": "None",
|
||||
"StopBits": "One",
|
||||
"DataBits": "8",
|
||||
"FullDuplex": "False",
|
||||
"Modbus": {
|
||||
|
||||
@@ -46,8 +46,8 @@ namespace MachineJob.Service
|
||||
|
||||
IMachine<string> machine = new ModbusMachine<string, string>("ModbusMachine1", ModbusType.Tcp, null, _addresses, true, 1, 2, Endian.BigEndianLsb);
|
||||
IMachine<string> machine2 = new SiemensMachine<string, string>("SiemensMachine1", SiemensType.Tcp, null, SiemensMachineModel.S7_1200, _addresses2, true, 1, 2);
|
||||
|
||||
var machines = new List<IMachine<string>>() { machine, machine2 };
|
||||
IMachine<string> machine3 = new ModbusMachine<string, string>("ModbusMachine2", ModbusType.Rtu, "COM3", _addresses, true, 3, 2);
|
||||
var machines = new List<IMachine<string>>() { machine, machine2, machine3 };
|
||||
return Task.Run(() => MultipleMachinesJobScheduler.RunScheduler(machines, async (machine, scheduler) =>
|
||||
{
|
||||
await scheduler.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();
|
||||
@@ -56,7 +56,7 @@ namespace MachineJob.Service
|
||||
|
||||
public override Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.Run(()=>MultipleMachinesJobScheduler.CancelJob());
|
||||
return Task.Run(() => MultipleMachinesJobScheduler.CancelJob());
|
||||
}
|
||||
|
||||
public Task OnSuccess(string machineId)
|
||||
@@ -67,51 +67,55 @@ namespace MachineJob.Service
|
||||
|
||||
public Task OnFailure(string machineId, int errorCode, string errorMsg)
|
||||
{
|
||||
_logger.LogError("Machine {0} set failure", machineId);
|
||||
_logger.LogError("Machine {0} set failure: {1}", machineId, errorMsg);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private Dictionary<string, double> QueryConsole(DataReturnDef dataReturnDef)
|
||||
private Dictionary<string, double>? QueryConsole(DataReturnDef dataReturnDef)
|
||||
{
|
||||
var values = dataReturnDef.ReturnValues.Datas;
|
||||
foreach (var value in values)
|
||||
if (dataReturnDef.ReturnValues.IsSuccess)
|
||||
{
|
||||
_logger.LogInformation(dataReturnDef.MachineId + " " + value.Key + " " + value.Value.DeviceValue);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
using (var context = new DatabaseWriteContext())
|
||||
foreach (var value in values)
|
||||
{
|
||||
context.DatabaseWrites.Add(new DatabaseWriteEntity
|
||||
{
|
||||
Value1 = values["Test1"].DeviceValue,
|
||||
Value2 = values["Test2"].DeviceValue,
|
||||
Value3 = values["Test3"].DeviceValue,
|
||||
Value4 = values["Test4"].DeviceValue,
|
||||
Value5 = values["Test5"].DeviceValue,
|
||||
Value6 = values["Test6"].DeviceValue,
|
||||
Value7 = values["Test7"].DeviceValue,
|
||||
Value8 = values["Test8"].DeviceValue,
|
||||
Value9 = values["Test9"].DeviceValue,
|
||||
Value10 = values["Test10"].DeviceValue,
|
||||
UpdateTime = DateTime.Now,
|
||||
});
|
||||
context.SaveChanges();
|
||||
_logger.LogInformation(dataReturnDef.MachineId + " " + value.Key + " " + value.Value.DeviceValue);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
//ignore
|
||||
}
|
||||
|
||||
Random r = new Random();
|
||||
foreach (var value in values)
|
||||
{
|
||||
value.Value.DeviceValue = r.Next(65536) - 32768;
|
||||
}
|
||||
try
|
||||
{
|
||||
using (var context = new DatabaseWriteContext())
|
||||
{
|
||||
context.DatabaseWrites.Add(new DatabaseWriteEntity
|
||||
{
|
||||
Value1 = values["Test1"].DeviceValue,
|
||||
Value2 = values["Test2"].DeviceValue,
|
||||
Value3 = values["Test3"].DeviceValue,
|
||||
Value4 = values["Test4"].DeviceValue,
|
||||
Value5 = values["Test5"].DeviceValue,
|
||||
Value6 = values["Test6"].DeviceValue,
|
||||
Value7 = values["Test7"].DeviceValue,
|
||||
Value8 = values["Test8"].DeviceValue,
|
||||
Value9 = values["Test9"].DeviceValue,
|
||||
Value10 = values["Test10"].DeviceValue,
|
||||
UpdateTime = DateTime.Now,
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
//ignore
|
||||
}
|
||||
|
||||
return values.MapGetValuesToSetValues();
|
||||
Random r = new Random();
|
||||
foreach (var value in values)
|
||||
{
|
||||
value.Value.DeviceValue = r.Next(65536) - 32768;
|
||||
}
|
||||
|
||||
return values.MapGetValuesToSetValues();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,8 +26,8 @@
|
||||
"FetchSleepTime": "100",
|
||||
"ConnectionTimeout": "5000",
|
||||
"BaudRate": "9600",
|
||||
"Parity": "Parity.None",
|
||||
"StopBits": "StopBits.One",
|
||||
"Parity": "None",
|
||||
"StopBits": "One",
|
||||
"DataBits": "8",
|
||||
"FullDuplex": "False",
|
||||
"Modbus": {
|
||||
|
||||
@@ -26,8 +26,8 @@
|
||||
"FetchSleepTime": "100",
|
||||
"ConnectionTimeout": "5000",
|
||||
"BaudRate": "9600",
|
||||
"Parity": "Parity.None",
|
||||
"StopBits": "StopBits.One",
|
||||
"Parity": "None",
|
||||
"StopBits": "One",
|
||||
"DataBits": "8",
|
||||
"FullDuplex": "False",
|
||||
"Modbus": {
|
||||
|
||||
Reference in New Issue
Block a user