Example #1
0
        public void FindSCI()
        {
            for (int i = 0; i < SCIPorts.Length; i++)
            {
                sci = new SCI(SCIPorts[i], 115200);
                if (sci.SCIOpen())
                {
                    sci.SCISendFrameData(ref userShake);

                    Thread.Sleep(500);
                    if (sci.SCIReceiveData(ref recvData))
                    {
                        if (recvData.Length == 0 || !System.Text.Encoding.Default.GetString(recvData).Contains("I am an KL36"))
                        {
                            sci.Close();
                            continue;
                        }
                        if (System.Text.Encoding.Default.GetString(recvData).Contains("I am an KL36"))   //记录UART_User串口的Com号
                        {
                            PublicVar.g_SCIComNum = SCIPorts[i];
                            sci.Close();
                            break;                                                              //找到UART_User串口后,跳出循环
                        }
                    }
                }
            }
        }
Example #2
0
 public void UartConfrim()
 {
     sci = new SCI(PublicVar.g_SCIComNum, PublicVar.g_SCIBaudRate);
     if (sci.SCIOpen())
     {
         sci.SCISendFrameData(ref uartON);
     }
     sci.Close();
 }
Example #3
0
 public UC_ADC()
 {
     InitializeComponent();
     sci = new SCI(PublicVar.g_SCIComNum, PublicVar.g_SCIBaudRate);
     if (sci.SCIOpen())
     {
         sci.SCISendFrameData(ref uartOFF);
     }
     sci.Close();
 }
Example #4
0
        ///-----------------------------------------------------------------
        /// <summary>
        /// 对    象:SCIPort
        /// 事    件:DataReceived
        /// 功    能:串口接收数据
        /// 函数调用:(1)SCIReceiveData,串口接收函数
        ///          (2)SCIUpdateRevtxtbox,更新文本框中的内容
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        ///-----------------------------------------------------------------
        private void SCIPort_DataReceived(object sender,
                                          System.IO.Ports.SerialDataReceivedEventArgs e)
        {
            String str = String.Empty;
            bool   Flag;//标记串口接收数据是否成功

            byte[] ch2 = new byte[2];
            //ComDevice.Encoding = System.Text.Encoding.GetEncoding("GB2312");

            //调用串口接收函数,并返回结果
            Flag = sci.SCIReceiveData(ref PublicVar.g_ReceiveByteArray);
            if (Flag == true)//串口接收数据成功
            {
                str = Encoding.GetEncoding("GB2312").GetString(PublicVar.g_ReceiveByteArray);
                SCIUpdateRevtxtbox(textBox1, str);
                sci.Close();
            }
        }
Example #5
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (this.comboBox1.Text != "")
     {
         PublicVar.g_SCIBaudRate = int.Parse(this.comboBox1.Text);
         button1.Visible         = true;
     }
     sci = new SCI(PublicVar.g_SCIComNum, PublicVar.g_SCIBaudRate);
     if (sci.SCIOpen())//串口打开成功
     {
         this.label3.Text  = "已选择波特率为:" + comboBox1.Text + "\n";
         this.label3.Text += "设备可以正常连接,开始实验吧!";
         PublicVar.g_Uflag = 1;
         sci.SCISendFrameData(ref finshShake);
         sci.Close();
     }
 }
Example #6
0
 private void UC_ADC_Leave(object sender, EventArgs e)
 {
     sci.Close();
 }