| | |
| | | using System.Net.NetworkInformation; |
| | | using WIDESEA_Comm.DataHandle; |
| | | using WIDESEA_Comm.LogInfo; |
| | | using static FreeSql.Internal.GlobalFilter; |
| | | |
| | | namespace WIDESEA_WCS.WCSClient |
| | | { |
| | |
| | | siemensPLCClient.Port = Port; |
| | | siemensPLCClient.Slot = (byte)Slot; |
| | | siemensPLCClient.ConnectTimeOut = 1000 * 3;//è¶
æ¶æ¶é´ |
| | | siemensPLCClient.ReceiveTimeOut = 1000 * 3; |
| | | siemensPLCClient.ConnectClose(); |
| | | var coonRes = siemensPLCClient.ConnectServer(); |
| | | IsConnected = coonRes.IsSuccess; |
| | |
| | | } |
| | | 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("\u000e\u000e", "")?.Replace("\n", "")?.Replace("?", "")?.Trim(); |
| | | return (DataType)(str as object); |
| | | } |
| | | else |
| | |
| | | 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", "")?.Replace("\n","")?.Trim(); |
| | | str = str.Replace("\0", "")?.Replace("\\", "")?.Replace("\u0014", "")?.Replace("?\u0006", "")?.Replace("\n", "")?.Replace("?", "")?.Trim(); |
| | | return (DataType)(str as object); |
| | | } |
| | | else |
| | |
| | | |
| | | if (!result.IsSuccess) |
| | | { |
| | | IsConnected = false; |
| | | WriteLog.Write_Log(PLCName, $"{PLCName}_Write", $"{dbAddress}åå
¥å¤±è´¥," + result.Message); |
| | | throw new Exception($"{dbAddress}åå
¥å¤±è´¥," + result.Message); |
| | | } |
| | |
| | | |
| | | if (!result.IsSuccess) |
| | | { |
| | | IsConnected = false; |
| | | WriteLog.Write_Log(PLCName, $"{PLCName}_Write", $"{orderName}åå
¥å¤±è´¥," + result.Message, item); |
| | | throw new Exception($"{PLCName},{orderName}åå
¥å¤±è´¥," + result.Message); |
| | | } |