优化Mitsubishi驱动
This commit is contained in:
parent
79d74b9fd4
commit
5683a35117
@ -1,40 +1,33 @@
|
|||||||
using IoTClient.Clients.PLC;
|
using IoTClient.Clients.PLC;
|
||||||
using IoTClient.Enums;
|
using IoTClient.Enums;
|
||||||
using PluginInterface;
|
using PluginInterface;
|
||||||
using System;
|
|
||||||
using System.Text;
|
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace DriverMitsubishi
|
namespace DriverMitsubishi
|
||||||
{
|
{
|
||||||
[DriverSupported("A_1E")]
|
[DriverSupported("A_1E")]
|
||||||
[DriverSupported("Qna_3E")]
|
[DriverSupported("Qna_3E")]
|
||||||
[DriverInfoAttribute("Mitsubishi", "V1.0.0", "Copyright IoTGateway-IoTClient© 2022-01-15")]
|
[DriverInfo("Mitsubishi", "V1.0.0", "Copyright IoTGateway-IoTClient© 2022-01-15")]
|
||||||
public class Mitsubishi : IDriver
|
public class Mitsubishi : IDriver
|
||||||
{
|
{
|
||||||
private MitsubishiClient plc = null;
|
private MitsubishiClient? _plc;
|
||||||
|
|
||||||
public ILogger _logger { get; set; }
|
public ILogger _logger { get; set; }
|
||||||
private readonly string _device;
|
private readonly string _device;
|
||||||
|
|
||||||
#region 配置参数
|
#region 配置参数
|
||||||
|
|
||||||
[ConfigParameter("设备Id")]
|
[ConfigParameter("设备Id")] public string DeviceId { get; set; }
|
||||||
public Guid DeviceId { get; set; }
|
|
||||||
|
|
||||||
[ConfigParameter("PLC类型")]
|
[ConfigParameter("PLC类型")] public MitsubishiVersion CpuType { get; set; } = MitsubishiVersion.Qna_3E;
|
||||||
public MitsubishiVersion CpuType { get; set; } = MitsubishiVersion.Qna_3E;
|
|
||||||
|
|
||||||
[ConfigParameter("IP地址")]
|
[ConfigParameter("IP地址")] public string IpAddress { get; set; } = "127.0.0.1";
|
||||||
public string IpAddress { get; set; } = "127.0.0.1";
|
|
||||||
|
|
||||||
[ConfigParameter("端口号")]
|
[ConfigParameter("端口号")] public int Port { get; set; } = 6000;
|
||||||
public int Port { get; set; } = 6000;
|
|
||||||
|
|
||||||
[ConfigParameter("超时时间ms")]
|
[ConfigParameter("超时时间ms")] public int Timeout { get; set; } = 3000;
|
||||||
public int Timeout { get; set; } = 3000;
|
|
||||||
|
|
||||||
[ConfigParameter("最小通讯周期ms")]
|
[ConfigParameter("最小通讯周期ms")] public uint MinPeriod { get; set; } = 3000;
|
||||||
public uint MinPeriod { get; set; } = 3000;
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -49,23 +42,21 @@ namespace DriverMitsubishi
|
|||||||
|
|
||||||
public bool IsConnected
|
public bool IsConnected
|
||||||
{
|
{
|
||||||
get
|
get { return _plc != null && _plc.Connected; }
|
||||||
{
|
|
||||||
return plc != null && plc.Connected;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Connect()
|
public bool Connect()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
plc = new MitsubishiClient(MitsubishiVersion.Qna_3E, IpAddress, Port);
|
_plc = new MitsubishiClient(MitsubishiVersion.Qna_3E, IpAddress, Port);
|
||||||
plc.Open();
|
_plc.Open();
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return IsConnected;
|
return IsConnected;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,12 +64,11 @@ namespace DriverMitsubishi
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
plc?.Close();
|
_plc?.Close();
|
||||||
return !IsConnected;
|
return !IsConnected;
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -87,11 +77,10 @@ namespace DriverMitsubishi
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
plc = null;
|
_plc = null;
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,61 +89,62 @@ namespace DriverMitsubishi
|
|||||||
{
|
{
|
||||||
var ret = new DriverReturnValueModel { StatusType = VaribaleStatusTypeEnum.Good };
|
var ret = new DriverReturnValueModel { StatusType = VaribaleStatusTypeEnum.Good };
|
||||||
|
|
||||||
if (plc != null && this.IsConnected)
|
if (_plc != null && this.IsConnected)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
switch (ioarg.ValueType)
|
switch (ioarg.ValueType)
|
||||||
{
|
{
|
||||||
case PluginInterface.DataTypeEnum.Bit:
|
case PluginInterface.DataTypeEnum.Bit:
|
||||||
ret.Value = plc.ReadBoolean(ioarg.Address).Value == true ? 1 : 0;
|
ret.Value = _plc.ReadBoolean(ioarg.Address).Value ? 1 : 0;
|
||||||
break;
|
break;
|
||||||
case PluginInterface.DataTypeEnum.Bool:
|
case PluginInterface.DataTypeEnum.Bool:
|
||||||
ret.Value = plc.ReadBoolean(ioarg.Address).Value;
|
ret.Value = _plc.ReadBoolean(ioarg.Address).Value;
|
||||||
break;
|
break;
|
||||||
case PluginInterface.DataTypeEnum.UByte:
|
case PluginInterface.DataTypeEnum.UByte:
|
||||||
ret.Value = plc.ReadByte(ioarg.Address).Value;
|
ret.Value = _plc.ReadByte(ioarg.Address).Value;
|
||||||
break;
|
break;
|
||||||
case PluginInterface.DataTypeEnum.Byte:
|
case PluginInterface.DataTypeEnum.Byte:
|
||||||
ret.Value = (sbyte)plc.ReadByte(ioarg.Address).Value;
|
ret.Value = (sbyte)_plc.ReadByte(ioarg.Address).Value;
|
||||||
break;
|
break;
|
||||||
case PluginInterface.DataTypeEnum.Uint16:
|
case PluginInterface.DataTypeEnum.Uint16:
|
||||||
ret.Value =plc.ReadUInt16(ioarg.Address).Value;
|
ret.Value = _plc.ReadUInt16(ioarg.Address).Value;
|
||||||
break;
|
break;
|
||||||
case PluginInterface.DataTypeEnum.Int16:
|
case PluginInterface.DataTypeEnum.Int16:
|
||||||
ret.Value = plc.ReadInt16(ioarg.Address).Value;
|
ret.Value = _plc.ReadInt16(ioarg.Address).Value;
|
||||||
break;
|
break;
|
||||||
case PluginInterface.DataTypeEnum.Uint32:
|
case PluginInterface.DataTypeEnum.Uint32:
|
||||||
ret.Value =plc.ReadUInt32(ioarg.Address).Value;
|
ret.Value = _plc.ReadUInt32(ioarg.Address).Value;
|
||||||
break;
|
break;
|
||||||
case PluginInterface.DataTypeEnum.Int32:
|
case PluginInterface.DataTypeEnum.Int32:
|
||||||
ret.Value = plc.ReadInt32(ioarg.Address).Value;
|
ret.Value = _plc.ReadInt32(ioarg.Address).Value;
|
||||||
break;
|
break;
|
||||||
case PluginInterface.DataTypeEnum.Float:
|
case PluginInterface.DataTypeEnum.Float:
|
||||||
ret.Value = plc.ReadFloat(ioarg.Address).Value;
|
ret.Value = _plc.ReadFloat(ioarg.Address).Value;
|
||||||
break;
|
break;
|
||||||
case PluginInterface.DataTypeEnum.Double:
|
case PluginInterface.DataTypeEnum.Double:
|
||||||
ret.Value = plc.ReadDouble(ioarg.Address).Value;
|
ret.Value = _plc.ReadDouble(ioarg.Address).Value;
|
||||||
break;
|
break;
|
||||||
case PluginInterface.DataTypeEnum.Uint64:
|
case PluginInterface.DataTypeEnum.Uint64:
|
||||||
ret.Value = plc.ReadUInt64(ioarg.Address).Value;
|
ret.Value = _plc.ReadUInt64(ioarg.Address).Value;
|
||||||
break;
|
break;
|
||||||
case PluginInterface.DataTypeEnum.Int64:
|
case PluginInterface.DataTypeEnum.Int64:
|
||||||
ret.Value = plc.ReadInt64(ioarg.Address).Value;
|
ret.Value = _plc.ReadInt64(ioarg.Address).Value;
|
||||||
break;
|
break;
|
||||||
case PluginInterface.DataTypeEnum.AsciiString:
|
case PluginInterface.DataTypeEnum.AsciiString:
|
||||||
ret.Value = plc.ReadString(ioarg.Address);
|
ret.Value = _plc.ReadString(ioarg.Address);
|
||||||
break;
|
break;
|
||||||
case PluginInterface.DataTypeEnum.Utf8String:
|
case PluginInterface.DataTypeEnum.Utf8String:
|
||||||
ret.Value = plc.ReadString(ioarg.Address);
|
ret.Value = _plc.ReadString(ioarg.Address);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
ret.StatusType = VaribaleStatusTypeEnum.Bad;
|
||||||
|
ret.Message = $"读取失败,不支持的类型:{ioarg.ValueType}";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
||||||
ret.StatusType = VaribaleStatusTypeEnum.Bad;
|
ret.StatusType = VaribaleStatusTypeEnum.Bad;
|
||||||
ret.Message = $"读取失败,{ex.Message}";
|
ret.Message = $"读取失败,{ex.Message}";
|
||||||
}
|
}
|
||||||
@ -164,9 +154,11 @@ namespace DriverMitsubishi
|
|||||||
ret.StatusType = VaribaleStatusTypeEnum.Bad;
|
ret.StatusType = VaribaleStatusTypeEnum.Bad;
|
||||||
ret.Message = "连接失败";
|
ret.Message = "连接失败";
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
public async Task<RpcResponse> WriteAsync(string RequestId, string Method, DriverAddressIoArgModel Ioarg)
|
|
||||||
|
public async Task<RpcResponse> WriteAsync(string requestId, string method, DriverAddressIoArgModel ioarg)
|
||||||
{
|
{
|
||||||
RpcResponse rpcResponse = new() { IsSuccess = false, Description = "设备驱动内未实现写入功能" };
|
RpcResponse rpcResponse = new() { IsSuccess = false, Description = "设备驱动内未实现写入功能" };
|
||||||
return rpcResponse;
|
return rpcResponse;
|
||||||
|
Loading…
Reference in New Issue
Block a user