From eb7ac0eff1a5c4ce88701394f091b56009a8cb07 Mon Sep 17 00:00:00 2001 From: UserX Date: Thu, 21 Dec 2023 13:36:42 +0200 Subject: [PATCH 1/5] fix StartClientAsync --- IoTGateway.sln | 11 + IoTGateway/IoTGateway.csproj.user | 2 +- .../PublishProfiles/FolderProfile.pubxml.user | 4 +- IoTGateway/iotgateway.db | Bin 319488 -> 319488 bytes .../Drivers/CNC.Fanuc.H/CNC.Fanuc.H.csproj | 2 +- Plugins/Drivers/PLC.LS/DeviceXGB.cs | 741 ++++++++++++++++++ Plugins/Drivers/PLC.LS/PLC.LSIS.csproj | 18 + Plugins/Plugin/MyMqttClient.cs | 62 +- 8 files changed, 835 insertions(+), 5 deletions(-) create mode 100644 Plugins/Drivers/PLC.LS/DeviceXGB.cs create mode 100644 Plugins/Drivers/PLC.LS/PLC.LSIS.csproj diff --git a/IoTGateway.sln b/IoTGateway.sln index 9ba8878..353f924 100644 --- a/IoTGateway.sln +++ b/IoTGateway.sln @@ -65,6 +65,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Mock", "Mock", "{87954B15-5 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mock.TcpClient", "Plugins\Drivers\Mock.TcpClient\Mock.TcpClient.csproj", "{1DE34C11-5461-442B-8C67-FCB0247C09D3}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PLC.LSIS", "Plugins\Drivers\PLC.LS\PLC.LSIS.csproj", "{D3043673-283C-45D7-8F86-6BAAD89AF761}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -241,6 +243,14 @@ Global {1DE34C11-5461-442B-8C67-FCB0247C09D3}.Release|Any CPU.Build.0 = Release|Any CPU {1DE34C11-5461-442B-8C67-FCB0247C09D3}.Release|x86.ActiveCfg = Release|Any CPU {1DE34C11-5461-442B-8C67-FCB0247C09D3}.Release|x86.Build.0 = Release|Any CPU + {D3043673-283C-45D7-8F86-6BAAD89AF761}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D3043673-283C-45D7-8F86-6BAAD89AF761}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D3043673-283C-45D7-8F86-6BAAD89AF761}.Debug|x86.ActiveCfg = Debug|Any CPU + {D3043673-283C-45D7-8F86-6BAAD89AF761}.Debug|x86.Build.0 = Debug|Any CPU + {D3043673-283C-45D7-8F86-6BAAD89AF761}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D3043673-283C-45D7-8F86-6BAAD89AF761}.Release|Any CPU.Build.0 = Release|Any CPU + {D3043673-283C-45D7-8F86-6BAAD89AF761}.Release|x86.ActiveCfg = Release|Any CPU + {D3043673-283C-45D7-8F86-6BAAD89AF761}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -271,6 +281,7 @@ Global {0C82F208-B9B3-485D-A6DD-9ADC59FBF831} = {F8957F78-9D5D-4905-9EFC-EEEBA3A3A13F} {87954B15-5C35-4454-AFC7-9DCE8066D5A0} = {D05CFF72-D58C-418A-8F52-B06848DAC4F1} {1DE34C11-5461-442B-8C67-FCB0247C09D3} = {87954B15-5C35-4454-AFC7-9DCE8066D5A0} + {D3043673-283C-45D7-8F86-6BAAD89AF761} = {1606D516-3865-4F57-9199-93091CF546F5} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {1F219808-E6E8-4C1D-B846-41F2F7CF20FA} diff --git a/IoTGateway/IoTGateway.csproj.user b/IoTGateway/IoTGateway.csproj.user index 0fe4b33..75a2511 100644 --- a/IoTGateway/IoTGateway.csproj.user +++ b/IoTGateway/IoTGateway.csproj.user @@ -2,7 +2,7 @@ IoTGateway - D:\000000-IIoTGateway\00000-iotgateway\IoTGateway\Properties\PublishProfiles\FolderProfile.pubxml + FolderProfile RazorViewEmptyScaffolder root/Common/MVC/View diff --git a/IoTGateway/Properties/PublishProfiles/FolderProfile.pubxml.user b/IoTGateway/Properties/PublishProfiles/FolderProfile.pubxml.user index 7b6b1c9..666b147 100644 --- a/IoTGateway/Properties/PublishProfiles/FolderProfile.pubxml.user +++ b/IoTGateway/Properties/PublishProfiles/FolderProfile.pubxml.user @@ -4,8 +4,8 @@ https://go.microsoft.com/fwlink/?LinkID=208121. --> - <_PublishTargetUrl>D:\000000-IIoTGateway\00000-iotgateway\IoTGateway\bin\Release\net6.0\publish\ - True|2023-05-06T08:43:37.2780869Z;True|2023-05-06T16:16:53.5825444+08:00;True|2023-05-06T15:23:48.5579380+08:00;True|2023-02-27T11:39:28.6812515+08:00;True|2023-02-20T16:42:44.7526644+08:00;True|2023-02-20T16:12:12.9091659+08:00;True|2023-02-20T09:51:20.5504880+08:00;True|2023-02-20T09:35:31.1757073+08:00;True|2023-01-13T15:48:56.7869969+08:00;True|2022-11-21T15:59:03.8927175+08:00;True|2022-11-21T15:58:06.9464735+08:00;True|2022-11-21T15:57:24.8426888+08:00;True|2022-11-21T15:55:06.1675530+08:00;True|2022-10-20T22:40:01.3534004+08:00;True|2022-08-30T20:02:03.8144013+08:00;True|2022-08-30T19:59:49.6042620+08:00;True|2022-08-30T19:52:02.8823029+08:00;True|2022-08-30T19:36:54.3646619+08:00;True|2022-07-15T22:49:16.0563176+08:00;True|2022-07-15T22:48:07.3189129+08:00;True|2022-07-15T22:44:35.7670375+08:00;True|2022-07-15T22:40:17.0184184+08:00;True|2022-06-09T15:43:47.6180879+08:00;True|2022-06-09T15:42:06.6021355+08:00;False|2022-06-09T15:41:10.3444145+08:00;False|2022-06-09T15:39:22.0048230+08:00;False|2022-06-09T15:37:35.5049088+08:00;True|2022-06-09T15:34:27.8095097+08:00;True|2022-06-09T15:33:30.9577399+08:00;False|2022-06-09T15:29:58.9432537+08:00;False|2022-06-09T15:29:15.9735490+08:00;True|2022-06-09T15:27:02.3333134+08:00;True|2022-06-09T15:18:02.0623963+08:00;True|2022-01-24T23:31:28.3620602+08:00;True|2022-01-24T23:30:03.8991942+08:00;True|2022-01-24T23:23:16.4288882+08:00;True|2021-12-24T19:18:19.0736393+08:00;True|2021-12-24T16:46:49.1192015+08:00;True|2021-12-24T16:23:28.9214784+08:00;True|2021-12-24T15:20:08.6401847+08:00;True|2021-12-17T19:11:07.1655146+08:00;True|2021-12-12T14:11:08.8380502+08:00; + <_PublishTargetUrl>C:\Users\UserX\RiderProjects\iotgateway1\IoTGateway\bin\Release\net6.0\publish\ + True|2023-12-19T20:21:26.6090666Z;True|2023-05-06T10:43:37.2780869+02:00;True|2023-05-06T10:16:53.5825444+02:00;True|2023-05-06T09:23:48.5579380+02:00;True|2023-02-27T05:39:28.6812515+02:00;True|2023-02-20T10:42:44.7526644+02:00;True|2023-02-20T10:12:12.9091659+02:00;True|2023-02-20T03:51:20.5504880+02:00;True|2023-02-20T03:35:31.1757073+02:00;True|2023-01-13T09:48:56.7869969+02:00;True|2022-11-21T09:59:03.8927175+02:00;True|2022-11-21T09:58:06.9464735+02:00;True|2022-11-21T09:57:24.8426888+02:00;True|2022-11-21T09:55:06.1675530+02:00;True|2022-10-20T16:40:01.3534004+02:00;True|2022-08-30T14:02:03.8144013+02:00;True|2022-08-30T13:59:49.6042620+02:00;True|2022-08-30T13:52:02.8823029+02:00;True|2022-08-30T13:36:54.3646619+02:00;True|2022-07-15T16:49:16.0563176+02:00;True|2022-07-15T16:48:07.3189129+02:00;True|2022-07-15T16:44:35.7670375+02:00;True|2022-07-15T16:40:17.0184184+02:00;True|2022-06-09T09:43:47.6180879+02:00;True|2022-06-09T09:42:06.6021355+02:00;False|2022-06-09T09:41:10.3444145+02:00;False|2022-06-09T09:39:22.0048230+02:00;False|2022-06-09T09:37:35.5049088+02:00;True|2022-06-09T09:34:27.8095097+02:00;True|2022-06-09T09:33:30.9577399+02:00;False|2022-06-09T09:29:58.9432537+02:00;False|2022-06-09T09:29:15.9735490+02:00;True|2022-06-09T09:27:02.3333134+02:00;True|2022-06-09T09:18:02.0623963+02:00;True|2022-01-24T17:31:28.3620602+02:00;True|2022-01-24T17:30:03.8991942+02:00;True|2022-01-24T17:23:16.4288882+02:00;True|2021-12-24T13:18:19.0736393+02:00;True|2021-12-24T10:46:49.1192015+02:00;True|2021-12-24T10:23:28.9214784+02:00;True|2021-12-24T09:20:08.6401847+02:00;True|2021-12-17T13:11:07.1655146+02:00;True|2021-12-12T08:11:08.8380502+02:00; \ No newline at end of file diff --git a/IoTGateway/iotgateway.db b/IoTGateway/iotgateway.db index ef5a5b99378e112e89299543894d3314637ab069..104db513a19d57e66a03972b3cc02238405c9bb0 100644 GIT binary patch delta 12909 zcmb_i3zQYbneM)~?##V+?gJc#mmxEZjDn=cu739oLHY?Our7Gj2ogpZaBzfCCoxL& zI>~Bsd;o^Titah;iJX&-QP4G;yXGZljpwYJxcFT0t=VYIYLd-vj>*~09`~#2VVnU5 z+U(LZOm+9)Re$~UKfeF3y8b}>^#|H_pIoMrB(1{l3jF47n{UhXp$&Vt&n)I2%~T#K zTv%+DGxxM>&M1T)fbgCWP5 z`12SVWq6k0*sZB*jq1I+t+|%&2#z0Kc-@Qg%wlDWRC%PjziL#rRNJbDDnGC6uHIO^ z2$DRzvS;^B(vybWwlD48+1$NT{+vuqscJqv^_+#(DI?3|a{ZLf%*t{wBbXttWUuU( z=drDK%b)(Z5T&MeQLRR4&7{4iY8bYr3&!%zH}00_O_`mo%#^BoE3a2(mM_Hl$R}%B>A`X4h)hnaDA%h zW!X_3)uyhaIG*DuhUJ=yuX+alvpv@}{m8Z=ETNfW>whHAYmDQE8a2(SQSf8BCKg2S z<7z<^gl4G3X5=b{qx*^%hmaH1o!B&DkJ@o@6ZlwO@5qnm!!*M{^V~>L4QeZf85oKi z`JNIwk#Cu*V|z3_XGJD31Rv{;;KQz&davuM(9wPMx%rO66D-JiEeb6)jBQ1=eG3!x zRmG12U4hNGh91#KjZI8YQ-bY7SJQL*uN*$sOm)3Rjb6jGG)FT$ZYd|2DL6S;?}5pL z*(pNg1&ExlYex2>n0izT6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uc.H/CNC.Fanuc.H.csproj @@ -9,7 +9,7 @@ - + diff --git a/Plugins/Drivers/PLC.LS/DeviceXGB.cs b/Plugins/Drivers/PLC.LS/DeviceXGB.cs new file mode 100644 index 0000000..6ea2b86 --- /dev/null +++ b/Plugins/Drivers/PLC.LS/DeviceXGB.cs @@ -0,0 +1,741 @@ +using HslCommunication; +using HslCommunication.Profinet.LSIS; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json.Linq; +using PluginInterface; +using System.IO.Ports; +using System.Net; + +namespace PLC.LSIS +{ + [DriverSupported("FENet")] + [DriverSupported("CNet")] + [DriverInfo("XGB", "V1.0.0", "Copyright IoTGateway.net 20230220")] + public class DeviceXGB : IDriver + { + public ILogger _logger { get; set; } + private readonly string _device; + + private XGBCnet xGBCnet = null; + private XGBFastEnet fastEnet = null; + + + #region 配置参数 + + [ConfigParameter("设备Id")] public string DeviceId { get; set; } + + [ConfigParameter("PLC类型")] public LSCpuInfo lSCpuInfo { get; set; } = LSCpuInfo.XGB; + + [ConfigParameter("PLC类型")] public LSTypeConnect lSTypeConnect { get; set; } = LSTypeConnect.FENet; + + [ConfigParameter("IP地址")] public string IpAddress { get; set; } = "127.0.0.1"; + + [ConfigParameter("端口号")] public int Port { get; set; } = 2004; + + [ConfigParameter("Slot")] public short Slot { get; set; } = 0; + + [ConfigParameter("串口名")] public string PortName { get; set; } = "COM1"; + + [ConfigParameter("波特率")] public int BaudRate { get; set; } = 9600; + + [ConfigParameter("数据位")] public int DataBits { get; set; } = 8; + + [ConfigParameter("校验位")] public Parity Parity { get; set; } = Parity.None; + + [ConfigParameter("停止位")] public StopBits StopBits { get; set; } = StopBits.One; + + [ConfigParameter("从站号")] public byte Station { get; set; } = 1; + + [ConfigParameter("超时时间ms")] public int Timeout { get; set; } = 3000; + + [ConfigParameter("最小通讯周期ms")] public uint MinPeriod { get; set; } = 3000; + + #endregion + + #region + /// + /// 反射构造函数 + /// + /// + /// + public DeviceXGB(string device, ILogger logger) + { + _device = device; + _logger = logger; + + _logger.LogInformation($"Device:[{_device}],Create()"); + } + + public bool IsConnected { get; set; } + + public bool Connect() + { + try + { + _logger.LogInformation($"Device:[{_device}],Connect()"); + if (!IsConnected) + { + switch (lSTypeConnect) + { + case LSTypeConnect.FENet: + if (fastEnet == null || !IsConnected) + { + fastEnet = new XGBFastEnet(IpAddress, Port); + IsConnected = fastEnet.ConnectServer().IsSuccess; + } + break; + case LSTypeConnect.CNet: + if (xGBCnet == null || !IsConnected) + { + xGBCnet = new XGBCnet + { + Station = Station + }; + xGBCnet.SerialPortInni(sp => + { + sp.PortName = PortName; + sp.BaudRate = BaudRate; + sp.DataBits = DataBits; + sp.StopBits = StopBits; + sp.Parity = Parity; + }); + xGBCnet.Open(); + IsConnected = xGBCnet.IsOpen(); + } + break; + + default: + return IsConnected; + } + + } + else + { + return IsConnected; + } + return IsConnected; + } + catch (Exception ex) + { + _logger.LogError(ex, $"Device:[{_device}],Connect()"); + return IsConnected; + } + } + + public bool Close() + { + try + { + _logger.LogInformation($"Device:[{_device}],Close()"); + switch (lSTypeConnect) + { + case LSTypeConnect.FENet: + if (fastEnet != null) + { + + fastEnet.ConnectClose(); + return !IsConnected; + } + break; + case LSTypeConnect.CNet: + if (xGBCnet != null) + { + xGBCnet.Close(); + + return !IsConnected; + } + break; + + default: + return false; + } + return !IsConnected; + } + catch (Exception ex) + { + _logger.LogError(ex, $"Device:[{_device}],Close()"); + return false; + } + } + + public void Dispose() + { + try + { + _logger?.LogInformation($"Device:[{_device}],Dispose()"); + switch (lSTypeConnect) + { + case LSTypeConnect.FENet: + if (fastEnet != null) + { + + fastEnet.Dispose(); + + } + break; + case LSTypeConnect.CNet: + if (xGBCnet != null) + { + xGBCnet.Dispose(); + + + } + break; + + + + } + + // Suppress finalization. + GC.SuppressFinalize(this); + } + catch (Exception ex) + { + _logger.LogError(ex, $"Device:[{_device}],Dispose()"); + } + + } + [Method("XGB", description: "Read")] + public DriverReturnValueModel Read(DriverAddressIoArgModel ioArg) + { + DriverReturnValueModel ret = new() { StatusType = VaribaleStatusTypeEnum.Good }; + if (!IsConnected) + ret.StatusType = VaribaleStatusTypeEnum.Bad; + else + { + if (ret.StatusType != VaribaleStatusTypeEnum.Good) + return ret; + try + { + + + if (ioArg.ValueType == DataTypeEnum.Bool) + { + + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.ReadBool(ioArg.Address, 1) : xGBCnet.ReadBool(ioArg.Address, 1); + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content[0]); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"读取失败"; + } + return ret; + } + if (ioArg.ValueType == DataTypeEnum.Bit) + { + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.ReadBool(ioArg.Address, 1) : xGBCnet.ReadBool(ioArg.Address, 1); + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content[0]); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"读取失败"; + } + return ret; + } + if (ioArg.ValueType == DataTypeEnum.Byte) + { + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.ReadByte(ioArg.Address) : xGBCnet.ReadByte(ioArg.Address); + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"读取失败"; + } + return ret; + } + if (ioArg.ValueType == DataTypeEnum.Uint16) + { + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.ReadUInt16(ioArg.Address, 1) : xGBCnet.ReadUInt16(ioArg.Address, 1); + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content[0]); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"读取失败"; + } + return ret; + + } + else if (ioArg.ValueType == DataTypeEnum.Int16) + { + + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.ReadInt16(ioArg.Address, 1) : xGBCnet.ReadInt16(ioArg.Address, 1); + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content[0]); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"读取失败"; + } + return ret; + } + else if (ioArg.ValueType == DataTypeEnum.Int32) + { + + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.ReadInt32(ioArg.Address, 1) : xGBCnet.ReadInt32(ioArg.Address, 1); + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content[0]); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"读取失败"; + } + return ret; + } + else if (ioArg.ValueType == DataTypeEnum.Uint32) + { + + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.ReadUInt32(ioArg.Address, 1) : xGBCnet.ReadUInt32(ioArg.Address, 1); + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content[0]); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"读取失败"; + } + return ret; + } + else if (ioArg.ValueType == DataTypeEnum.Int64) + { + + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.ReadInt64(ioArg.Address, 1) : xGBCnet.ReadInt64(ioArg.Address, 1); + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content[0]); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"读取失败"; + } + return ret; + } + else if (ioArg.ValueType == DataTypeEnum.Uint64) + { + + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.ReadUInt64(ioArg.Address, 1) : xGBCnet.ReadUInt64(ioArg.Address, 1); + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content[0]); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"读取失败"; + } + return ret; + } + else if (ioArg.ValueType == DataTypeEnum.Double) + { + + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.ReadDouble(ioArg.Address, 1) : xGBCnet.ReadDouble(ioArg.Address, 1); + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content[0]); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"读取失败"; + } + return ret; + } + else if (ioArg.ValueType == DataTypeEnum.Float) + { + + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.ReadFloat(ioArg.Address, 1) : xGBCnet.ReadFloat(ioArg.Address, 1); + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content[0]); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"读取失败"; + } + return ret; + } + else if (ioArg.ValueType == DataTypeEnum.AsciiString) + { + + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.ReadString(ioArg.Address, 1) : xGBCnet.ReadString(ioArg.Address, 1); + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"读取失败"; + } + return ret; + } + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.UnKnow; + ret.Message = "类型未定义"; + _logger.LogError($"Device:[{_device}],[{ioArg.ValueType}]类型未定义"); + return ret; + } + } + catch (Exception ex) + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = ex.Message; + _logger.LogError(ex, $"Device:[{_device}],ReadRegistersBuffers(),Error"); + } + } + + + return ret; + + } + [Method("XGB", description: "ReadMultiple")] + public DriverReturnValueModel ReadMultiple(DriverAddressIoArgModel ioArg) + { + DriverReturnValueModel ret = new() { StatusType = VaribaleStatusTypeEnum.Good }; + + + + if (!IsConnected) + ret.StatusType = VaribaleStatusTypeEnum.Bad; + else + { + if (ret.StatusType != VaribaleStatusTypeEnum.Good) + return ret; + try + { + string startAddress; + if (ioArg.Address.Contains('|')) + { + startAddress = ioArg.Address.Split('|')[0]; + ioArg.Address = ioArg.Address.Split('|')[1]; + } + var args = ioArg.Address.Split(','); + + startAddress = args[0]; + var length = ushort.Parse(args[1]); + + if (ioArg.ValueType == DataTypeEnum.Bool) + { + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.ReadBool(startAddress, length) : xGBCnet.ReadBool(startAddress, length); + + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"读取失败"; + } + return ret; + } + if (ioArg.ValueType == DataTypeEnum.Bit) + { + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.ReadBool(startAddress, length) : xGBCnet.ReadBool(startAddress, length); + + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"读取失败"; + } + return ret; + } + if (ioArg.ValueType == DataTypeEnum.Byte) + { + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.Read(startAddress, length) : xGBCnet.Read(startAddress, length); + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"读取失败"; + } + return ret; + } + if (ioArg.ValueType == DataTypeEnum.Uint16) + { + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.ReadUInt16(startAddress, length) : xGBCnet.ReadUInt16(startAddress, length); + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"读取失败"; + } + return ret; + + } + else if (ioArg.ValueType == DataTypeEnum.Int16) + { + + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.ReadInt16(startAddress, length) : xGBCnet.ReadInt16(startAddress, length); + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"读取失败"; + } + return ret; + } + else if (ioArg.ValueType == DataTypeEnum.Int32) + { + + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.ReadInt32(startAddress, length) : xGBCnet.ReadInt32(startAddress, length); + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"读取失败"; + } + return ret; + } + else if (ioArg.ValueType == DataTypeEnum.Uint32) + { + + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.ReadUInt32(startAddress, length) : xGBCnet.ReadUInt32(startAddress, length); + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"读取失败"; + } + return ret; + } + else if (ioArg.ValueType == DataTypeEnum.Int64) + { + + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.ReadInt64(startAddress, length) : xGBCnet.ReadInt64(startAddress, length); + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"读取失败"; + } + return ret; + } + else if (ioArg.ValueType == DataTypeEnum.Uint64) + { + + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.ReadUInt64(startAddress, length) : xGBCnet.ReadUInt64(startAddress, length); + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"读取失败"; + } + return ret; + } + else if (ioArg.ValueType == DataTypeEnum.Double) + { + + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.ReadDouble(startAddress, length) : xGBCnet.ReadDouble(startAddress, length); + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"读取失败"; + } + return ret; + } + else if (ioArg.ValueType == DataTypeEnum.Float) + { + + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.ReadFloat(startAddress, length) : xGBCnet.ReadFloat(startAddress, length); + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"读取失败"; + } + return ret; + } + else if (ioArg.ValueType == DataTypeEnum.AsciiString) + { + + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.ReadString(startAddress, length) : xGBCnet.ReadString(startAddress, length); + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"读取失败"; + } + return ret; + } + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.UnKnow; + ret.Message = "类型未定义"; + _logger.LogError($"Device:[{_device}],[{ioArg.ValueType}]类型未定义"); + return ret; + } + } + catch (Exception ex) + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = ex.Message; + _logger.LogError(ex, $"Device:[{_device}],ReadRegistersBuffers(),Error"); + } + } + + + return ret; + + } + [Method("XGB", description: "Write")] + public async Task WriteAsync(string RequestId, string Method, DriverAddressIoArgModel ioArg) + { + RpcResponse rpcResponse = new() { IsSuccess = false }; + try + { + OperateResult writeResult; + if (!IsConnected) + rpcResponse.Description = "设备连接已断开"; + else + { + + + if (ioArg.ValueType == DataTypeEnum.Bool) + { + var value = ioArg.Value.ToString() == "1" || ioArg.Value.ToString().ToLower() == "true"; + writeResult = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.WriteCoil(ioArg.Address, value) : xGBCnet.WriteCoil(ioArg.Address, value); + rpcResponse.IsSuccess = true; + return rpcResponse; + + + } + if (ioArg.ValueType == DataTypeEnum.Bit) + { + var value = ioArg.Value.ToString() == "1" || ioArg.Value.ToString().ToLower() == "true"; + writeResult = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.WriteCoil(ioArg.Address, value) : xGBCnet.WriteCoil(ioArg.Address, value); + rpcResponse.IsSuccess = true; + return rpcResponse; + } + if (ioArg.ValueType == DataTypeEnum.Byte) + { + var value = ioArg.Value.ToString(); + writeResult = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.Write(ioArg.Address, value) : xGBCnet.Write(ioArg.Address, value); + + rpcResponse.IsSuccess = true; + return rpcResponse; + } + if (ioArg.ValueType == DataTypeEnum.Uint16) + { + var value = ushort.Parse(ioArg.Value.ToString()); + writeResult = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.Write(ioArg.Address, value) : xGBCnet.Write(ioArg.Address, value); + rpcResponse.IsSuccess = true; + return rpcResponse; + + } + else if (ioArg.ValueType == DataTypeEnum.Int16) + { + var value = short.Parse(ioArg.Value.ToString()); + writeResult = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.Write(ioArg.Address, value) : xGBCnet.Write(ioArg.Address, value); + rpcResponse.IsSuccess = true; + return rpcResponse; + } + else if (ioArg.ValueType == DataTypeEnum.Int32) + { + + var value = int.Parse(ioArg.Value.ToString()); + writeResult = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.Write(ioArg.Address, value) : xGBCnet.Write(ioArg.Address, value); + rpcResponse.IsSuccess = true; + return rpcResponse; + } + else if (ioArg.ValueType == DataTypeEnum.Uint32) + { + + var value = uint.Parse(ioArg.Value.ToString()); + writeResult = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.Write(ioArg.Address, value) : xGBCnet.Write(ioArg.Address, value); + rpcResponse.IsSuccess = true; + return rpcResponse; + } + else if (ioArg.ValueType == DataTypeEnum.Int64) + { + + var value = long.Parse(ioArg.Value.ToString()); + writeResult = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.Write(ioArg.Address, value) : xGBCnet.Write(ioArg.Address, value); + rpcResponse.IsSuccess = true; + return rpcResponse; + } + else if (ioArg.ValueType == DataTypeEnum.Uint64) + { + + var value = ulong.Parse(ioArg.Value.ToString()); + writeResult = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.Write(ioArg.Address, value) : xGBCnet.Write(ioArg.Address, value); + rpcResponse.IsSuccess = true; + return rpcResponse; + } + else if (ioArg.ValueType == DataTypeEnum.Double) + { + + var value = double.Parse(ioArg.Value.ToString()); + writeResult = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.Write(ioArg.Address, value) : xGBCnet.Write(ioArg.Address, value); + rpcResponse.IsSuccess = true; + return rpcResponse; + } + else if (ioArg.ValueType == DataTypeEnum.Float) + { + + var value = float.Parse(ioArg.Value.ToString()); + writeResult = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.Write(ioArg.Address, value) : xGBCnet.Write(ioArg.Address, value); + rpcResponse.IsSuccess = true; + return rpcResponse; + } + + + + + rpcResponse.Description = $"不支持写入:{Method}"; + } + } + catch (Exception ex) + { + IsConnected = false; + rpcResponse.Description = $"写入失败,[method]:{Method},[ioArg]:{ioArg},[ex]:{ex}"; + _logger.LogError(ex, $"Device:[{_device}],WriteAsync(),Error"); + } + + return rpcResponse; + } + #endregion + + } + + public enum LSTypeConnect + { + CNet = 0, + FENet = 1, + + } +} diff --git a/Plugins/Drivers/PLC.LS/PLC.LSIS.csproj b/Plugins/Drivers/PLC.LS/PLC.LSIS.csproj new file mode 100644 index 0000000..09e2dee --- /dev/null +++ b/Plugins/Drivers/PLC.LS/PLC.LSIS.csproj @@ -0,0 +1,18 @@ + + + + net6.0 + ../../../IoTGateway/bin/Debug/net6.0/drivers + enable + enable + + + + + + + + + + + diff --git a/Plugins/Plugin/MyMqttClient.cs b/Plugins/Plugin/MyMqttClient.cs index 75a4ccf..9aabde0 100644 --- a/Plugins/Plugin/MyMqttClient.cs +++ b/Plugins/Plugin/MyMqttClient.cs @@ -32,7 +32,7 @@ namespace Plugin _logger = logger; //_uaNodeManager = uaService.server.m_server.nodeManagers[0] as ReferenceNodeManager; - StartClientAsync().Wait(); + //StartClientAsync().Wait(); } public async Task StartClientAsync() @@ -76,6 +76,10 @@ namespace Plugin private async Task Client_ConnectedAsync(MqttClientConnectedEventArgs arg) { + if (Client == null) + { + StartClientAsync().Wait(); + } _logger.LogInformation($"MQTT CONNECTED WITH SERVER "); #region Topics try @@ -123,6 +127,10 @@ namespace Plugin private async Task Client_DisconnectedAsync(MqttClientDisconnectedEventArgs arg) { + if (Client == null) + { + StartClientAsync().Wait(); + } try { _logger.LogError($"MQTT DISCONNECTED WITH SERVER "); @@ -256,6 +264,10 @@ namespace Plugin private async Task ResponseTbRpcAsync(TBRpcResponse tBRpcResponse) { + if (Client == null) + { + StartClientAsync().Wait(); + } await Client.PublishAsync(new MqttApplicationMessageBuilder() .WithTopic(_tbRpcTopic) .WithPayload(JsonConvert.SerializeObject(tBRpcResponse)) @@ -264,6 +276,10 @@ namespace Plugin private async Task ResponseTcRpcAsync(TCRpcRequest tCRpcResponse) { + if (Client == null) + { + StartClientAsync().Wait(); + } var topic = $"command/reply/{tCRpcResponse.RequestData.RequestId}"; await Client.PublishAsync(new MqttApplicationMessageBuilder() .WithTopic(topic) @@ -273,6 +289,10 @@ namespace Plugin private async Task ResponseIsRpcAsync(ISRpcResponse rpcResult) { + if (Client == null) + { + StartClientAsync().Wait(); + } //var responseTopic = $"/devices/{deviceid}/rpc/response/{methodName}/{rpcid}"; var topic = $"devices/{rpcResult.DeviceId}/rpc/response/{rpcResult.Method}/{rpcResult.ResponseId}"; await Client.PublishAsync(new MqttApplicationMessageBuilder() @@ -313,6 +333,10 @@ namespace Plugin //Message: {"Device A":{"attribute1":"value1", "attribute2": 42}, "Device B":{"attribute1":"value1", "attribute2": 42} try { + if (Client == null) + { + StartClientAsync().Wait(); + } return Client.PublishAsync(new MqttApplicationMessageBuilder() .WithTopic($"devices/{deviceName}/attributes").WithPayload(JsonConvert.SerializeObject(obj)) .WithQualityOfServiceLevel(MqttQualityOfServiceLevel.AtMostOnce) @@ -328,12 +352,20 @@ namespace Plugin public async Task UploadIsTelemetryDataAsync(string deviceName, object obj) { + if (Client == null) + { + StartClientAsync().Wait(); + } await Client.PublishAsync(new MqttApplicationMessageBuilder().WithTopic($"devices/{deviceName}/telemetry") .WithPayload(JsonConvert.SerializeObject(obj)).Build()); } public async Task UploadTcTelemetryDataAsync(string deviceName, object obj) { + if (Client == null) + { + StartClientAsync().Wait(); + } var toSend = new Dictionary { { deviceName, obj } }; await Client.PublishAsync(new MqttApplicationMessageBuilder().WithTopic($"gateway/attributes") .WithPayload(JsonConvert.SerializeObject(toSend)).WithQualityOfServiceLevel(MqttQualityOfServiceLevel.ExactlyOnce).Build()); @@ -361,6 +393,10 @@ namespace Plugin { Devices = hwTelemetry }; + if (Client == null) + { + StartClientAsync().Wait(); + } await Client.PublishAsync(new MqttApplicationMessageBuilder().WithTopic($"/v1/devices/{_systemConfig.GatewayName}/datas") .WithPayload(JsonConvert.SerializeObject(hwTelemetrys)).WithQualityOfServiceLevel(MqttQualityOfServiceLevel.ExactlyOnce).Build()); @@ -418,6 +454,10 @@ namespace Plugin { try { + if (Client == null) + { + StartClientAsync().Wait(); + } string id = Guid.NewGuid().ToString(); switch (_systemConfig.IoTPlatformType) { @@ -512,6 +552,10 @@ namespace Plugin { try { + if (Client == null) + { + StartClientAsync().Wait(); + } if (CanPubTelemetry(deviceName, device, sendModel)) { switch (_systemConfig.IoTPlatformType) @@ -583,6 +627,10 @@ namespace Plugin { try { + if (Client == null) + { + StartClientAsync().Wait(); + } switch (_systemConfig.IoTPlatformType) { case IoTPlatformType.ThingsBoard: @@ -638,6 +686,10 @@ namespace Plugin { try { + if (Client == null) + { + StartClientAsync().Wait(); + } switch (_systemConfig.IoTPlatformType) { case IoTPlatformType.ThingsBoard: @@ -693,6 +745,10 @@ namespace Plugin { try { + if (Client == null) + { + StartClientAsync().Wait(); + } switch (_systemConfig.IoTPlatformType) { case IoTPlatformType.HuaWei: @@ -728,6 +784,10 @@ namespace Plugin { try { + if (Client == null) + { + StartClientAsync().Wait(); + } switch (_systemConfig.IoTPlatformType) { case IoTPlatformType.HuaWei: From 28c58d9700d8c8a9d6e84a8854a6bf5fb5311acd Mon Sep 17 00:00:00 2001 From: UserX Date: Thu, 21 Dec 2023 22:38:54 +0200 Subject: [PATCH 2/5] fix mqtt --- Plugins/Plugin/MyMqttClient.cs | 62 +--------------------------------- 1 file changed, 1 insertion(+), 61 deletions(-) diff --git a/Plugins/Plugin/MyMqttClient.cs b/Plugins/Plugin/MyMqttClient.cs index 9aabde0..75a4ccf 100644 --- a/Plugins/Plugin/MyMqttClient.cs +++ b/Plugins/Plugin/MyMqttClient.cs @@ -32,7 +32,7 @@ namespace Plugin _logger = logger; //_uaNodeManager = uaService.server.m_server.nodeManagers[0] as ReferenceNodeManager; - //StartClientAsync().Wait(); + StartClientAsync().Wait(); } public async Task StartClientAsync() @@ -76,10 +76,6 @@ namespace Plugin private async Task Client_ConnectedAsync(MqttClientConnectedEventArgs arg) { - if (Client == null) - { - StartClientAsync().Wait(); - } _logger.LogInformation($"MQTT CONNECTED WITH SERVER "); #region Topics try @@ -127,10 +123,6 @@ namespace Plugin private async Task Client_DisconnectedAsync(MqttClientDisconnectedEventArgs arg) { - if (Client == null) - { - StartClientAsync().Wait(); - } try { _logger.LogError($"MQTT DISCONNECTED WITH SERVER "); @@ -264,10 +256,6 @@ namespace Plugin private async Task ResponseTbRpcAsync(TBRpcResponse tBRpcResponse) { - if (Client == null) - { - StartClientAsync().Wait(); - } await Client.PublishAsync(new MqttApplicationMessageBuilder() .WithTopic(_tbRpcTopic) .WithPayload(JsonConvert.SerializeObject(tBRpcResponse)) @@ -276,10 +264,6 @@ namespace Plugin private async Task ResponseTcRpcAsync(TCRpcRequest tCRpcResponse) { - if (Client == null) - { - StartClientAsync().Wait(); - } var topic = $"command/reply/{tCRpcResponse.RequestData.RequestId}"; await Client.PublishAsync(new MqttApplicationMessageBuilder() .WithTopic(topic) @@ -289,10 +273,6 @@ namespace Plugin private async Task ResponseIsRpcAsync(ISRpcResponse rpcResult) { - if (Client == null) - { - StartClientAsync().Wait(); - } //var responseTopic = $"/devices/{deviceid}/rpc/response/{methodName}/{rpcid}"; var topic = $"devices/{rpcResult.DeviceId}/rpc/response/{rpcResult.Method}/{rpcResult.ResponseId}"; await Client.PublishAsync(new MqttApplicationMessageBuilder() @@ -333,10 +313,6 @@ namespace Plugin //Message: {"Device A":{"attribute1":"value1", "attribute2": 42}, "Device B":{"attribute1":"value1", "attribute2": 42} try { - if (Client == null) - { - StartClientAsync().Wait(); - } return Client.PublishAsync(new MqttApplicationMessageBuilder() .WithTopic($"devices/{deviceName}/attributes").WithPayload(JsonConvert.SerializeObject(obj)) .WithQualityOfServiceLevel(MqttQualityOfServiceLevel.AtMostOnce) @@ -352,20 +328,12 @@ namespace Plugin public async Task UploadIsTelemetryDataAsync(string deviceName, object obj) { - if (Client == null) - { - StartClientAsync().Wait(); - } await Client.PublishAsync(new MqttApplicationMessageBuilder().WithTopic($"devices/{deviceName}/telemetry") .WithPayload(JsonConvert.SerializeObject(obj)).Build()); } public async Task UploadTcTelemetryDataAsync(string deviceName, object obj) { - if (Client == null) - { - StartClientAsync().Wait(); - } var toSend = new Dictionary { { deviceName, obj } }; await Client.PublishAsync(new MqttApplicationMessageBuilder().WithTopic($"gateway/attributes") .WithPayload(JsonConvert.SerializeObject(toSend)).WithQualityOfServiceLevel(MqttQualityOfServiceLevel.ExactlyOnce).Build()); @@ -393,10 +361,6 @@ namespace Plugin { Devices = hwTelemetry }; - if (Client == null) - { - StartClientAsync().Wait(); - } await Client.PublishAsync(new MqttApplicationMessageBuilder().WithTopic($"/v1/devices/{_systemConfig.GatewayName}/datas") .WithPayload(JsonConvert.SerializeObject(hwTelemetrys)).WithQualityOfServiceLevel(MqttQualityOfServiceLevel.ExactlyOnce).Build()); @@ -454,10 +418,6 @@ namespace Plugin { try { - if (Client == null) - { - StartClientAsync().Wait(); - } string id = Guid.NewGuid().ToString(); switch (_systemConfig.IoTPlatformType) { @@ -552,10 +512,6 @@ namespace Plugin { try { - if (Client == null) - { - StartClientAsync().Wait(); - } if (CanPubTelemetry(deviceName, device, sendModel)) { switch (_systemConfig.IoTPlatformType) @@ -627,10 +583,6 @@ namespace Plugin { try { - if (Client == null) - { - StartClientAsync().Wait(); - } switch (_systemConfig.IoTPlatformType) { case IoTPlatformType.ThingsBoard: @@ -686,10 +638,6 @@ namespace Plugin { try { - if (Client == null) - { - StartClientAsync().Wait(); - } switch (_systemConfig.IoTPlatformType) { case IoTPlatformType.ThingsBoard: @@ -745,10 +693,6 @@ namespace Plugin { try { - if (Client == null) - { - StartClientAsync().Wait(); - } switch (_systemConfig.IoTPlatformType) { case IoTPlatformType.HuaWei: @@ -784,10 +728,6 @@ namespace Plugin { try { - if (Client == null) - { - StartClientAsync().Wait(); - } switch (_systemConfig.IoTPlatformType) { case IoTPlatformType.HuaWei: From c09dc77fdd5b0c13b6da6f51e5430101084a92eb Mon Sep 17 00:00:00 2001 From: UserX Date: Sat, 23 Dec 2023 11:34:58 +0200 Subject: [PATCH 3/5] Translate IoTGateway.Model --- IoTGateway.Model/Common.cs | 12 +++++----- IoTGateway.Model/Device.cs | 26 +++++++++++----------- IoTGateway.Model/DeviceConfig.cs | 12 +++++----- IoTGateway.Model/DeviceVariable.cs | 34 ++++++++++++++--------------- IoTGateway.Model/Driver.cs | 8 +++---- IoTGateway.Model/IVariable.cs | 12 +++++----- IoTGateway.Model/RpcLog.cs | 20 ++++++++--------- IoTGateway.Model/SystemConfig.cs | 20 ++++++++--------- IoTGateway/iotgateway.db | Bin 319488 -> 319488 bytes 9 files changed, 72 insertions(+), 72 deletions(-) diff --git a/IoTGateway.Model/Common.cs b/IoTGateway.Model/Common.cs index 10596fa..06d8265 100644 --- a/IoTGateway.Model/Common.cs +++ b/IoTGateway.Model/Common.cs @@ -4,26 +4,26 @@ namespace IoTGateway.Model { public enum DeviceTypeEnum { - [Display(Name = "采集组")] + [Display(Name = "Collection Group")] Group = 0, - [Display(Name = "采集点")] + [Display(Name = "Collection Device")] Device = 1 } public enum AccessEnum { - [Display(Name = "只读")] + [Display(Name = "Read Only")] ReadOnly = 0, - [Display(Name = "读写")] + [Display(Name = "Read and write")] ReadAndWrite = 1 } public enum DataSide { - [Display(Name ="共享属性")] + [Display(Name = "Shared Properties")] AnySide=0, //ServerSide=1, - [Display(Name = "客户端属性")] + [Display(Name = "Client Properties")] ClientSide =2, } } \ No newline at end of file diff --git a/IoTGateway.Model/Device.cs b/IoTGateway.Model/Device.cs index 7c7eb46..4b2e98a 100644 --- a/IoTGateway.Model/Device.cs +++ b/IoTGateway.Model/Device.cs @@ -7,41 +7,41 @@ namespace IoTGateway.Model { public class Device : TreePoco, IBasePoco { - [Display(Name = "名称")] + [Display(Name = "Name")] public string DeviceName { get; set; } - [Display(Name = "排序")] + [Display(Name = "sort")] public uint Index { get; set; } - [Display(Name = "描述")] + [Display(Name = "describe")] public string Description { get; set; } public Driver Driver { get; set; } - [Display(Name = "驱动")] + [Display(Name = "drive")] public Guid? DriverId { get; set; } - [Display(Name = "启动")] + [Display(Name = "start up")] public bool AutoStart { get; set; } - [Display(Name = "变化上传")] + [Display(Name = "Change upload")] public bool CgUpload { get; set; } - [Display(Name = "归档周期ms")] + [Display(Name = "Archiving cycle ms")] public uint EnforcePeriod { get; set; } - [Display(Name = "指令间隔ms")] + [Display(Name = "Command interval ms")] public uint CmdPeriod { get; set; } - [Display(Name = "类型")] + [Display(Name = "Type")] public DeviceTypeEnum DeviceTypeEnum { get; set; } - [Display(Name = "创建时间")] + [Display(Name = "Creation time")] public DateTime? CreateTime { get; set; } - [Display(Name = "创建人")] + [Display(Name = "Founder")] public string CreateBy { get; set; } - [Display(Name = "更新时间")] + [Display(Name = "Update time")] public DateTime? UpdateTime { get; set; } - [Display(Name = "更新人")] + [Display(Name = "updater")] public string UpdateBy { get; set; } public List DeviceConfigs { get; set; } diff --git a/IoTGateway.Model/DeviceConfig.cs b/IoTGateway.Model/DeviceConfig.cs index b6cbf83..f2acdbb 100644 --- a/IoTGateway.Model/DeviceConfig.cs +++ b/IoTGateway.Model/DeviceConfig.cs @@ -6,18 +6,18 @@ namespace IoTGateway.Model { public class DeviceConfig : BasePoco { - [Display(Name = "名称")] + [Display(Name = "Name")] public string DeviceConfigName { get; set; } - [Display(Name = "属性侧")] + [Display(Name = "attribute side")] public DataSide DataSide { get; set; } - [Display(Name = "描述")] + [Display(Name = "Description")] public string Description { get; set; } - [Display(Name = "值")] + [Display(Name = "Value")] public string Value { get; set; } - [Display(Name = "备注")] + [Display(Name = "Remark")] public string EnumInfo { get; set; } public Device Device { get; set; } - [Display(Name = "设备")] + [Display(Name = "ID")] public Guid? DeviceId { get; set; } } } diff --git a/IoTGateway.Model/DeviceVariable.cs b/IoTGateway.Model/DeviceVariable.cs index c04add9..46eefdb 100644 --- a/IoTGateway.Model/DeviceVariable.cs +++ b/IoTGateway.Model/DeviceVariable.cs @@ -10,61 +10,61 @@ namespace IoTGateway.Model { public class DeviceVariable : TopBasePoco, IVariable { - [Display(Name = "变量名")] + [Display(Name = "Tag Name")] public string Name { get; set; } - [Display(Name = "描述")] + [Display(Name = "Description")] public string Description { get; set; } - [Display(Name = "方法")] + [Display(Name = "Method")] public string Method { get; set; } - [Display(Name = "地址")] + [Display(Name = "Address")] public string DeviceAddress { get; set; } - [Display(Name = "类型")] + [Display(Name = "DataType")] public DataTypeEnum DataType { get; set; } - [Display(Name = "大小端")] + [Display(Name = "EndianType")] public EndianEnum EndianType { get; set; } - [Display(Name = "表达式")] + [Display(Name = "Expressions")] public string Expressions { get; set; } - [Display(Name = "上传")] + [Display(Name = "Upload")] public bool IsUpload { get; set; } - [Display(Name = "权限")] + [Display(Name = "Permissions")] public ProtectTypeEnum ProtectType { get; set; } - [Display(Name = "排序")] + [Display(Name = "sort")] public uint Index { get; set; } [Newtonsoft.Json.JsonIgnore] public Device Device { get; set; } - [Display(Name = "设备")] + [Display(Name = "ID")] public Guid? DeviceId { get; set; } - [Display(Name = "别名")] + [Display(Name = "Alias")] public string Alias { get; set; } [NotMapped] - [Display(Name = "原值")] + [Display(Name = "Value")] public object Value { get; set; } [NotMapped] - [Display(Name = "值")] + [Display(Name = "CookedValue")] public object CookedValue { get; set; } [NotMapped] public string Message { get; set; } [NotMapped] - [Display(Name = "更新时间")] + [Display(Name = "Update time")] public DateTime Timestamp { get; set; } [NotMapped] - [Display(Name = "状态")] + [Display(Name = "State")] [JsonConverter(typeof(StringEnumConverter))] public VaribaleStatusTypeEnum StatusType { get; set; } = VaribaleStatusTypeEnum.UnKnow; - [NotMapped][Display(Name = "最近几次的值")] public object[] Values { get; set; } = new object[3]; + [NotMapped][Display(Name = "The Most Recent Values")] public object[] Values { get; set; } = new object[3]; public void EnqueueVariable(object value) { Values[2] = Values[1]; diff --git a/IoTGateway.Model/Driver.cs b/IoTGateway.Model/Driver.cs index 1d6e06a..9271c5b 100644 --- a/IoTGateway.Model/Driver.cs +++ b/IoTGateway.Model/Driver.cs @@ -6,13 +6,13 @@ namespace IoTGateway.Model { public class Driver : BasePoco { - [Display(Name = "驱动名")] + [Display(Name = "Name")] public string DriverName { get; set; } - [Display(Name = "文件名")] + [Display(Name = "FileName")] public string FileName { get; set; } - [Display(Name = "程序集名")] + [Display(Name = "AssembleName")] public string AssembleName { get; set; } - [Display(Name = "剩余授权数量")] + [Display(Name = "Number of licenses remaining")] public int AuthorizesNum { get; set; } } } \ No newline at end of file diff --git a/IoTGateway.Model/IVariable.cs b/IoTGateway.Model/IVariable.cs index b69920f..8e7cc14 100644 --- a/IoTGateway.Model/IVariable.cs +++ b/IoTGateway.Model/IVariable.cs @@ -5,22 +5,22 @@ namespace IoTGateway.Model { public interface IVariable { - [Display(Name = "变量名")] + [Display(Name = "Variable Name")] public string Name { get; set; } - [Display(Name = "描述")] + [Display(Name = "Description")] public string Description { get; set; } - [Display(Name = "地址")] + [Display(Name = "Address")] public string DeviceAddress { get; set; } - [Display(Name = "数据类型")] + [Display(Name = "DataType")] public PluginInterface.DataTypeEnum DataType { get; set; } - [Display(Name = "表达式")] + [Display(Name = "Expressions")] public string Expressions { get; set; } - [Display(Name = "权限")] + [Display(Name = "Permissions")] public ProtectTypeEnum ProtectType { get; set; } } } \ No newline at end of file diff --git a/IoTGateway.Model/RpcLog.cs b/IoTGateway.Model/RpcLog.cs index 1a09f40..9406ac2 100644 --- a/IoTGateway.Model/RpcLog.cs +++ b/IoTGateway.Model/RpcLog.cs @@ -10,38 +10,38 @@ namespace IoTGateway.Model { public class RpcLog:TopBasePoco { - [Display(Name = "发起方")] + [Display(Name = "Initiator")] public RpcSide RpcSide { get; set; } - [Display(Name = "开始时间")] + [Display(Name = "Starting Time")] public DateTime StartTime { get; set; } public Device Device { get; set; } - [Display(Name = "设备名")] + [Display(Name = "ID")] public Guid? DeviceId { get; set; } - [Display(Name = "方法名")] + [Display(Name = "Method")] public string Method { get; set; } - [Display(Name = "请求参数")] + [Display(Name = "Request Parameters")] public string Params { get; set; } - [Display(Name = "结束时间")] + [Display(Name = "End Time")] public DateTime EndTime { get; set; } - [Display(Name = "结果")] + [Display(Name = "Result")] public bool IsSuccess { get; set; } - [Display(Name = "描述")] + [Display(Name = "Description")] public string Description { get; set; } } public enum RpcSide { - [Display(Name ="服务端请求")] + [Display(Name = "Server Request")] ServerSide=1, - [Display(Name = "客户端请求")] + [Display(Name = "Client Request")] ClientSide =1 } } diff --git a/IoTGateway.Model/SystemConfig.cs b/IoTGateway.Model/SystemConfig.cs index 1fdfe7b..8ce666f 100644 --- a/IoTGateway.Model/SystemConfig.cs +++ b/IoTGateway.Model/SystemConfig.cs @@ -5,19 +5,19 @@ namespace IoTGateway.Model { public class SystemConfig : BasePoco { - [Display(Name = "网关名称")] + [Display(Name = "Gateway Name")] public string GatewayName { get; set; } [Display(Name = "ClientId")] public string ClientId { get; set; } - [Display(Name = "Mqtt服务器")] + [Display(Name = "Mqtt Server ")] public string MqttIp { get; set; } - [Display(Name = "Mqtt端口")] + [Display(Name = "Mqtt Port")] public int MqttPort { get; set; } - [Display(Name = "Mqtt用户名")] + [Display(Name = "Mqtt UserName")] public string MqttUName { get; set; } - [Display(Name = "Mqtt密码")] + [Display(Name = "Mqtt Password")] public string MqttUPwd { get; set; } - [Display(Name = "输出平台")] + [Display(Name = "Output platform")] public IoTPlatformType IoTPlatformType { get; set; } } public enum IoTPlatformType @@ -26,17 +26,17 @@ namespace IoTGateway.Model ThingsBoard =0, [Display(Name = "IoTSharp")] IoTSharp =1, - [Display(Name = "阿里物联网平台")] + [Display(Name = "Alibaba Internet of Things Platform")] AliCloudIoT=2, - [Display(Name = "腾讯智能云")] + [Display(Name = "Tencent Intelligent Cloud")] TencentIoTHub =3, - [Display(Name = "百度物联网通信")] + [Display(Name = "Baidu Internet of Things Communication")] BaiduIoTCore =4, [Display(Name = "中移OneNet")] OneNET = 5, [Display(Name = "ThingsCloud")] ThingsCloud = 6, - [Display(Name = "华为云")] + [Display(Name = "Huawei Cloud")] HuaWei = 7, [Display(Name = "IoTGateway")] IoTGateway = 8 diff --git a/IoTGateway/iotgateway.db b/IoTGateway/iotgateway.db index 104db513a19d57e66a03972b3cc02238405c9bb0..26647696ad7b65d06856e967d64f2612d37364eb 100644 GIT binary patch delta 778 zcmb7?KaUbY7{+IZ@z_On2jTV*Eg;B+7_;2&>>pq6N!EUuad&XEA0FN+PHuTh0U2v_s;X1=a+d0pAv)MyyFf= z2|c5!C6km0DVSPOQw^=netzW6`CmtzdOZa313waj+c*aHLR{37(+S`KP)YLa+X~FF zS82E!Co_mqB1XZoY@1O3cNz+rcvw0D_!c(sNj%1H@V<29FO}gJiT&7u=h^N(nDg}p zJS;D8xC3y7=HRYQ@$aLN&)S ziAr=uBg&+QR#MfHY7{83OpCD3GF(>f_cr@?9%k3uT`gP6Qks4APeQi})YO9r-5Y;cN`jvw9u~*hsS<+10CX(e8>}yvmTRIr>UJFg(fNXG!Anw2WaCD D7>TpU delta 605 zcmZvZPiPZC6o+RguiM=;vlAOvTM!ar0tMZ4cV@C?Ll23GIYnE=J(MD8`Ug=eRS~49 z5HCG=Dhkd`5vdl4S*GQaN|-g~{bnVzbb+Ot8% z%`vyCO8BJ;t1!kzSN?pX9gjW_H1~W$qZ?5&jn^r?4_Yd;vl$d3)HrI$uhY07Uu5x& z+&YGJ!h>qLTnfr=z+4gi$zn4%uG29@FHu3q=pNmso92(`NDY6qA4naf7H*11qI(SO_Iv%k~c31@aeNl^=FsDZQ*)p++(xv28;$h$(3Y3UcWzJcTY; zp&U5}&Br#*Ok7y)uBea2S|SE$NF3WRV&H)Su*rwh$bK8rhgFOtgci&=ro1YqwjF!F zP2%FA#`>~mg{Hm#D8F=|C>LhIqiguUZW=_sZ$l@QRI=eE_Nb879Gr+w&B3-M$v`QS z9r&G4%a2AEVV6#;=v33=<;EGm<%p&bj;NomI6=#=JFV8iU1H~ux~?dQso?<6d$9Nq DLH~{P From 2109fd644a72e8c9180aa5d6cac79c536819d33a Mon Sep 17 00:00:00 2001 From: UserX Date: Sat, 23 Dec 2023 13:23:22 +0200 Subject: [PATCH 4/5] Translate IoTGateway --- IoTGateway.Model/Device.cs | 12 ++++++------ IoTGateway.Model/DeviceVariable.cs | 2 +- Plugins/PluginInterface/DataTypeEnum.cs | 12 ++++++------ Plugins/PluginInterface/EndianEnum.cs | 10 +++++----- Plugins/PluginInterface/ProtectTypeEnum.cs | 6 +++--- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/IoTGateway.Model/Device.cs b/IoTGateway.Model/Device.cs index 4b2e98a..8795544 100644 --- a/IoTGateway.Model/Device.cs +++ b/IoTGateway.Model/Device.cs @@ -7,20 +7,20 @@ namespace IoTGateway.Model { public class Device : TreePoco, IBasePoco { - [Display(Name = "Name")] + [Display(Name = "Device Name")] public string DeviceName { get; set; } - [Display(Name = "sort")] + [Display(Name = "Sort")] public uint Index { get; set; } - [Display(Name = "describe")] + [Display(Name = "Description")] public string Description { get; set; } public Driver Driver { get; set; } - [Display(Name = "drive")] + [Display(Name = "Device PLC")] public Guid? DriverId { get; set; } - [Display(Name = "start up")] + [Display(Name = "Start up")] public bool AutoStart { get; set; } [Display(Name = "Change upload")] @@ -32,7 +32,7 @@ namespace IoTGateway.Model [Display(Name = "Command interval ms")] public uint CmdPeriod { get; set; } - [Display(Name = "Type")] + [Display(Name = "Device Type")] public DeviceTypeEnum DeviceTypeEnum { get; set; } [Display(Name = "Creation time")] diff --git a/IoTGateway.Model/DeviceVariable.cs b/IoTGateway.Model/DeviceVariable.cs index 46eefdb..a619aec 100644 --- a/IoTGateway.Model/DeviceVariable.cs +++ b/IoTGateway.Model/DeviceVariable.cs @@ -42,7 +42,7 @@ namespace IoTGateway.Model [Newtonsoft.Json.JsonIgnore] public Device Device { get; set; } - [Display(Name = "ID")] + [Display(Name = "Device Name")] public Guid? DeviceId { get; set; } [Display(Name = "Alias")] diff --git a/Plugins/PluginInterface/DataTypeEnum.cs b/Plugins/PluginInterface/DataTypeEnum.cs index 309ff24..4875ec4 100644 --- a/Plugins/PluginInterface/DataTypeEnum.cs +++ b/Plugins/PluginInterface/DataTypeEnum.cs @@ -47,17 +47,17 @@ namespace PluginInterface TimeStampMs, [Display(Name = "timestamp(s)")] TimeStampS, - [Display(Name = "任意类型")] + [Display(Name = "Any")] Any, - [Display(Name = "自定义1")] + [Display(Name = "Custom 1")] Custome1, - [Display(Name = "自定义2")] + [Display(Name = "Custom 2")] Custome2, - [Display(Name = "自定义3")] + [Display(Name = "Custom 3")] Custome3, - [Display(Name = "自定义4")] + [Display(Name = "Custom4")] Custome4, - [Display(Name = "自定义5")] + [Display(Name = "Custom 5")] Custome5, [Display(Name = "Gb2312")] Gb2312String, diff --git a/Plugins/PluginInterface/EndianEnum.cs b/Plugins/PluginInterface/EndianEnum.cs index 99c95ce..38e334d 100644 --- a/Plugins/PluginInterface/EndianEnum.cs +++ b/Plugins/PluginInterface/EndianEnum.cs @@ -10,10 +10,10 @@ namespace PluginInterface { public enum EndianEnum { - [Display(Name = "无")] None = 0, - [Display(Name = "大端")] BigEndian, - [Display(Name = "小端")] LittleEndian, - [Display(Name = "大端交换")] BigEndianSwap, - [Display(Name = "小端交换")] LittleEndianSwap + [Display(Name = "None")] None = 0, + [Display(Name = "BigEndian")] BigEndian, + [Display(Name = "LittleEndian")] LittleEndian, + [Display(Name = "BigEndianSwap")] BigEndianSwap, + [Display(Name = "LittleEndianSwap")] LittleEndianSwap } } diff --git a/Plugins/PluginInterface/ProtectTypeEnum.cs b/Plugins/PluginInterface/ProtectTypeEnum.cs index 0f4a106..421bd97 100644 --- a/Plugins/PluginInterface/ProtectTypeEnum.cs +++ b/Plugins/PluginInterface/ProtectTypeEnum.cs @@ -9,11 +9,11 @@ namespace PluginInterface { public enum ProtectTypeEnum { - [Display(Name = "只读")] + [Display(Name = "ReadOnly")] ReadOnly, - [Display(Name = "读写")] + [Display(Name = "ReadWrite")] ReadWrite, - [Display(Name = "只写")] + [Display(Name = "WriteOnly")] WriteOnly, } } From b1628b13399615f25e8281aaea3705409378f049 Mon Sep 17 00:00:00 2001 From: UserX Date: Sat, 23 Dec 2023 14:15:55 +0200 Subject: [PATCH 5/5] Add DeviceXGK --- IoTGateway/iotgateway.db | Bin 319488 -> 319488 bytes Plugins/Drivers/PLC.LS/DeviceXGB.cs | 92 ++-- Plugins/Drivers/PLC.LS/DeviceXGK.cs | 735 ++++++++++++++++++++++++++++ Plugins/Plugin/MyMqttClient.cs | 9 +- 4 files changed, 788 insertions(+), 48 deletions(-) create mode 100644 Plugins/Drivers/PLC.LS/DeviceXGK.cs diff --git a/IoTGateway/iotgateway.db b/IoTGateway/iotgateway.db index 26647696ad7b65d06856e967d64f2612d37364eb..aee9041224031e7792aef1cb2405b5866924b8fe 100644 GIT binary patch delta 1121 zcmZvbUu@e{6vnUZ6FYX|v~Ier=>~P$jWH>rncHs7=>C+nsz3!gQg>qmB+oUOv&0Uz z)6kbOt73hC2hg-f__LRRgoK@ffPtTm zeRPh$@4LTyb|rpxC4Td}HJU&O^%yhjYqRTXgtxv%wja(CFQXQ;gqnodPJTFgD)KIO zi>-%$V18o~^!89c94BXpPtX!|k-ST0{Q2PVi_!r+CQ?!|XO>Eu>gc8+=1k*Ny->B3 z;Eg+F$sJybsTHQBr#NwW?kz zYlb7172R+&Lork>KW#se*Az=Vb@#(hzrQ-W?hc<8^T&i{uJ%5A`*YVAI4$7qW0O;TNQwOYI4V-RkT9&x0zT!v|SNZ`+hmE>{g* zZG`i;A^bB1ecN;9KbjAz#TkID_%;g%y$u3#4DlGwu+WJ=5UG#72nSzKppJf9K=aH$!tME$`H!Bt%{$g`OMNf=iO|5k{fBVggeUbqe6ZscH|fC_!u zjSBveQb~}ujQHnWQ>Gsp8caf`cRdd00Q?}2;+{6hGwv~$7vw>_w+*EBaZ54mvTob| zVGG}jLl)m?gE8-960Rn=8cA=^iO@4p^O`eI0LFdZ-5MyK=>>@yvh*p<67i95$yV>n zURb8+2{#oG`DQ=(M3(e`x4fe`RU7}l5BASx;kb7!3)d$)xK$Ko+7aIy`6+UOdxU*4 zyvY36G|Js!+G93-iOXxoqsD->)zc?kyS zDR-A3Z)r5)S^t&=Uk@|BOfT6XsY)(BtfrnTB%*50%($&B~9@Z$HqoSgGJ z-|zQ3=S#18(yN|@-_{6AQPiH^lg3)cSfe##jd`-kZ>Bud0m|ie?r^k7o%RXaSK?ja zKL3cXBu{e@Xr~UaXArk8g828%xS7*SvSz^dM?F{>MSV|l4K zGK)D0_MlwLwrTC#*}1zRnx!^Vb(E{wdCKv#W3%**{R`WVHk+sjNq&a>LPV|+2H0t4 zmHvYkO`vt~fg66ZiMuJ{j;n`N25)VGK3w3yh8Ld#0Vmziq1~e)#?u645o)mmz$=y0 z7fOZs4Oh62hDMq}8K4RaG`y_YZE%a_>iR9&cO39owmv(i4`0VBC#1AfP8gsArhp1I zPr2%yT@I9fus^hKwY?}Ngmodn_mCy-FK#z320^MZn%Uf7E39@vSSs^K6>sFGD`@_^znRwnep#SO{qe~ZAJ2kct18ZK4Z zj#K0wspR&s_g*4i4Xm!tmHkP`NXqM@Ka8hl0Z*T + /// 反射构造函数 + /// + /// + /// + public DeviceXGK(string device, ILogger logger) + { + _device = device; + _logger = logger; + + _logger.LogInformation($"Device:[{_device}],Create()"); + } + + public bool IsConnected { get; set; } + + public bool Connect() + { + try + { + _logger.LogInformation($"Device:[{_device}],Connect()"); + if (!IsConnected) + { + switch (lSTypeConnect) + { + case LSTypeConnect.FENet: + if (fastEnet == null || !IsConnected) + { + fastEnet = new XGKFastEnet(IpAddress, Port); + + fastEnet.SlotNo = (byte)Slot; + fastEnet.SetCpuType = $"{lSCpuInfo}"; + IsConnected = fastEnet.ConnectServer().IsSuccess; + } + break; + case LSTypeConnect.CNet: + if (xGBCnet == null || !IsConnected) + { + xGBCnet = new XGKCnet + { + Station = Station + }; + xGBCnet.SerialPortInni(sp => + { + sp.PortName = PortName; + sp.BaudRate = BaudRate; + sp.DataBits = DataBits; + sp.StopBits = StopBits; + sp.Parity = Parity; + }); + xGBCnet.Open(); + IsConnected = xGBCnet.IsOpen(); + } + break; + + default: + return IsConnected; + } + + } + else + { + return IsConnected; + } + return IsConnected; + } + catch (Exception ex) + { + _logger.LogError(ex, $"Device:[{_device}],Connect()"); + return IsConnected; + } + } + + public bool Close() + { + try + { + _logger.LogInformation($"Device:[{_device}],Close()"); + switch (lSTypeConnect) + { + case LSTypeConnect.FENet: + if (fastEnet != null) + { + + fastEnet.ConnectClose(); + return !IsConnected; + } + break; + case LSTypeConnect.CNet: + if (xGBCnet != null) + { + xGBCnet.Close(); + + return !IsConnected; + } + break; + + default: + return false; + } + return !IsConnected; + } + catch (Exception ex) + { + _logger.LogError(ex, $"Device:[{_device}],Close()"); + return false; + } + } + + public void Dispose() + { + try + { + _logger?.LogInformation($"Device:[{_device}],Dispose()"); + switch (lSTypeConnect) + { + case LSTypeConnect.FENet: + if (fastEnet != null) + { + + fastEnet.Dispose(); + + } + break; + case LSTypeConnect.CNet: + if (xGBCnet != null) + { + xGBCnet.Dispose(); + + + } + break; + + + + } + + // Suppress finalization. + GC.SuppressFinalize(this); + } + catch (Exception ex) + { + _logger.LogError(ex, $"Device:[{_device}],Dispose()"); + } + + } + [Method("XGK", description: "Read")] + public DriverReturnValueModel Read(DriverAddressIoArgModel ioArg) + { + DriverReturnValueModel ret = new() { StatusType = VaribaleStatusTypeEnum.Good }; + if (!IsConnected) + ret.StatusType = VaribaleStatusTypeEnum.Bad; + else + { + if (ret.StatusType != VaribaleStatusTypeEnum.Good) + return ret; + try + { + + + if (ioArg.ValueType == DataTypeEnum.Bool) + { + + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.ReadBool(ioArg.Address, 1) : xGBCnet.ReadBool(ioArg.Address, 1); + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content[0]); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"Read failed"; + } + return ret; + } + if (ioArg.ValueType == DataTypeEnum.Bit) + { + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.ReadBool(ioArg.Address, 1) : xGBCnet.ReadBool(ioArg.Address, 1); + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content[0]); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"Read failed"; + } + return ret; + } + if (ioArg.ValueType == DataTypeEnum.Byte) + { + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.ReadByte(ioArg.Address) : xGBCnet.ReadByte(ioArg.Address); + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"Read failed"; + } + return ret; + } + if (ioArg.ValueType == DataTypeEnum.Uint16) + { + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.ReadUInt16(ioArg.Address, 1) : xGBCnet.ReadUInt16(ioArg.Address, 1); + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content[0]); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"Read failed"; + } + return ret; + + } + else if (ioArg.ValueType == DataTypeEnum.Int16) + { + + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.ReadInt16(ioArg.Address, 1) : xGBCnet.ReadInt16(ioArg.Address, 1); + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content[0]); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"Read failed"; + } + return ret; + } + else if (ioArg.ValueType == DataTypeEnum.Int32) + { + + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.ReadInt32(ioArg.Address, 1) : xGBCnet.ReadInt32(ioArg.Address, 1); + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content[0]); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"Read failed"; + } + return ret; + } + else if (ioArg.ValueType == DataTypeEnum.Uint32) + { + + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.ReadUInt32(ioArg.Address, 1) : xGBCnet.ReadUInt32(ioArg.Address, 1); + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content[0]); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"Read failed"; + } + return ret; + } + else if (ioArg.ValueType == DataTypeEnum.Int64) + { + + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.ReadInt64(ioArg.Address, 1) : xGBCnet.ReadInt64(ioArg.Address, 1); + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content[0]); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"Read failed"; + } + return ret; + } + else if (ioArg.ValueType == DataTypeEnum.Uint64) + { + + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.ReadUInt64(ioArg.Address, 1) : xGBCnet.ReadUInt64(ioArg.Address, 1); + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content[0]); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"Read failed"; + } + return ret; + } + else if (ioArg.ValueType == DataTypeEnum.Double) + { + + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.ReadDouble(ioArg.Address, 1) : xGBCnet.ReadDouble(ioArg.Address, 1); + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content[0]); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"Read failed"; + } + return ret; + } + else if (ioArg.ValueType == DataTypeEnum.Float) + { + + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.ReadFloat(ioArg.Address, 1) : xGBCnet.ReadFloat(ioArg.Address, 1); + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content[0]); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"Read failed"; + } + return ret; + } + else if (ioArg.ValueType == DataTypeEnum.AsciiString) + { + + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.ReadString(ioArg.Address, 1) : xGBCnet.ReadString(ioArg.Address, 1); + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"Read failed"; + } + return ret; + } + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.UnKnow; + ret.Message = "Read failed"; + _logger.LogError($"Device:[{_device}],[{ioArg.ValueType}]类型未定义"); + return ret; + } + } + catch (Exception ex) + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = ex.Message; + _logger.LogError(ex, $"Device:[{_device}],ReadRegistersBuffers(),Error"); + } + } + + + return ret; + + } + [Method("XGK", description: "ReadMultiple")] + public DriverReturnValueModel ReadMultiple(DriverAddressIoArgModel ioArg) + { + DriverReturnValueModel ret = new() { StatusType = VaribaleStatusTypeEnum.Good }; + + + + if (!IsConnected) + ret.StatusType = VaribaleStatusTypeEnum.Bad; + else + { + if (ret.StatusType != VaribaleStatusTypeEnum.Good) + return ret; + try + { + string startAddress; + if (ioArg.Address.Contains('|')) + { + startAddress = ioArg.Address.Split('|')[0]; + ioArg.Address = ioArg.Address.Split('|')[1]; + } + var args = ioArg.Address.Split(','); + + startAddress = args[0]; + ushort length = (ushort)(ushort.Parse(args[1]) * 2); + + if (ioArg.ValueType == DataTypeEnum.Bool) + { + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.ReadBool(startAddress, length) : xGBCnet.ReadBool(startAddress, length); + + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"Read failed"; + } + return ret; + } + if (ioArg.ValueType == DataTypeEnum.Bit) + { + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.ReadBool(startAddress, length) : xGBCnet.ReadBool(startAddress, length); + + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"Read failed"; + } + return ret; + } + if (ioArg.ValueType == DataTypeEnum.Byte) + { + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.Read(startAddress, length) : xGBCnet.Read(startAddress, length); + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"Read failed"; + } + return ret; + } + if (ioArg.ValueType == DataTypeEnum.Uint16) + { + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.ReadUInt16(startAddress, length) : xGBCnet.ReadUInt16(startAddress, length); + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"Read failed"; + } + return ret; + + } + else if (ioArg.ValueType == DataTypeEnum.Int16) + { + + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.ReadInt16(startAddress, length) : xGBCnet.ReadInt16(startAddress, length); + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"Read failed"; + } + return ret; + } + else if (ioArg.ValueType == DataTypeEnum.Int32) + { + + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.ReadInt32(startAddress, length) : xGBCnet.ReadInt32(startAddress, length); + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"Read failed"; + } + return ret; + } + else if (ioArg.ValueType == DataTypeEnum.Uint32) + { + + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.ReadUInt32(startAddress, length) : xGBCnet.ReadUInt32(startAddress, length); + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"Read failed"; + } + return ret; + } + else if (ioArg.ValueType == DataTypeEnum.Int64) + { + + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.ReadInt64(startAddress, length) : xGBCnet.ReadInt64(startAddress, length); + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"Read failed"; + } + return ret; + } + else if (ioArg.ValueType == DataTypeEnum.Uint64) + { + + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.ReadUInt64(startAddress, length) : xGBCnet.ReadUInt64(startAddress, length); + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"Read failed"; + } + return ret; + } + else if (ioArg.ValueType == DataTypeEnum.Double) + { + + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.ReadDouble(startAddress, length) : xGBCnet.ReadDouble(startAddress, length); + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"Read failed"; + } + return ret; + } + else if (ioArg.ValueType == DataTypeEnum.Float) + { + + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.ReadFloat(startAddress, length) : xGBCnet.ReadFloat(startAddress, length); + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"Read failed"; + } + return ret; + } + else if (ioArg.ValueType == DataTypeEnum.AsciiString) + { + + OperateResult read = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.ReadString(startAddress, length) : xGBCnet.ReadString(startAddress, length); + if (read.IsSuccess) + ret.Value = Newtonsoft.Json.JsonConvert.SerializeObject(read.Content); + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = $"Read failed"; + } + return ret; + } + else + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.UnKnow; + ret.Message = "Read failed"; + _logger.LogError($"Device:[{_device}],[{ioArg.ValueType}]类型未定义"); + return ret; + } + } + catch (Exception ex) + { + IsConnected = false; + ret.StatusType = VaribaleStatusTypeEnum.Bad; + ret.Message = ex.Message; + _logger.LogError(ex, $"Device:[{_device}],ReadRegistersBuffers(),Error"); + } + } + + + return ret; + + } + [Method("XGK", description: "Write")] + public async Task WriteAsync(string RequestId, string Method, DriverAddressIoArgModel ioArg) + { + RpcResponse rpcResponse = new() { IsSuccess = false }; + try + { + OperateResult writeResult; + if (!IsConnected) + rpcResponse.Description = "Device connection has been disconnected"; + else + { + + + if (ioArg.ValueType == DataTypeEnum.Bool) + { + var value = ioArg.Value.ToString() == "1" || ioArg.Value.ToString().ToLower() == "true"; + writeResult = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.WriteCoil(ioArg.Address, value) : xGBCnet.WriteCoil(ioArg.Address, value); + rpcResponse.IsSuccess = true; + return rpcResponse; + + + } + if (ioArg.ValueType == DataTypeEnum.Bit) + { + var value = ioArg.Value.ToString() == "1" || ioArg.Value.ToString().ToLower() == "true"; + writeResult = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.WriteCoil(ioArg.Address, value) : xGBCnet.WriteCoil(ioArg.Address, value); + rpcResponse.IsSuccess = true; + return rpcResponse; + } + if (ioArg.ValueType == DataTypeEnum.Byte) + { + var value = ioArg.Value.ToString(); + writeResult = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.Write(ioArg.Address, value) : xGBCnet.Write(ioArg.Address, value); + + rpcResponse.IsSuccess = true; + return rpcResponse; + } + if (ioArg.ValueType == DataTypeEnum.Uint16) + { + var value = ushort.Parse(ioArg.Value.ToString()); + writeResult = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.Write(ioArg.Address, value) : xGBCnet.Write(ioArg.Address, value); + rpcResponse.IsSuccess = true; + return rpcResponse; + + } + else if (ioArg.ValueType == DataTypeEnum.Int16) + { + var value = short.Parse(ioArg.Value.ToString()); + writeResult = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.Write(ioArg.Address, value) : xGBCnet.Write(ioArg.Address, value); + rpcResponse.IsSuccess = true; + return rpcResponse; + } + else if (ioArg.ValueType == DataTypeEnum.Int32) + { + + var value = int.Parse(ioArg.Value.ToString()); + writeResult = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.Write(ioArg.Address, value) : xGBCnet.Write(ioArg.Address, value); + rpcResponse.IsSuccess = true; + return rpcResponse; + } + else if (ioArg.ValueType == DataTypeEnum.Uint32) + { + + var value = uint.Parse(ioArg.Value.ToString()); + writeResult = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.Write(ioArg.Address, value) : xGBCnet.Write(ioArg.Address, value); + rpcResponse.IsSuccess = true; + return rpcResponse; + } + else if (ioArg.ValueType == DataTypeEnum.Int64) + { + + var value = long.Parse(ioArg.Value.ToString()); + writeResult = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.Write(ioArg.Address, value) : xGBCnet.Write(ioArg.Address, value); + rpcResponse.IsSuccess = true; + return rpcResponse; + } + else if (ioArg.ValueType == DataTypeEnum.Uint64) + { + + var value = ulong.Parse(ioArg.Value.ToString()); + writeResult = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.Write(ioArg.Address, value) : xGBCnet.Write(ioArg.Address, value); + rpcResponse.IsSuccess = true; + return rpcResponse; + } + else if (ioArg.ValueType == DataTypeEnum.Double) + { + + var value = double.Parse(ioArg.Value.ToString()); + writeResult = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.Write(ioArg.Address, value) : xGBCnet.Write(ioArg.Address, value); + rpcResponse.IsSuccess = true; + return rpcResponse; + } + else if (ioArg.ValueType == DataTypeEnum.Float) + { + + var value = float.Parse(ioArg.Value.ToString()); + writeResult = lSTypeConnect == LSTypeConnect.FENet ? fastEnet.Write(ioArg.Address, value) : xGBCnet.Write(ioArg.Address, value); + rpcResponse.IsSuccess = true; + return rpcResponse; + } + + + + + rpcResponse.Description = $"Writing is not supported:{Method}"; + } + } + catch (Exception ex) + { + IsConnected = false; + rpcResponse.Description = $"Write failed,[method]:{Method},[ioArg]:{ioArg},[ex]:{ex}"; + _logger.LogError(ex, $"Device:[{_device}],WriteAsync(),Error"); + } + + return rpcResponse; + } + #endregion + + } +} diff --git a/Plugins/Plugin/MyMqttClient.cs b/Plugins/Plugin/MyMqttClient.cs index 75a4ccf..5db5cda 100644 --- a/Plugins/Plugin/MyMqttClient.cs +++ b/Plugins/Plugin/MyMqttClient.cs @@ -64,9 +64,12 @@ namespace Plugin Client.DisconnectedAsync += Client_DisconnectedAsync; Client.ApplicationMessageReceivedAsync += Client_ApplicationMessageReceivedAsync; - await Client.ConnectAsync(_options); + if(Client.ConnectAsync(_options).IsCompletedSuccessfully) ; + { + _logger.LogInformation("MQTT WAITING FOR APPLICATION MESSAGES"); + } - _logger.LogInformation("MQTT WAITING FOR APPLICATION MESSAGES"); + } catch (Exception ex) { @@ -126,7 +129,7 @@ namespace Plugin try { _logger.LogError($"MQTT DISCONNECTED WITH SERVER "); - await Client.ConnectAsync(_options); + await Client.DisconnectAsync(); } catch (Exception ex) {