上位机发送数据给PLC S71200

客户端

上位机发送数据给PLC S71200(后续删除此处示例)

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

 

using System.Net;

using System.Net.Sockets;

using System.Threading;

 

namespace ConsoleApplication4

{


class
Program

{


static
void Main(string[] args)

{


IPAddress ip = IPAddress.Parse(“192.168.0.1”);


Socket clientSocket = new
Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp );


try

{

clientSocket.Connect(new
IPEndPoint(ip,2000));


Console.WriteLine(服务器连接成功!”);

}


catch

{


Console.WriteLine(服务器连接失败!);


return;

}


byte[] sendmessage = new
byte[10];


for (int i= 0;i< 10;++i)

{

sendmessage[i] = Convert.ToByte(i);

}

clientSocket.Send(sendmessage);

clientSocket.Close();

 

}

}

}