1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
| 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;
| }
| }
| }
|
|