wxw
2024-09-05 64274de013b172d31d6cda1349786e5c165cf79f
Admin.NET/WCS.Application/PLC/PLCUtil.cs
@@ -1,4 +1,5 @@
using DocumentFormat.OpenXml.Bibliography;
using DocumentFormat.OpenXml.Drawing;
using Elastic.Clients.Elasticsearch;
using IoTClient;
using IoTClient.Clients.Modbus;
@@ -11,12 +12,14 @@
public class PLCUtil
{
    public readonly long PlcId;
    public readonly string PlcIP;
    private SiemensClient _client;
    private WcsPlc _modPlc;
    private readonly object OLock = new object();
    public PLCUtil(WcsPlc modPlc)
    {
        PlcId = modPlc.Id;
        PlcIP = modPlc.IP;
        _modPlc = modPlc;
        _client = new SiemensClient((SiemensVersion)modPlc.PLCType, modPlc.IP, modPlc.Port);
        _client.Open();
@@ -39,8 +42,9 @@
    /// <param name="DbNumber">DB区指定值</param>
    /// <param name="PosType">字符类型</param>
    /// <param name="Pos">偏移量/地址</param>
    /// <param name="Length">长度(字符串)</param>
    /// <returns></returns>
    public (IoTClient.Result, dynamic value) GetPlcDBValue(PLCDataTypeEnum PosType, string DbNumber, string Pos)
    public (IoTClient.Result, dynamic value) GetPlcDBValue(PLCDataTypeEnum PosType, string DbNumber, string Pos, int? Length = 0)
    {
        lock (OLock)
        {
@@ -83,7 +87,7 @@
                    result = _client.ReadDouble(address);
                    break;
                case PLCDataTypeEnum.String:
                    result = _client.ReadString(address);
                    result = _client.ReadString(address, Convert.ToUInt16(Length));
                    break;
                default:
                    result = new IoTClient.Result<object>();