示例#1
0
 /// <summary>
 /// 打开串口
 /// </summary>
 /// <returns></returns>
 public int open()
 {
     if (!serialUtil.IsOpen())
     {
         SerialConfig config = serialConfigDAL.get();
         return(serialUtil.open(config.PortName,
                                config.BaudRate,
                                config.DataBits,
                                config.Parity,
                                config.StopBits));
     }
     return(0);
 }
示例#2
0
        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            //页面数据初始化
            l_portName.Content     = parentWindow.resource.PortName;
            l_baudRate.Content     = parentWindow.resource.BaudRate;
            l_dataBits.Content     = parentWindow.resource.DataBits;
            l_parity.Content       = parentWindow.resource.Parity;
            l_stopBits.Content     = parentWindow.resource.StopBits;
            btn_saveConfig.Content = parentWindow.resource.Save;
            btn_lastPage.Content   = parentWindow.resource.LastPage;
            btn_indexPage.Content  = parentWindow.resource.IndexPage;

            //端口号
            List <string> portList = parentWindow.eleTagController.getSerialList();

            cb_portList.ItemsSource = portList;
            //波特率
            List <string> baudRateList = new List <string>()
            {
                "9600", "19200", "38400", "115200"
            };

            cb_baudRateList.ItemsSource = baudRateList;
            //数据位
            List <string> dataBitsList = new List <string>()
            {
                "5", "6", "7", "8"
            };

            cb_dataBitsList.ItemsSource = dataBitsList;
            //校验位
            List <string> parityList = new List <string>()
            {
                "None", "Even", "Odd", "Mark", "Space"
            };

            cb_parityList.ItemsSource = parityList;
            //停止位
            List <string> stopBitsList = new List <string>()
            {
                "1", "1.5", "2"
            };

            cb_stopBitsList.ItemsSource = stopBitsList;

            config = serialConfig.get();
            //g_config.DataContext = config;

            if (config.PortName != "")
            {
                cb_portList.Text = config.PortName;
            }
            if (config.BaudRate > 0)
            {
                cb_baudRateList.Text = config.BaudRate.ToString();
            }
            if (config.DataBits > 0)
            {
                cb_dataBitsList.Text = config.DataBits.ToString();
            }
            if (config.Parity != "")
            {
                cb_parityList.Text = config.Parity;
            }
            if (config.StopBits != "")
            {
                cb_stopBitsList.Text = config.StopBits;
            }
        }