Exemplo n.º 1
0
 private void RxAltDataActions(object sender, RxAltDataArgs e)
 {
     if (ShowDeviceSettings)
     {
         string str = "ETX Mode = " + e.ETXMode.ToString() +
                      "\r\nNo Load Current Limit = " + e.NoLoadCurrent.ToString() +
                      "\r\nLED Enable = " + e.LEDState.ToString() +
                      "\r\nBacklight Mode = " + e.BacklightMode.ToString() +
                      "\r\nBacklight Red = " + e.BacklightRed.ToString() +
                      "\r\nBacklight Green = " + e.BacklightGreen.ToString() +
                      "\r\nBacklight Blue = " + e.BacklightBlue.ToString() +
                      "\r\nBacklight Brightness = " + e.BacklightBrightness.ToString() +
                      "\r\nBrightness Multiplier = " + e.BrightnessMultiplier;
         Thread t = new Thread(() => AltDataMessageBox(str));
         t.Start();
     }
     else
     {
         DeviceSettings = e;
     }
 }
Exemplo n.º 2
0
        private bool FindData()
        {
            bool found   = false;
            bool altData = false;

            for (; ;)
            {
                int   start = 0, end = 0;
                float currentData, temperatureData, voltageData;
                byte  buttonData;
                for (int i = 0; i < buffer.Length - 1; i++)
                {
                    if ((buffer[i] == 0xFA) && (buffer[i + 1] == 0xFE))
                    {
                        start = i + 2;
                    }
                    else if ((buffer[i] == 0xFB) && (buffer[i + 1] == 0xFE))
                    {
                        start = i + 2; altData = true;
                    }
                    if ((buffer[i] == 13) && (buffer[i + 1] == 10))
                    {
                        end = i - 1; break;
                    }
                }
                if (start < end)
                {
                    using (MemoryStream stream = new MemoryStream(buffer, start, end))
                    {
                        using (BinaryReader binReader = new BinaryReader(stream))
                        {
                            if (!altData && (end - start) >= 12)
                            {
                                currentData     = binReader.ReadSingle();
                                temperatureData = binReader.ReadSingle();
                                buttonData      = binReader.ReadByte();
                                voltageData     = binReader.ReadSingle();
                                OnMainDataReady?.Invoke(this, new RxMainDataArgs(temperatureData, currentData, voltageData, buttonData));
                            }
                            else if (altData && (end - start) >= 26)
                            {
                                RxAltDataArgs args = new RxAltDataArgs();
                                args.ETXMode              = binReader.ReadByte();
                                args.NoLoadCurrent        = binReader.ReadSingle();
                                args.LEDState             = binReader.ReadByte();
                                args.BacklightMode        = binReader.ReadByte();
                                args.BacklightRed         = binReader.ReadSingle();
                                args.BacklightGreen       = binReader.ReadSingle();
                                args.BacklightBlue        = binReader.ReadSingle();
                                args.BacklightBrightness  = binReader.ReadSingle();
                                args.BrightnessMultiplier = binReader.ReadSingle();
                                OnAltDataReady?.Invoke(this, args);
                            }
                        }
                    }
                    found = true;
                    Array.Copy(buffer, end + 3, buffer, 0, buffer.Length - (end + 3));
                    endIndex -= end + 3;
                }
                else
                {
                    break;
                }
            }
            return(found);
        }