Beispiel #1
0
        private void mainForm_Load(object sender, EventArgs e)
        {
            String connstr = @"Data Source=|DataDirectory|\data.db;Pooling=true;FailIfMissing=true";

            //初始化数据库
            if (false == System.IO.File.Exists(Application.StartupPath + @"\data.db"))
            {
                MessageBox.Show("缺少数据文件");
            }
            this.m_db = new dbdriver(connstr);

            //初始化html界面
            String url = Application.StartupPath + @"\assets\index.html";

            if (false == System.IO.File.Exists(url))
            {
                MessageBox.Show("缺少Assets下的界面文件");
            }
            else
            {
                this.m_webClient.Navigate(url);
                this.m_webClient.ObjectForScripting = this; // 可以js中可以通过 window.external. 访问 this中的方法
            }

            //初始化串口配置
            m_comSettingDlg = new ComSetting();
            m_comSettingDlg.LoadData(this.m_db);
            this.m_comClient = new SerialPortClient();
            this.m_comClient.Setting(m_comSettingDlg.GetComName(),
                                     m_comSettingDlg.GetBund(),
                                     m_comSettingDlg.GetDataBit(),
                                     m_comSettingDlg.GetStopBit(),
                                     m_comSettingDlg.GetParity()
                                     );
        }
Beispiel #2
0
        private static void readData(object obj)
        {
            SerialPortClient self = (SerialPortClient)obj;

            m_isRuning = true;
            Console.WriteLine("Com thread has start..");
            while (m_isRuning)
            {
                try
                {
                    string message = m_port.ReadLine();
                    message = message.Replace("\n", string.Empty);
                    message = message.Replace("\r", string.Empty);
                    if (message.Length > 0)
                    {
                        self.PushMessage(message);
                        Console.WriteLine("has recve message:" + message);
                    }
                }
                catch (TimeoutException) { }
            }
            m_port.Close();
        }