static public void open(Config cfg, string portname) //从配置或名称传入 { if (portname != "socket") //若是串口 { cur_ds = dsdict[DSType.uart]; (cur_ds as DataSrc_uart).uart.PortName = portname; } else { cur_ds = dsdict[cfg.socket.type]; //若是网络 } cur_ds.open(cfg); }
private void btnConnCom_Click(object sender, RoutedEventArgs e) { var btn = sender as Button; try { if (btn.Content.ToString() == "打开端口") { DataSrc.open(config, comPort.Text); btn.Content = "关闭端口"; } else { btn.Content = "打开端口"; DataSrc.cur_ds.close(); } } catch { } }