usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;usingSystem.Net.Sockets;usingSystem.Threading;usingNModbus;usingSystem.Net;namespaceModbusTcp
{public partial classForm1 : Form
{private staticModbusFactory modbusFactory;//private static IModbusMaster master=null;
private staticIModbusMaster master;//写线圈或写寄存器数组
bool[] coilsBuffer;ushort[] registerBuffer;//参数(分别为站号,起始地址,长度)
byteslaveAddress;ushortstartAddress;ushortnumberOfPoints;stringfunctionCode;publicForm1()
{
InitializeComponent();
}///
///监听状态///
//private bool isConnected = false;
private void Form1_Load(objectsender, EventArgs e)
{//IPAddress address = new IPAddress(new byte[]{127,0,0,1});//TcpClient client = new TcpClient(address.ToString(), 502);
groupBox1.Enabled= false;
groupBox2.Enabled= false;
}private void comboBox1_SelectedIndexChanged(objectsender, EventArgs e)
{if (comboBox1.SelectedIndex >= 4)
{
groupBox2.Enabled= true;
groupBox1.Enabled= false;