Пример #1
0
 private void Button1_Click(object sender, EventArgs e)
 {
     if (timer == null)
     {
         timer           = new System.Timers.Timer();
         timer.Interval  = Data.DataProcessingTimerInterval;
         timer.AutoReset = true;
         timer.Elapsed  += new System.Timers.ElapsedEventHandler(Timer_Tick);
     }
     if (timerLEDUpdate == null)
     {
         timerLEDUpdate           = new System.Timers.Timer();
         timerLEDUpdate.Interval  = Data.DataSendingTimerInterval;
         timerLEDUpdate.AutoReset = true;
         timerLEDUpdate.Elapsed  += new System.Timers.ElapsedEventHandler(TimerLEDUpdate_Tick);
     }
     if (timerVolumeUpdate == null)
     {
         timerVolumeUpdate           = new System.Timers.Timer();
         timerVolumeUpdate.Interval  = Data.DataVolumeProcessingTimerInterval;
         timerVolumeUpdate.AutoReset = true;
         timerVolumeUpdate.Elapsed  += new System.Timers.ElapsedEventHandler(TimerVolumeUpdate_Tick);
     }
     if (!timer.Enabled)
     {
         enumerator = new MMDeviceEnumerator();
         if (serialPort.IsOpen)
         {
             try
             {
                 ShowDeviceSettings = false;
                 byte[] array = SendCommandList.RequestAltData();
                 serialPort.Write(array, 0, (int)array.Length);
                 Thread.Sleep(200);
                 array = SendCommandList.ChangeBacklightModeCommand(0);
                 serialPort.Write(array, 0, (int)array.Length);
                 array = SendCommandList.SetBrightnessCommand(1);
                 serialPort.Write(array, 0, (int)array.Length);
             }
             catch { errorCount++; }
         }
         AudioFormat = new WaveFormat();
         SampleRate  = AudioFormat.SampleRate;
         if (Recorder != null)
         {
             Recorder.Dispose();
         }
         Recorder = new LoopbackRecorder(Data.BufferSize, true);
         Recorder.StartRecording();
         timer.Enabled              = true;
         timerLEDUpdate.Enabled     = true;
         timerVolumeUpdate.Enabled  = true;
         VisualizationOnButton.Text = "Выключить";
         bufferTrackBar.Enabled     = false;
     }
     else
     {
         if (serialPort.IsOpen)
         {
             try
             {
                 if (DeviceSettings != null)
                 {
                     byte[] array = SendCommandList.SetBrightnessCommand(DeviceSettings.BacklightBrightness);
                     serialPort.Write(array, 0, (int)array.Length);
                     array = SendCommandList.SetColourCommand(DeviceSettings.BacklightRed, DeviceSettings.BacklightGreen, DeviceSettings.BacklightBlue);
                     serialPort.Write(array, 0, (int)array.Length);
                     array = SendCommandList.ChangeBacklightModeCommand(DeviceSettings.BacklightMode);
                     serialPort.Write(array, 0, (int)array.Length);
                 }
             }
             catch { errorCount++; }
         }
         timer.Enabled             = false;
         timerLEDUpdate.Enabled    = false;
         timerVolumeUpdate.Enabled = false;
         enumerator.Dispose();
         Recorder.StopRecording();
         VisualizationOnButton.Text = "Включить";
         bufferTrackBar.Enabled     = true;
     }
 }
Пример #2
0
        private void CommanSentB_Click(object sender, EventArgs e)
        {
            switch (commandList.SelectedIndex)
            {
            case 0:
                if (serialPort.IsOpen)
                {
                    byte[] array = SendCommandList.SetColourCommand(textboxParam1.Text, textboxParam2.Text, textboxParam3.Text);
                    serialPort.Write(array, 0, (int)array.Length);
                }

                break;

            case 1:
                if (serialPort.IsOpen)
                {
                    byte[] array = SendCommandList.SetBrightnessCommand(textboxParam1.Text);
                    serialPort.Write(array, 0, (int)array.Length);
                }

                break;

            case 2:
                if (serialPort.IsOpen)
                {
                    byte[] array = SendCommandList.ChangeBacklightModeCommand(textboxParam1.Text);
                    serialPort.Write(array, 0, (int)array.Length);
                }

                break;

            case 3:
                if (serialPort.IsOpen)
                {
                    byte[] array = SendCommandList.CustomModeSetupCommand(textboxParam1.Text);
                    serialPort.Write(array, 0, (int)array.Length);
                }

                break;

            case 4:
                if (serialPort.IsOpen)
                {
                    byte[] array = SendCommandList.CustomModeDataCommand(textboxParam1.Text, textboxParam2.Text,
                                                                         textboxParam3.Text, textboxParam4.Text, textboxParam5.Text, textboxParam6.Text,
                                                                         textboxParam7.Text, textboxParam8.Text, textboxParam9.Text);
                    serialPort.Write(array, 0, (int)array.Length);
                }

                break;

            case 5:
                if (serialPort.IsOpen)
                {
                    byte[] array = SendCommandList.CustomModeCopyCommand(textboxParam1.Text, textboxParam2.Text);
                    serialPort.Write(array, 0, (int)array.Length);
                }

                break;

            case 6:
                if (serialPort.IsOpen)
                {
                    byte[] array = SendCommandList.SaveCommand(textboxParam1.Text);
                    serialPort.Write(array, 0, (int)array.Length);
                }

                break;

            case 7:
                using (MemoryStream stream = new MemoryStream())
                {
                    using (BinaryWriter binWriter = new BinaryWriter(stream))
                    {
                        binWriter.Write((byte)0x2D);
                        binWriter.Write((byte)0x2D);
                        binWriter.Write((byte)0x62);
                        binWriter.Write((byte)0x6D);
                        binWriter.Write(Convert.ToSingle(textboxParam1.Text));
                        serialPort.Write(stream.ToArray(), 0, (int)stream.Length);
                    }
                }

                break;

            case 8:
                if (serialPort.IsOpen)
                {
                    byte[] array = SendCommandList.ResetCommand();
                    serialPort.Write(array, 0, (int)array.Length);
                }

                break;

            case 9:
                if (serialPort.IsOpen)
                {
                    byte[] array = SendCommandList.CalibrationRunCommand(textboxParam1.Text);
                    serialPort.Write(array, 0, (int)array.Length);
                }

                break;

            case 10:
                if (serialPort.IsOpen)
                {
                    byte[] array = SendCommandList.SetTXControlCommand(textboxParam1.Text);
                    serialPort.Write(array, 0, (int)array.Length);
                }

                break;

            case 11:
                if (serialPort.IsOpen)
                {
                    ShowDeviceSettings = true;
                    byte[] array = SendCommandList.RequestAltData();
                    serialPort.Write(array, 0, (int)array.Length);
                }

                break;
            }
        }