ModBus-RTU通信测试平台

1.界面初始化

private void FrmModbusRtu_Load(object sender, EventArgs e)
        {
            this.lst_Info.Columns[1].Width = this.lst_Info.ClientSize.Width -         
            this.lst_Info.Columns[0].Width;
            //串口名
            string[] PortName = SerialPort.GetPortNames();
            this.cmb_Port.DataSource = PortName;
            this.cmb_Port.SelectedIndex = 0;
            //波特率
            this.cmb_Paud.DataSource = new string[] {"19200","38400","115200"};
            this.cmb_Paud.SelectedIndex = 0;
            //检验位
            this.cmb_Parity.DataSource = Enum.GetNames(typeof(Parity));
            this.cmb_Parity.SelectedIndex = 0;
            //停止位
            this.cmb_StopBits.DataSource = Enum.GetNames(typeof(StopBits));
            this.cmb_StopBits.SelectedIndex = 1;
            //数据格式
            this.cmb_DataFormat.DataSource = Enum.GetNames(typeof(dataFormeat));
            this.cmb_DataFormat.SelectedIndex = 0;
            //存储区域
            this.cmb_StoreArea.DataSource = Enum.GetNames(typeof(StoreArea));
            this.cmb_StoreArea.SelectedIndex = 0;
            this.cmb_VarType.DataSource = Enum.GetNames(typeof(VarType)); 
        }

2.串口参数设置

 if (IsConnected)
            {
                AddLog(1, "串口已经连接,请勿重复连接");
                return;
            }
            else
            {
                MyCom.PortName = this.cmb_Port.Text.Trim();
                MyCom.BaudRate = int.Parse(this.cmb_Paud.Text.Trim());
                MyCom.Parity = (Parity)(Enum.Parse(typeof(Parity), 
                this.cmb_Parity.Text.Trim(), false));
                MyCom.StopBits = (StopBits)(Enum.Parse(typeof(StopBits), 
                this.cmb_StopBits.Text.Trim(), false));
                modBusConfigHelper.OpenCom(MyCom);
                AddLog(0, "串口连接成功!");
                IsConnected = true;
            }

 3.串口关闭

            if(IsConnected)
            {
                mod
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值