mirror of
https://gitee.com/iioter/iotgateway.git
synced 2024-11-29 18:28:09 +08:00
commit
cd7352ee6f
@ -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,
|
||||
}
|
||||
}
|
@ -7,41 +7,41 @@ namespace IoTGateway.Model
|
||||
{
|
||||
public class Device : TreePoco<Device>, IBasePoco
|
||||
{
|
||||
[Display(Name = "名称")]
|
||||
[Display(Name = "Device Name")]
|
||||
public string DeviceName { get; set; }
|
||||
|
||||
[Display(Name = "排序")]
|
||||
[Display(Name = "Sort")]
|
||||
public uint Index { get; set; }
|
||||
|
||||
[Display(Name = "描述")]
|
||||
[Display(Name = "Description")]
|
||||
public string Description { get; set; }
|
||||
|
||||
public Driver Driver { get; set; }
|
||||
[Display(Name = "驱动")]
|
||||
[Display(Name = "Device PLC")]
|
||||
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 = "Device 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<DeviceConfig> DeviceConfigs { get; set; }
|
||||
|
@ -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; }
|
||||
}
|
||||
}
|
||||
|
@ -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 = "Device Name")]
|
||||
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];
|
||||
|
@ -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; }
|
||||
}
|
||||
}
|
@ -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; }
|
||||
}
|
||||
}
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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}
|
||||
|
@ -2,7 +2,7 @@
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ActiveDebugProfile>IoTGateway</ActiveDebugProfile>
|
||||
<NameOfLastUsedPublishProfile>D:\000000-IIoTGateway\00000-iotgateway\IoTGateway\Properties\PublishProfiles\FolderProfile.pubxml</NameOfLastUsedPublishProfile>
|
||||
<NameOfLastUsedPublishProfile>FolderProfile</NameOfLastUsedPublishProfile>
|
||||
<View_SelectedScaffolderID>RazorViewEmptyScaffolder</View_SelectedScaffolderID>
|
||||
<View_SelectedScaffolderCategoryPath>root/Common/MVC/View</View_SelectedScaffolderCategoryPath>
|
||||
</PropertyGroup>
|
||||
|
@ -4,8 +4,8 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
|
||||
-->
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<_PublishTargetUrl>D:\000000-IIoTGateway\00000-iotgateway\IoTGateway\bin\Release\net6.0\publish\</_PublishTargetUrl>
|
||||
<History>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;</History>
|
||||
<_PublishTargetUrl>C:\Users\UserX\RiderProjects\iotgateway1\IoTGateway\bin\Release\net6.0\publish\</_PublishTargetUrl>
|
||||
<History>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;</History>
|
||||
<LastFailureDetails />
|
||||
</PropertyGroup>
|
||||
</Project>
|
Binary file not shown.
@ -9,7 +9,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="HslCommunication" Version="11.6.3" />
|
||||
<PackageReference Include="HslCommunication" Version="11.7.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
|
743
Plugins/Drivers/PLC.LS/DeviceXGB.cs
Normal file
743
Plugins/Drivers/PLC.LS/DeviceXGB.cs
Normal file
@ -0,0 +1,743 @@
|
||||
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 20231223")]
|
||||
public class DeviceXGB : IDriver
|
||||
{
|
||||
public ILogger _logger { get; set; }
|
||||
private readonly string _device;
|
||||
|
||||
private XGBCnet xGBCnet = null;
|
||||
private XGBFastEnet fastEnet = null;
|
||||
|
||||
|
||||
#region ConfigParameter
|
||||
|
||||
[ConfigParameter("Device Id")] public string DeviceId { get; set; }
|
||||
|
||||
[ConfigParameter("PLC LSCpuInfo")] public LSCpuInfo lSCpuInfo { get; set; } = LSCpuInfo.XGB;
|
||||
|
||||
[ConfigParameter("PLC TypeConnect")] public LSTypeConnect lSTypeConnect { get; set; } = LSTypeConnect.FENet;
|
||||
|
||||
[ConfigParameter("IP")] public string IpAddress { get; set; } = "127.0.0.1";
|
||||
|
||||
[ConfigParameter("Port")] public int Port { get; set; } = 2004;
|
||||
|
||||
[ConfigParameter("Slot")] public short Slot { get; set; } = 0;
|
||||
|
||||
[ConfigParameter("PortName")] public string PortName { get; set; } = "COM1";
|
||||
|
||||
[ConfigParameter("BaudRate")] public int BaudRate { get; set; } = 9600;
|
||||
|
||||
[ConfigParameter("DataBits")] public int DataBits { get; set; } = 8;
|
||||
|
||||
[ConfigParameter("Parity")] public Parity Parity { get; set; } = Parity.None;
|
||||
|
||||
[ConfigParameter("StopBits")] public StopBits StopBits { get; set; } = StopBits.One;
|
||||
|
||||
[ConfigParameter("Station")] public byte Station { get; set; } = 1;
|
||||
|
||||
[ConfigParameter("Overtime time ms")] public int Timeout { get; set; } = 3000;
|
||||
|
||||
[ConfigParameter("Minimum communication Cycle ms")] public uint MinPeriod { get; set; } = 3000;
|
||||
|
||||
#endregion
|
||||
|
||||
#region
|
||||
/// <summary>
|
||||
/// 反射构造函数
|
||||
/// </summary>
|
||||
/// <param name="device"></param>
|
||||
/// <param name="logger"></param>
|
||||
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);
|
||||
fastEnet.SlotNo = (byte)Slot;
|
||||
fastEnet.SetCpuType = $"{lSCpuInfo}";
|
||||
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<bool[]> 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<bool[]> 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<byte> 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<ushort[]> 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<short[]> 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<int[]> 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<uint[]> 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<long[]> 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<ulong[]> 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<double[]> 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<float[]> 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<string> 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("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];
|
||||
ushort length = (ushort)(ushort.Parse(args[1]) * 2);
|
||||
|
||||
if (ioArg.ValueType == DataTypeEnum.Bool)
|
||||
{
|
||||
OperateResult<bool[]> 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<bool[]> 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<byte[]> 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<ushort[]> 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<short[]> 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<int[]> 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<uint[]> 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<long[]> 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<ulong[]> 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<double[]> 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<float[]> 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<string> 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("XGB", description: "Write")]
|
||||
public async Task<RpcResponse> 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
|
||||
|
||||
}
|
||||
|
||||
public enum LSTypeConnect
|
||||
{
|
||||
CNet = 0,
|
||||
FENet = 1,
|
||||
|
||||
}
|
||||
}
|
735
Plugins/Drivers/PLC.LS/DeviceXGK.cs
Normal file
735
Plugins/Drivers/PLC.LS/DeviceXGK.cs
Normal file
@ -0,0 +1,735 @@
|
||||
using HslCommunication;
|
||||
using HslCommunication.Profinet.LSIS;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PluginInterface;
|
||||
using System.IO.Ports;
|
||||
|
||||
namespace PLC.LSIS
|
||||
{
|
||||
[DriverSupported("FENet")]
|
||||
[DriverSupported("CNet")]
|
||||
[DriverInfo("XGK", "V1.0.0", "Copyright IoTGateway.net 20231223")]
|
||||
public class DeviceXGK : IDriver
|
||||
{
|
||||
public ILogger _logger { get; set; }
|
||||
private readonly string _device;
|
||||
|
||||
private XGKCnet xGBCnet = null;
|
||||
private XGKFastEnet fastEnet = null;
|
||||
|
||||
|
||||
#region ConfigParameter
|
||||
|
||||
[ConfigParameter("Device Id")] public string DeviceId { get; set; }
|
||||
|
||||
[ConfigParameter("PLC LSCpuInfo")] public LSCpuInfo lSCpuInfo { get; set; } = LSCpuInfo.XGK;
|
||||
|
||||
[ConfigParameter("PLC TypeConnect")] public LSTypeConnect lSTypeConnect { get; set; } = LSTypeConnect.FENet;
|
||||
|
||||
[ConfigParameter("IP")] public string IpAddress { get; set; } = "127.0.0.1";
|
||||
|
||||
[ConfigParameter("Port")] public int Port { get; set; } = 2004;
|
||||
|
||||
[ConfigParameter("Slot")] public short Slot { get; set; } = 0;
|
||||
|
||||
[ConfigParameter("PortName")] public string PortName { get; set; } = "COM1";
|
||||
|
||||
[ConfigParameter("BaudRate")] public int BaudRate { get; set; } = 9600;
|
||||
|
||||
[ConfigParameter("DataBits")] public int DataBits { get; set; } = 8;
|
||||
|
||||
[ConfigParameter("Parity")] public Parity Parity { get; set; } = Parity.None;
|
||||
|
||||
[ConfigParameter("StopBits")] public StopBits StopBits { get; set; } = StopBits.One;
|
||||
|
||||
[ConfigParameter("Station")] public byte Station { get; set; } = 1;
|
||||
|
||||
[ConfigParameter("Overtime time ms")] public int Timeout { get; set; } = 3000;
|
||||
|
||||
[ConfigParameter("Minimum communication Cycle ms")] public uint MinPeriod { get; set; } = 3000;
|
||||
|
||||
#endregion
|
||||
|
||||
#region
|
||||
/// <summary>
|
||||
/// 反射构造函数
|
||||
/// </summary>
|
||||
/// <param name="device"></param>
|
||||
/// <param name="logger"></param>
|
||||
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<bool[]> 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<bool[]> 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<byte> 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<ushort[]> 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<short[]> 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<int[]> 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<uint[]> 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<long[]> 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<ulong[]> 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<double[]> 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<float[]> 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<string> 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<bool[]> 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<bool[]> 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<byte[]> 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<ushort[]> 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<short[]> 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<int[]> 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<uint[]> 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<long[]> 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<ulong[]> 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<double[]> 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<float[]> 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<string> 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<RpcResponse> 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
|
||||
|
||||
}
|
||||
}
|
18
Plugins/Drivers/PLC.LS/PLC.LSIS.csproj
Normal file
18
Plugins/Drivers/PLC.LS/PLC.LSIS.csproj
Normal file
@ -0,0 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<OutputPath>../../../IoTGateway/bin/Debug/net6.0/drivers</OutputPath>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="HslCommunication" Version="11.7.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\PluginInterface\PluginInterface.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -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)
|
||||
{
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user