From 9d1660270272180cd71147d6ddd53d1382643d2e Mon Sep 17 00:00:00 2001
From: wenxiangchao <wenxiangchao@ihengxin.com.cn>
Date: 星期一, 02 十一月 2026 18:00:14 +0800
Subject: [PATCH] merge: 并入远程 Initial commit 作为历史根节点

---
 CellStepSender/TcpClientTool.cs |  104 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 104 insertions(+), 0 deletions(-)

diff --git a/CellStepSender/TcpClientTool.cs b/CellStepSender/TcpClientTool.cs
new file mode 100644
index 0000000..fb485a9
--- /dev/null
+++ b/CellStepSender/TcpClientTool.cs
@@ -0,0 +1,104 @@
+锘縰sing System;
+using System.Net;
+using System.Net.Sockets;
+using System.Text;
+using System.Threading;
+
+namespace CellStepSender
+{
+    public class TcpClientTool
+    {
+        private string _ip;
+        private int _port;
+        private bool _isConnected = false; // 鏄惁杩炴帴
+        private Socket _clientSocket; // 濂楁帴瀛�
+        private Thread _receiveThread = null; // 鎺ユ敹绾跨▼
+        private volatile bool needRecieve = true;
+
+        public event EventHandler<string> ExecuteMessageChanged;
+
+        public TcpClientTool(string ip, int port)
+        {
+            this._ip = ip;
+            this._port = port;
+        }
+
+        public void Connect()
+        {
+            try
+            {
+                _clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
+                IPAddress ipaddress = IPAddress.Parse(this._ip);
+                IPEndPoint endpoint = new IPEndPoint(ipaddress, _port);
+                _clientSocket.Connect(endpoint);
+                _isConnected = true;
+                _receiveThread = new Thread(Received);
+                _receiveThread.IsBackground = true;
+                _receiveThread.Start();
+            }
+            catch (Exception ex)
+            {
+                needRecieve = false;
+                _receiveThread?.Abort();
+                _receiveThread = null;
+                _clientSocket.Close();
+                _isConnected = false;
+                throw ex;
+            }
+        }
+
+        public void Disconnect()
+        {
+            needRecieve = false;
+            _clientSocket.Close();
+            _receiveThread?.Abort();
+            _receiveThread = null;
+            _isConnected = false;
+        }
+
+        public void Send(string data)
+        {
+            byte[] arrClientSendMsg = Encoding.UTF8.GetBytes(data);
+            _clientSocket.Send(arrClientSendMsg);
+        }
+
+        public void Received()
+        {
+            //while (needRecieve)
+            //{
+            //    byte[] arrRecMsg = new byte[1024 * 1024];
+            //    int length = _clientSocket.Receive(arrRecMsg);
+            //    string strRecMsg = Encoding.UTF8.GetString(arrRecMsg, 0, length);
+            //    ExecuteMessageChanged?.Invoke(this, strRecMsg);
+            //    Thread.Sleep(100);
+            //}
+        }
+
+
+        public bool SendStep(
+            string ip, int port,
+            int ovenIndex, int cellIndex, string step, string value, string limitUp,
+            string limitDown, string unit, string result, string updateTime, out string errorMsg)
+        {
+
+            errorMsg = null;
+            try
+            {
+                if (!_isConnected)
+                {
+                    errorMsg = "Not Connected";
+                    return false;
+                }
+
+                string msg = $"{ovenIndex};{cellIndex};{step},{value},{limitUp},{limitDown},{unit},{result},{updateTime}\n";
+                Send(msg);
+                return true;
+            }
+            catch (Exception ex)
+            {
+                errorMsg = ex.Message;
+                return false;
+            }
+        }
+    }
+}

--
Gitblit v1.9.1