Exemplo n.º 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();
        }
Exemplo n.º 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";
 }
Exemplo n.º 4
0
        private void SendTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            Interlocked.Increment(ref _currentIndex);

            if (_currentIndex <= Tasks.Count)
            {
                Tasks[_currentIndex].Start();

                ProgressAction(_currentIndex, TotalNumberOfTasks);
            }
            else
            {
                SendTimer.Stop();
            }
        }
Exemplo n.º 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();
        }
        private void SendMessage()
        {
            IsAutoMessage    = Auto_SendMessage.Checked;
            Protocol_Context = SendTextBox.Text.Trim();
            Send_Protocol();

            if (IsAutoMessage)
            {
                SendTimer.Start();
            }
            else
            {
                serialPort.Write(Sendbytes, 0, 8);
            }
        }
Exemplo n.º 7
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();
        }
Exemplo n.º 9
0
 private void Start()
 {
     try
     {
         Capturer                = new WasapiLoopbackCapture();
         TargetFormat            = new WaveFormat(16000, 8, 1);
         SendTimer               = Stopwatch.StartNew();
         Capturer.DataAvailable += (aud, args) =>
         {
             try
             {
                 if (args.BytesRecorded > 0)
                 {
                     lock (TempBuffer)
                     {
                         if (!SendTimer.IsRunning)
                         {
                             SendTimer.Restart();
                         }
                         TempBuffer.AddRange(args.Buffer.Take(args.BytesRecorded));
                         if (TempBuffer.Count > 200000)
                         {
                             SendTimer.Reset();
                             SendTempBuffer();
                         }
                         else if (SendTimer.Elapsed.TotalMilliseconds > 1000)
                         {
                             SendTimer.Reset();
                             SendTempBuffer();
                         }
                     }
                 }
             }
             catch
             {
             }
         };
         Capturer.StartRecording();
     }
     catch
     {
     }
 }
        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";
            }
        }
Exemplo n.º 11
0
        private void SetWriteTimeout(TimeSpan timeout, bool synchronous)
        {
            if (synchronous)
            {
                CancelSendTimer();

                // 0 == infinite for winsock timeouts, so we should preempt and throw
                if (timeout <= TimeSpan.Zero)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                              new TimeoutException(SR.Format(SR.TcpConnectionTimedOut, timeout)));
                }

                if (UpdateTimeout(_sendTimeout, timeout))
                {
                    lock (ThisLock)
                    {
                        ThrowIfNotOpen();
                        _socket.SendTimeout = TimeoutHelper.ToMilliseconds(timeout);
                    }
                    _sendTimeout = timeout;
                }
            }
            else
            {
                _sendTimeout = timeout;
                if (timeout == TimeSpan.MaxValue)
                {
                    CancelSendTimer();
                }
                else
                {
                    SendTimer.Change(timeout, TimeSpan.FromMilliseconds(-1));
                }
            }
        }
Exemplo n.º 12
0
 private void Stop()
 {
     Capturer?.StopRecording();
     SendTimer?.Reset();
 }
Exemplo n.º 13
0
 private void button1_Click(object sender, EventArgs e)
 {
     SendTimer.Start();
 }
Exemplo n.º 14
0
 private void Close_Btn_Click(object sender, EventArgs e)
 {
     serialPort1.Close();
     SendTimer.Stop();
 }
 private void SendTimer_Tick(object sender, EventArgs e)
 {
     SendTimer.Stop();
     serialPort.Write(Sendbytes, 0, 8);
     SendTimer.Start();
 }
Exemplo n.º 16
0
 private void button2_Click(object sender, EventArgs e)
 {
     SendTimer.Stop();
 }
Exemplo n.º 17
0
 private void Stop()
 {
     SendTimer.Stop();
     CloudButtonContent = "Push";
 }
Exemplo n.º 18
0
 public Form1()
 {
     InitializeComponent();
     SendTimer.Start();
     BaseRadio.Checked = true;
 }
 private void Stop()
 {
     SendTimer.Stop();
 }