一、安装Modbus包
二、创建modbushelper类
1、打开串口
public bool IfCOMOpend; //用于实例内的COM口的状态
public SerialPort OpenedCOM;//用于手动输入的COM转成SERIAL PORT
/// <summary>
/// 打开串口
/// </summary>
/// <param name="COMname">串口名称</param>
/// <param name="baudRate">波特率</param>/// <param name="parity">奇偶校验 (无,奇校验,偶校验)</param>
/// <param name="stopBits">停止位(1,2)</param>/// <param name="dataBits">数据位</param>
public bool OpenCOMPort(string COMname,string baudRate,string parity,string stopBits,string dataBits)
{
try
{Parity Comparity;
StopBits Comstopbits;
switch (parity)
{
case "无":
Comparity = Parity.None;
break;case "奇校验":
Comparity = Parity.Odd;
break;case "偶校验":
Comparity = Parity.Even;
break;
}switch (stopBits)
{
case "1":
Comstopbits = StopBits.One;
break;