From f3493a6f6f9958cea100ad596fa84239a6e2e962 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期二, 18 六月 2024 16:58:53 +0800
Subject: [PATCH] 获取老PCS下VK、桁架机械手、机床、状态信息
---
代码管理/PCS/WCS_Server/WIDESEA_WCS/WCSClient/Siemens/SiemensPLCClient.cs | 20 +++++++++++++++-----
1 files changed, 15 insertions(+), 5 deletions(-)
diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/WCSClient/Siemens/SiemensPLCClient.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/WCSClient/Siemens/SiemensPLCClient.cs"
index 8922db1..51ab901 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/WCSClient/Siemens/SiemensPLCClient.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/WCSClient/Siemens/SiemensPLCClient.cs"
@@ -3,6 +3,7 @@
using System.Net.NetworkInformation;
using WIDESEA_Comm.DataHandle;
using WIDESEA_Comm.LogInfo;
+using static FreeSql.Internal.GlobalFilter;
namespace WIDESEA_WCS.WCSClient
{
@@ -14,9 +15,12 @@
private readonly object _lockWrite = new object();
public SiemensS7Net siemensPLCClient { get; set; }
- public SiemensPLCClient()
+ public SiemensPLCClient(string model)
{
- siemensPLCClient = new SiemensS7Net(SiemensPLCS.S1200);
+ if (model == "S300")
+ siemensPLCClient = new SiemensS7Net(SiemensPLCS.S300);
+ else
+ siemensPLCClient = new SiemensS7Net(SiemensPLCS.S1500);
base.siemensPLCClient = this.siemensPLCClient;
}
@@ -48,6 +52,7 @@
siemensPLCClient.Port = Port;
siemensPLCClient.Slot = (byte)Slot;
siemensPLCClient.ConnectTimeOut = 1000 * 3;//瓒呮椂鏃堕棿
+ siemensPLCClient.ReceiveTimeOut = 1000 * 3;
siemensPLCClient.ConnectClose();
var coonRes = siemensPLCClient.ConnectServer();
IsConnected = coonRes.IsSuccess;
@@ -130,8 +135,11 @@
}
else if (typeof(DataType) == typeof(string))//瀛楃涓�
{
- var bytes = (byte[])GetContent(siemensPLCClient.Read(dbAddress, (ushort)len), dbAddress);
- string str = DataParse.GetStr(bytes, 0);
+ //var bytes = (byte[])GetContent(siemensPLCClient.Read(dbAddress, (ushort)len), dbAddress);
+ //string str = DataParse.GetStr(bytes, 0);
+ //return (DataType)(str as object);
+ var str = GetContent(siemensPLCClient.ReadString(dbAddress, (ushort)len), dbAddress).ToString();
+ str = str.Replace("\0", "")?.Replace("\\", "")?.Replace("\u0014", "")?.Replace("?\u0006", "")?.Replace("\n", "")?.Replace("?", "")?.Trim();
return (DataType)(str as object);
}
else
@@ -189,7 +197,7 @@
else if (typeof(DataType) == typeof(string))//瀛楃涓�
{
var str = GetContent(siemensPLCClient.ReadString(item.dbAddress, (ushort)item.dataLen), item).ToString();
- str = str.Replace("\0", "")?.Replace("\\", "")?.Replace("\u0014", "")?.Replace("?\u0006", "");
+ str = str.Replace("\0", "")?.Replace("\\", "")?.Replace("\u0014", "")?.Replace("?\u0006", "")?.Replace("\n", "")?.Replace("?", "")?.Trim();
return (DataType)(str as object);
}
else
@@ -253,6 +261,7 @@
if (!result.IsSuccess)
{
+ IsConnected = false;
WriteLog.Write_Log(PLCName, $"{PLCName}_Write", $"{dbAddress}鍐欏叆澶辫触," + result.Message);
throw new Exception($"{dbAddress}鍐欏叆澶辫触," + result.Message);
}
@@ -322,6 +331,7 @@
if (!result.IsSuccess)
{
+ IsConnected = false;
WriteLog.Write_Log(PLCName, $"{PLCName}_Write", $"{orderName}鍐欏叆澶辫触," + result.Message, item);
throw new Exception($"{PLCName},{orderName}鍐欏叆澶辫触," + result.Message);
}
--
Gitblit v1.9.3