예제 #1
0
    public static void onChoseToConnectDevice(string key)
    {
        if (DeviceName.Contains(key))
        {
            int temp = DeviceName.IndexOf(key);
//			if(temp==-1)
//				return;
            Debug.Log("!!!!!!!!   onChoseToConnectDevice in unity" + temp + "   " + key);
            _onChoseToConnectDevice(temp);
        }
    }
예제 #2
0
        private void button14_Click(object sender, EventArgs e)
        {
            string DeviceName;


            if (comboBox4.Text.Trim() != "")
            {
                try
                {
                    label12.Text    = "";
                    myport.PortName = comboBox4.Text.Trim();
                    if (!myport.IsOpen)
                    {
                        myport.Open();
                    }
                    myport.DiscardOutBuffer();     //خالی کردن بافر
                    myport.WriteLine("AT+cgmm\r"); //دستور شناخت مدل دستگاه
                    Thread.Sleep(1000);
                    DeviceName = myport.ReadExisting();
                    if (DeviceName.Contains("ERROR"))
                    {
                        MsgBox.ShowMessage(this.Handle.ToInt32(), "Device does not support this command or any other problem...", "خطا ", "تایید", "", "", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign);
                    }

                    else
                    {
                        //دستورات زیر برای بیرون کشیدن نام دستگاه از رشته خوانده شده از پورت هست
                        //(char)13 کاراکتر اینتر!
                        DeviceName = DeviceName.Remove(0, DeviceName.IndexOf((char)13)).Trim();
                        DeviceName = DeviceName.Substring(0, DeviceName.IndexOf((char)13));

                        MsgBox.ShowMessage(this.Handle.ToInt32(), "شناسایی با موفقیت انجام شد :" + Environment.NewLine + "Device Name:" + Environment.NewLine + DeviceName, "  ", "تایید", "", "", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign);


                        label12.Text = "نام دستگاه : " + DeviceName;
                        //button1.Enabled = true;
                    }
                    myport.DiscardOutBuffer();
                }
                catch (Exception ex)
                {
                    MsgBox.ShowMessage(this.Handle.ToInt32(), ex.Message.ToString(), " خطا", "تایید", "", "", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign);
                }
                finally
                {
                    //  myport.Close();
                }
            }
        }