示例#1
0
 private void btnBegin_Click(object sender, EventArgs e)
 {
     if (btnBegin.Text == "开始")
     {
         if (btnSerial.Text != "打开串口" || btnListen.Text != "开始监听")
         {
             Counter = int.Parse(Tim.Text) / 100;
             if (Counter < 1)
             {
                 Info     = "时间间隔过小";
                 Tim.Text = "1000";
                 Counter  = 10;
             }
             SendTimer.Start(); //开启定时器
             btnBegin.Text = "停止";
         }
         else
         {
             Info = "端口未打开!";
         }
     }
     else
     {
         SendTimer.Stop(); //停止定时器
         btnBegin.Text = "开始";
     }
 }
        private void Open_Btn_Click(object sender, EventArgs e)
        {
            serialPort1.PortName = comboBox1.Text.Trim();
            serialPort1.BaudRate = Convert.ToInt32(textBox1.Text.Trim());

            serialPort1.Open();
            SendTimer.Start();
        }
示例#3
0
 private void Start()
 {
     try
     {
         deviceClient = DeviceClient.Create(Properties.AzureSettings.Default.Host,
                                            new DeviceAuthenticationWithRegistrySymmetricKey(Properties.AzureSettings.Default.DeviceId,
                                                                                             Properties.AzureSettings.Default.AccessKey), TransportType.Mqtt);
     }
     catch { ErrorText = "Error: Can't create cloud client"; }
     SendTimer.Start();
     CloudButtonContent = "Stop";
 }
        private void SendMessage()
        {
            IsAutoMessage    = Auto_SendMessage.Checked;
            Protocol_Context = SendTextBox.Text.Trim();
            Send_Protocol();

            if (IsAutoMessage)
            {
                SendTimer.Start();
            }
            else
            {
                serialPort.Write(Sendbytes, 0, 8);
            }
        }
示例#5
0
        private void Client_Load(object sender, EventArgs e)
        {
            var items = new MenuItem[1];

            ReadCaps();
            items[0] = new MenuItem("Exit", ExitHandler);
            backgroundNotifyIcon.ContextMenu = new ContextMenu(items);
            backgroundNotifyIcon.Visible     = true;
            ConnectionTimer.Interval         = 2000;
            ConnectionTimer.Start();
            SendTimer.Interval      = 60000;
            GuiUpdateTimer.Interval = 5000;
            GuiUpdateTimer.Start();
            SendTimer.Start();
        }
示例#6
0
        private void Start()
        {
            try
            {
                ErrorText = "";
                X509Certificate  CaCert     = X509Certificate.CreateFromCertFile(Properties.AmazonSettings.Default.RootCA);
                X509Certificate2 ClientCert = new X509Certificate2(Properties.AmazonSettings.Default.DeviceCA, Properties.AmazonSettings.Default.DeviceCAPassword);
                string           ClientId   = Guid.NewGuid().ToString();

                IotClient = new MqttClient(Properties.AmazonSettings.Default.IotEndpoint, 8883, true, CaCert, ClientCert, MqttSslProtocols.TLSv1_2);

                IotClient.Connect(ClientId);
                SendTimer.Start();
                CloudButtonContent = "Stop";
            }
            catch (Exception ex) { ErrorText = "Error: Can't create cloud client"; }
        }
        private void SendTimer_Tick(object sender, EventArgs e)
        {
            SendTimer.Stop();

            try
            {
                string[] SendMessageContent = SendProtocol.Split(' ');
                for (int i = 0; i < 8; i++)
                {
                    SendByte[i] = Convert.ToByte(SendMessageContent[i], 16);
                }
                serialPort1.Write(SendByte, 0, SendByte.Length);
            }
            catch (Exception ex)
            {
                MessageBox.Show("发送错误");
            }
            SendTimer.Start();
        }
        private void Start(CloudType cloudType)
        {
            try
            {
                if (cloudType == CloudType.Test)
                {
                    string path = Path.GetRandomFileName();
                    path         = path.Replace(".", ""); // Remove period.
                    deviceClient = new DeviceClient("testdev", path);
                    System.Diagnostics.Process.Start("https://quickstart.internetofthings.ibmcloud.com/#/device/" + path);
                }
                else
                {
                    deviceClient = new DeviceClient(Properties.IBMWatsonsSettings.Default.OrgId,
                                                    Properties.IBMWatsonsSettings.Default.DeviceType,
                                                    Properties.IBMWatsonsSettings.Default.DeviceId, "token",
                                                    Properties.IBMWatsonsSettings.Default.AuthToken);
                }


                ErrorText = "";
                deviceClient.connect();
                deviceClient.subscribeCommand("testcmd", "json", 0);
                SendTimer.Start();
            }
            catch (Exception ex)
            {
                if (CloudButtonContent == "Stop")
                {
                    Stop();
                    TestButtonEnable   = true;
                    CloudButtonContent = "Push";
                }
                if (TestButtonContent == "Stop testing")
                {
                    Stop();
                    CloundButtonEnable = true;
                    TestButtonContent  = "Test connection";
                }
                ErrorText = "Error: Can't create cloud client";
            }
        }
 private void SendTimer_Tick(object sender, EventArgs e)
 {
     SendTimer.Stop();
     serialPort.Write(Sendbytes, 0, 8);
     SendTimer.Start();
 }
示例#10
0
 private void button1_Click(object sender, EventArgs e)
 {
     SendTimer.Start();
 }
示例#11
0
文件: Form1.cs 项目: Edin023/RobotArm
 public Form1()
 {
     InitializeComponent();
     SendTimer.Start();
     BaseRadio.Checked = true;
 }