| | |
| | | using DocumentFormat.OpenXml.Bibliography; |
| | | using DocumentFormat.OpenXml.Drawing; |
| | | using Elastic.Clients.Elasticsearch; |
| | | using IoTClient; |
| | | using IoTClient.Clients.Modbus; |
| | |
| | | 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(); |
| | |
| | | /// <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) |
| | | { |
| | |
| | | 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>(); |