using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Sockets; using System.Text; using System.Threading.Tasks; using Hanhe.iWCS.Common; namespace Hanhe.iWCS.TaizhouGEMTwoProtocol { internal class TcpHelper { public static bool Write(string ip,int port,int startAddr, byte[] dataToSend) { try { // 创建TCP客户端并连接到目标设备 using (TcpClient client = new TcpClient(ip, port)) { // 获取网络流 NetworkStream stream = client.GetStream(); // 发送数据 stream.Write(dataToSend, startAddr, dataToSend.Length); return true; } } catch(Exception ex) { CMMLog.Error("数据写入失败:"+ex.Message); } return false; } } }