using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CanAerospaceCore;

using FTD2XX_NET;
using System.Threading;


namespace WindowsFormsApplication2
{
   
    public partial class Form1 : Form
    {
        public enum WeaponRegister : byte
        {
            HwName = 0, // uchar 4 bytes
            SerialNumber = 1, // uchar 4 bytes
            BaseAddress = 2, // uchar 1 byte
            ProductionYear = 3, // uchar 1 byte
            AccOffsetX = 200, // float
            AccOffsetY = 201, // float
            AccOffsetZ = 202, // float
            //
            TotalShots = 40,
            Powerons = 254,
        };
        public enum GLOCK_WeaponRegister : byte
        {
            BoltCatches = 42,
            TresholdLow = 29,
            TresholdHigh = 30,
            TriggerRelease = 31,
            TriggerHold = 32,
        };
        public enum MP5_WeaponRegister : byte
        {
            TresholdLow = 29,
            TresholdHigh = 30,
            SensorMin = 33,
            SensorMax = 34,
            HallMax = 35,
            HalfRange = 36,
            PeakFilter = 37,
        };
        public enum AK103_WeaponRegister : byte
        {
            TresholdLow = 29,
            TresholdHigh = 30,
            VoltOffset = 33,
            DAGain = 34,
            RS100m = 100,
            RS200m = 101,
            RS300m = 102,
            RS400m = 103,
            RS500m = 104,
            RS600m = 105,
            RS700m = 106,
            RS800m = 107,
        };
        public enum GP34_WeaponRegister : byte
        {
            Trigger1Low = 29,
            Trigger1High = 30,
            Trigger2Low = 33,
            Trigger2High = 34,
            RS0m = 100,
            RS100m = 101,
            RS150m = 102,
            RS200m = 103,
            RS250m = 104,
            RS300m = 105,
            RS350m = 106,
            RS400m = 107,
            RSx350m = 108,
            RSx300m = 109,
            RSx250m = 110,
            RSx200m = 111,
        };
        public enum BROWN_WeaponRegister : byte
        {
            BoltCatches = 42,
            TresholdLow = 29,
            TresholdHigh = 30,
            TriggerRelease = 31,
            TriggerHold = 32,
        };
        public enum COYOTE_WeaponRegister : byte
        {
            TresholdLow = 29,
            TresholdHigh = 30,
            TriggerRelease = 31,
            TriggerHold = 32,
            TriggerDAOffset = 33,
            BoltLockTreshold = 100,
            BoltUnlockTreshold = 101,
            FiringPinTreshold = 102,
            FiringPinDAOffset = 103,
            SafeTreshold = 104,
            SafeDAOffset = 105,
        };
        public enum G3_WeaponRegister : byte
        {
            TresholdLow = 29,
            TresholdHigh = 30,
            Sensor1aLow = 33,
            Sensor1aHigh = 34,
            Sensor1bLow = 35,
            Sensor1bHigh = 36,
        };
        public enum G36_WeaponRegister : byte
        {
            TresholdLow = 29,
            TresholdHigh = 30,
            Sensor1aLow = 33,
            Sensor1aHigh = 34,
            Sensor1bLow = 35,
            Sensor1bHigh = 36,
        };
        public enum LRT3_WeaponRegister : byte
        {
            TresholdLow = 29,
            TresholdHigh = 30,
            TriggerRelease = 31,
            TriggerHold = 32,
            TriggerDAOffset = 33,
            BoltLockTreshold = 100,
            BoltUnlockTreshold = 101,
            FiringPinTreshold = 102,
            FiringPinDAOffset = 103,
            SafeTreshold = 104,
            SafeDAOffset = 105,
        };
        public enum M60_WeaponRegister : byte
        {
            BeltReloads = 71,
            TresholdLow = 29,
            TresholdHigh = 30,
            HS3Release = 33,
            HS3Hold = 34,
            TempDown = 60,
            TempUp = 61,
            MaxLedPWM = 62,
            DownStep1 = 63,
            DownStep2 = 64,
            DownStep3 = 65,
            UpStep1 = 66,
            UpStep2 = 67,
            UpStep3 = 68,
        };
        public enum MG3_WeaponRegister : byte
        {
            BeltReloads = 71,
            TresholdLow = 29,
            TresholdHigh = 30,
            HS3Release = 33,
            HS3Hold = 34,
            TempDown = 60,
            TempUp = 61,
            MaxLedPWM = 62,
            DownStep1 = 63,
            DownStep2 = 64,
            DownStep3 = 65,
            UpStep1 = 66,
            UpStep2 = 67,
            UpStep3 = 68,
        };
        public enum RPG7_WeaponRegister : byte
        {
            TresholdLow = 29,
            TresholdHigh = 30,
            VoltOffset = 33,
            DAGain = 34,
        };
        public enum TIMBER_WeaponRegister : byte
        {
            TresholdLow = 29,
            TresholdHigh = 30,
            TriggerRelease = 31,
            TriggerHold = 32,
            TriggerDAOffset = 33,
            BoltLockTreshold = 100,
            BoltUnlockTreshold = 101,
            FiringPinTreshold = 102,
            FiringPinDAOffset = 103,
            SafeTreshold = 104,
            SafeDAOffset = 105,
        };
        public enum RezervaA_WeaponRegister : byte
        {
            BoltCatches = 42,
            TresholdLow = 29,
            TresholdHigh = 30,
            TriggerRelease = 31,
            TriggerHold = 32,
        };
        public enum RezervaB_WeaponRegister : byte
        {
            BoltCatches = 42,
            TresholdLow = 29,
            TresholdHigh = 30,
            TriggerRelease = 31,
            TriggerHold = 32,
        };

        public string HwName;
        public string SerialNumber;
        public byte BaseAddress;
        public int ProductionYear;
        public float AccOffsetX;
        public float AccOffsetY;
        public float AccOffsetZ;
        public string HwVersion;
        public string SwVersion;
        //
        public uint TotalShots;
        public uint Powerons;
        //---glock
        public uint BoltCatches;
        public byte TresholdLow;
        public byte TresholdHigh;
        public short TriggerRelease;
        public short TriggerHold;
        //---mp5
        //public byte TresholdLow;
        //public byte TresholdHigh;
        public short SensorMin;
        public short SensorMax;
        public short HallMax;
        public short HalfRange;
        public short PeakFilter;
        //---ak103
        //public byte TresholdLow;
        //public byte TresholdHigh;
        public short VoltOffset;
        public short DAGain;
        public short RS100m;
        public short RS200m;
        public short RS300m;
        public short RS400m;
        public short RS500m;
        public short RS600m;
        public short RS700m;
        public short RS800m;
        //---gp34
        public byte Trigger1Low;
        public byte Trigger1High;
        public byte Trigger2Low;
        public byte Trigger2High;
        public short RS0m;
        //public short RS100m;
        public short RS150m;
        //public short RS200m;
        public short RS250m;
        //public short RS300m;
        public short RS350m;
        //public short RS400m;
        public short RSx350m;
        public short RSx300m;
        public short RSx250m;
        public short RSx200m;
        //---brown
        //public uint BoltCatches;
        //public byte TresholdLow;
        //public byte TresholdHigh;
        //public short TriggerRelease;
        //public short TriggerHold;
        //---coyote
        //public byte TresholdLow;
        //public byte TresholdHigh;
        //public short TriggerRelease;
        //public short TriggerHold;
        public short TriggerDAOffset;
        public short BoltLockTreshold;
        public short BoltUnlockTreshold;
        public short FiringPinTreshold;
        public short FiringPinDAOffset;
        public short SafeTreshold;
        public short SafeDAOffset;
        //---g3
        //public byte TresholdLow;
        //public byte TresholdHigh;
        public short Sensor1aLow;
        public short Sensor1aHigh;
        public short Sensor1bLow;
        public short Sensor1bHigh;
        //---g36
        //public byte TresholdLow;
        //public byte TresholdHigh;
        //public short Sensor1aLow;
        //public short Sensor1aHigh;
        //public short Sensor1bLow;
        //public short Sensor1bHigh;
        //---lrt3
        //public byte TresholdLow;
        //public byte TresholdHigh;
        //public short TriggerRelease;
        //public short TriggerHold;
        //public short TriggerDAOffset;
        //public short BoltLockTreshold;
        //public short BoltUnlockTreshold;
        //public short FiringPinTreshold;
        //public short FiringPinDAOffset;
        //public short SafeTreshold;
        //public short SafeDAOffset;
        //---m60
        public uint BeltReloads;
        //public byte TresholdLow;
        //public byte TresholdHigh;
        public short HS3Release;
        public short HS3Hold;
        public short TempDown;
        public short TempUp;
        public short MaxLedPWM;
        public short DownStep1;
        public short DownStep2;
        public short DownStep3;
        public short UpStep1;
        public short UpStep2;
        public short UpStep3;
        //---mg3
        //public uint BeltReloads;
        //public byte TresholdLow;
        //public byte TresholdHigh;
        //public short HS3Release;
        //public short HS3Hold;
        //public short TempDown;
        //public short TempUp;
        //public short MaxLedPWM;
        //public short DownStep1;
        //public short DownStep2;
        //public short DownStep3;
        //public short UpStep1;
        //public short UpStep2;
        //public short UpStep3;
        //---rpg7
        //public byte TresholdLow;
        //public byte TresholdHigh;
        //public short VoltOffset;
        //public short DAGain;
        //---timber
        //public byte TresholdLow;
        //public byte TresholdHigh;
        //public short TriggerRelease;
        //public short TriggerHold;
        //public short TriggerDAOffset;
        //public short BoltLockTreshold;
        //public short BoltUnlockTreshold;
        //public short FiringPinTreshold;
        //public short FiringPinDAOffset;
        //public short SafeTreshold;
        //public short SafeDAOffset;
        //---RezervaA
        //public uint BoltCatches;
        //public byte TresholdLow;
        //public byte TresholdHigh;
        //public short TriggerRelease;
        //public short TriggerHold;
        //---RezervaB
        //public uint BoltCatches;
        //public byte TresholdLow;
        //public byte TresholdHigh;
        //public short TriggerRelease;
        //public short TriggerHold;

        //---accelerometer
        public short axis_x_raw_data;
        public short axis_y_raw_data;
        public short axis_z_raw_data;
        public int num_of_samples = 10;
        public float axis_x_g_value;
        public float axis_y_g_value;
        public float axis_z_g_value;
        public float actual_pitch_angle;
        public float actual_roll_angle;
        public float temp_x_g_value = 0;
        public float temp_y_g_value = 0;
        public float temp_z_g_value = 0;
        public int idx = 0;
        public bool idx1 = false;
        public bool idx2 = false;

        //---mainform
        public ulong RxCounter = 0;
        public Form ActiveForm2 = null;

        //---timer
        public MyCanAerospace canConnection;
        public CommunicatorZmq zmqCommunicator;
        bool wasDisconected = true;


        public Form1()
        {
            string filePath = System.IO.Path.Combine(Environment.CurrentDirectory, "CanAerospace");
            filePath = System.IO.Path.Combine(filePath, "server_bin");
            filePath = System.IO.Path.Combine(filePath, "CanAerospaceServer.exe");
            System.Diagnostics.Process.Start(filePath); 
            //System.Diagnostics.Process.Start(@"\CanAerospace\server_bin\CanAerospaceServer.exe");
            Thread.Sleep(7000);

            InitializeComponent();

            try
            {
                wasDisconected = false;
                // MyCanAerospace 
                canConnection = new MyCanAerospace();
                string requesterAddress = "tcp://localhost:5555";
                string subscriberAddress = "tcp://localhost:5556";

                //CommunicatorZmq 
                zmqCommunicator = new CommunicatorZmq(subscriberAddress, requesterAddress);

                zmqCommunicator.Init();
                canConnection.Init(zmqCommunicator);


                uint weaponChannel = 100;

                //------prepnutie do service mode
                if (canConnection.CyclicValueStorage.Keys.Count == 0) 
                {
                    if (canConnection.IsServerOnline())
                    {
                        if (canConnection.IsDeviceOpen())
                        {
                            canConnection.SendResetDevice();
                            Thread.Sleep(3000);
                        }
                    }
                }

                if (canConnection.IsServerOnline())
                {
                    if (canConnection.IsDeviceOpen())
                    {
                        RxCounter = RxCounter + 1;

                        //------zistenie NodeId (aka zbran) z cyklicky vysielanych dat
                        byte weaponNodeId = canConnection.CyclicValueStorage.Keys.ToArray()[0].nodeId;

                        //------vycitanie zakladnych registrov
                        foreach (WeaponRegister register in Enum.GetValues(typeof(WeaponRegister)))
                        {
                            for (int attempts = 0; attempts < 3; attempts++)
                            {
                                canConnection.SendRegisterReadRequest(weaponChannel, weaponNodeId, (byte)register);
                                RegisterKey regKey = new RegisterKey(weaponNodeId, (byte)register);
                                CanData registerData = null;
                                Thread.Sleep(1000);
                                if (canConnection.GetRegisterValue(regKey, out registerData) &&
                                    registerData.GetDataType() != CanData.DataType.DT_NODATA)
                                {
                                    switch (register)
                                    {
                                        case (WeaponRegister.HwName):
                                            HwName = registerData.GetAsAchar4();
                                            break;

                                        case (WeaponRegister.SerialNumber):
                                            SerialNumber = registerData.GetAsAchar4();
                                            break;

                                        case (WeaponRegister.BaseAddress):
                                            BaseAddress = registerData.GetAsUchar();
                                            break;

                                        case (WeaponRegister.ProductionYear):
                                            ProductionYear = Convert.ToInt32(registerData.GetAsUshort());
                                            break;

                                        case (WeaponRegister.AccOffsetX):
                                            AccOffsetX = registerData.GetAsFloat();
                                            break;

                                        case (WeaponRegister.AccOffsetY):
                                            AccOffsetY = registerData.GetAsFloat();
                                            break;

                                        case (WeaponRegister.AccOffsetZ):
                                            AccOffsetZ = registerData.GetAsFloat();
                                            break;

                                        case (WeaponRegister.TotalShots):
                                            TotalShots = registerData.GetAsUlong();
                                            break;

                                        case (WeaponRegister.Powerons):
                                            Powerons = registerData.GetAsUlong();
                                            break;

                                    }
                                    break;
                                }
                                // pockat pred dalsim pokusom
                                Thread.Sleep(100);
                            }
                            RxCounter = RxCounter + 1;
                        }

                        //------vycitanie specialnych registrov
                        if (weaponNodeId == 2) //glock
                        {
                            foreach (GLOCK_WeaponRegister register in Enum.GetValues(typeof(GLOCK_WeaponRegister)))
                            {
                                for (int attempts = 0; attempts < 3; attempts++)
                                {
                                    canConnection.SendRegisterReadRequest(weaponChannel, weaponNodeId, (byte)register);
                                    RegisterKey regKey = new RegisterKey(weaponNodeId, (byte)register);
                                    CanData registerData = null;
                                    Thread.Sleep(1000);
                                    if (canConnection.GetRegisterValue(regKey, out registerData) &&
                                        registerData.GetDataType() != CanData.DataType.DT_NODATA)
                                    {
                                        switch (register)
                                        {
                                            case (GLOCK_WeaponRegister.BoltCatches):
                                                BoltCatches = registerData.GetAsUlong();
                                                break;

                                            case (GLOCK_WeaponRegister.TresholdLow):
                                                TresholdLow = registerData.GetAsUchar();
                                                break;

                                            case (GLOCK_WeaponRegister.TresholdHigh):
                                                TresholdHigh = registerData.GetAsUchar();
                                                break;

                                            case (GLOCK_WeaponRegister.TriggerRelease):
                                                TriggerRelease = registerData.GetAsShort();
                                                break;

                                            case (GLOCK_WeaponRegister.TriggerHold):
                                                TriggerHold = registerData.GetAsShort();
                                                break;

                                        }
                                        break;
                                    }
                                    // pockat pred dalsim pokusom
                                    Thread.Sleep(100);
                                }
                                RxCounter = RxCounter + 1;
                            }
                        }

                        if (weaponNodeId == 132) //mp5
                        {
                            foreach (MP5_WeaponRegister register in Enum.GetValues(typeof(MP5_WeaponRegister)))
                            {
                                for (int attempts = 0; attempts < 3; attempts++)
                                {
                                    canConnection.SendRegisterReadRequest(weaponChannel, weaponNodeId, (byte)register);
                                    RegisterKey regKey = new RegisterKey(weaponNodeId, (byte)register);
                                    CanData registerData = null;
                                    Thread.Sleep(1000);
                                    if (canConnection.GetRegisterValue(regKey, out registerData) &&
                                        registerData.GetDataType() != CanData.DataType.DT_NODATA)
                                    {
                                        switch (register)
                                        {
                                            case (MP5_WeaponRegister.TresholdLow):
                                                TresholdLow = registerData.GetAsUchar();
                                                break;

                                            case (MP5_WeaponRegister.TresholdHigh):
                                                TresholdHigh = registerData.GetAsUchar();
                                                break;

                                            case (MP5_WeaponRegister.SensorMin):
                                                SensorMin = registerData.GetAsShort();
                                                break;

                                            case (MP5_WeaponRegister.SensorMax):
                                                SensorMax = registerData.GetAsShort();
                                                break;

                                            case (MP5_WeaponRegister.HallMax):
                                                HallMax = registerData.GetAsShort();
                                                break;

                                            case (MP5_WeaponRegister.HalfRange):
                                                HalfRange = registerData.GetAsShort();
                                                break;

                                            case (MP5_WeaponRegister.PeakFilter):
                                                PeakFilter = registerData.GetAsShort();
                                                break;
                                        }
                                        break;
                                    }
                                    // pockat pred dalsim pokusom
                                    Thread.Sleep(100);
                                }
                                RxCounter = RxCounter + 1;
                            }
                        }

                        if (weaponNodeId == 139) //ak103
                        {
                            foreach (AK103_WeaponRegister register in Enum.GetValues(typeof(AK103_WeaponRegister)))
                            {
                                for (int attempts = 0; attempts < 3; attempts++)
                                {
                                    canConnection.SendRegisterReadRequest(weaponChannel, weaponNodeId, (byte)register);
                                    RegisterKey regKey = new RegisterKey(weaponNodeId, (byte)register);
                                    CanData registerData = null;
                                    Thread.Sleep(1000);
                                    if (canConnection.GetRegisterValue(regKey, out registerData) &&
                                        registerData.GetDataType() != CanData.DataType.DT_NODATA)
                                    {
                                        switch (register)
                                        {
                                            case (AK103_WeaponRegister.TresholdLow):
                                                TresholdLow = registerData.GetAsUchar();
                                                break;

                                            case (AK103_WeaponRegister.TresholdHigh):
                                                TresholdHigh = registerData.GetAsUchar();
                                                break;

                                            case (AK103_WeaponRegister.VoltOffset):
                                                VoltOffset = registerData.GetAsShort();
                                                break;

                                            case (AK103_WeaponRegister.DAGain):
                                                DAGain = registerData.GetAsShort();
                                                break;

                                            case (AK103_WeaponRegister.RS100m):
                                                RS100m = registerData.GetAsShort();
                                                break;

                                            case (AK103_WeaponRegister.RS200m):
                                                RS200m = registerData.GetAsShort();
                                                break;
                                            case (AK103_WeaponRegister.RS300m):
                                                RS300m = registerData.GetAsShort();
                                                break;
                                            case (AK103_WeaponRegister.RS400m):
                                                RS400m = registerData.GetAsShort();
                                                break;
                                            case (AK103_WeaponRegister.RS500m):
                                                RS500m = registerData.GetAsShort();
                                                break;
                                            case (AK103_WeaponRegister.RS600m):
                                                RS600m = registerData.GetAsShort();
                                                break;
                                            case (AK103_WeaponRegister.RS700m):
                                                RS700m = registerData.GetAsShort();
                                                break;
                                            case (AK103_WeaponRegister.RS800m):
                                                RS800m = registerData.GetAsShort();
                                                break;

                                        }
                                        break;
                                    }
                                    // pockat pred dalsim pokusom
                                    Thread.Sleep(100);
                                }
                                RxCounter = RxCounter + 1;
                            }
                        }

                        if (weaponNodeId == 150) //gp34
                        {
                            foreach (GP34_WeaponRegister register in Enum.GetValues(typeof(GP34_WeaponRegister)))
                            {
                                for (int attempts = 0; attempts < 3; attempts++)
                                {
                                    canConnection.SendRegisterReadRequest(weaponChannel, weaponNodeId, (byte)register);
                                    RegisterKey regKey = new RegisterKey(weaponNodeId, (byte)register);
                                    CanData registerData = null;
                                    Thread.Sleep(1000);
                                    if (canConnection.GetRegisterValue(regKey, out registerData) &&
                                        registerData.GetDataType() != CanData.DataType.DT_NODATA)
                                    {
                                        switch (register)
                                        {
                                            case (GP34_WeaponRegister.Trigger1Low):
                                                Trigger1Low = registerData.GetAsUchar();
                                                break;

                                            case (GP34_WeaponRegister.Trigger1High):
                                                Trigger1High = registerData.GetAsUchar();
                                                break;

                                            case (GP34_WeaponRegister.Trigger2Low):
                                                Trigger2Low = registerData.GetAsUchar();
                                                break;

                                            case (GP34_WeaponRegister.Trigger2High):
                                                Trigger2High = registerData.GetAsUchar();
                                                break;

                                            case (GP34_WeaponRegister.RS0m):
                                                RS0m = registerData.GetAsShort();
                                                break;

                                            case (GP34_WeaponRegister.RS100m):
                                                RS100m = registerData.GetAsShort();
                                                break;
                                            case (GP34_WeaponRegister.RS150m):
                                                RS150m = registerData.GetAsShort();
                                                break;
                                            case (GP34_WeaponRegister.RS200m):
                                                RS200m = registerData.GetAsShort();
                                                break;
                                            case (GP34_WeaponRegister.RS250m):
                                                RS250m = registerData.GetAsShort();
                                                break;
                                            case (GP34_WeaponRegister.RS300m):
                                                RS300m = registerData.GetAsShort();
                                                break;
                                            case (GP34_WeaponRegister.RS350m):
                                                RS350m = registerData.GetAsShort();
                                                break;
                                            case (GP34_WeaponRegister.RS400m):
                                                RS400m = registerData.GetAsShort();
                                                break;
                                            case (GP34_WeaponRegister.RSx350m):
                                                RSx350m = registerData.GetAsShort();
                                                break;
                                            case (GP34_WeaponRegister.RSx300m):
                                                RSx300m = registerData.GetAsShort();
                                                break;
                                            case (GP34_WeaponRegister.RSx250m):
                                                RSx250m = registerData.GetAsShort();
                                                break;
                                            case (GP34_WeaponRegister.RSx200m):
                                                RSx200m = registerData.GetAsShort();
                                                break;
                                        }
                                        break;
                                    }
                                    // pockat pred dalsim pokusom
                                    Thread.Sleep(100);
                                }
                                RxCounter = RxCounter + 1;
                            }
                        }

                        if (weaponNodeId == 140) //brown
                        {
                            foreach (BROWN_WeaponRegister register in Enum.GetValues(typeof(BROWN_WeaponRegister)))
                            {
                                for (int attempts = 0; attempts < 3; attempts++)
                                {
                                    canConnection.SendRegisterReadRequest(weaponChannel, weaponNodeId, (byte)register);
                                    RegisterKey regKey = new RegisterKey(weaponNodeId, (byte)register);
                                    CanData registerData = null;
                                    Thread.Sleep(1000);
                                    if (canConnection.GetRegisterValue(regKey, out registerData) &&
                                        registerData.GetDataType() != CanData.DataType.DT_NODATA)
                                    {
                                        switch (register)
                                        {
                                            case (BROWN_WeaponRegister.BoltCatches):
                                                BoltCatches = registerData.GetAsUlong();
                                                break;

                                            case (BROWN_WeaponRegister.TresholdLow):
                                                TresholdLow = registerData.GetAsUchar();
                                                break;

                                            case (BROWN_WeaponRegister.TresholdHigh):
                                                TresholdHigh = registerData.GetAsUchar();
                                                break;

                                            case (BROWN_WeaponRegister.TriggerRelease):
                                                TriggerRelease = registerData.GetAsShort();
                                                break;

                                            case (BROWN_WeaponRegister.TriggerHold):
                                                TriggerHold = registerData.GetAsShort();
                                                break;

                                        }
                                        break;
                                    }
                                    // pockat pred dalsim pokusom
                                    Thread.Sleep(100);
                                }
                                RxCounter = RxCounter + 1;
                            }
                        }

                        if (weaponNodeId == 142) //coyote
                        {
                            foreach (COYOTE_WeaponRegister register in Enum.GetValues(typeof(COYOTE_WeaponRegister)))
                            {
                                for (int attempts = 0; attempts < 3; attempts++)
                                {
                                    canConnection.SendRegisterReadRequest(weaponChannel, weaponNodeId, (byte)register);
                                    RegisterKey regKey = new RegisterKey(weaponNodeId, (byte)register);
                                    CanData registerData = null;
                                    Thread.Sleep(1000);
                                    if (canConnection.GetRegisterValue(regKey, out registerData) &&
                                        registerData.GetDataType() != CanData.DataType.DT_NODATA)
                                    {
                                        switch (register)
                                        {
                                            case (COYOTE_WeaponRegister.TresholdLow):
                                                TresholdLow = registerData.GetAsUchar();
                                                break;

                                            case (COYOTE_WeaponRegister.TresholdHigh):
                                                TresholdHigh = registerData.GetAsUchar();
                                                break;

                                            case (COYOTE_WeaponRegister.TriggerRelease):
                                                TriggerRelease = registerData.GetAsShort();
                                                break;

                                            case (COYOTE_WeaponRegister.TriggerHold):
                                                TriggerHold = registerData.GetAsShort();
                                                break;

                                            case (COYOTE_WeaponRegister.BoltLockTreshold):
                                                BoltLockTreshold = registerData.GetAsShort();
                                                break;

                                            case (COYOTE_WeaponRegister.BoltUnlockTreshold):
                                                BoltUnlockTreshold = registerData.GetAsShort();
                                                break;

                                            case (COYOTE_WeaponRegister.FiringPinTreshold):
                                                FiringPinTreshold = registerData.GetAsShort();
                                                break;

                                            case (COYOTE_WeaponRegister.FiringPinDAOffset):
                                                FiringPinDAOffset = registerData.GetAsShort();
                                                break;
                                            case (COYOTE_WeaponRegister.SafeTreshold):
                                                SafeTreshold = registerData.GetAsShort();
                                                break;
                                            case (COYOTE_WeaponRegister.SafeDAOffset):
                                                SafeDAOffset = registerData.GetAsShort();
                                                break;
                                        }
                                        break;
                                    }
                                    // pockat pred dalsim pokusom
                                    Thread.Sleep(100);
                                }
                                RxCounter = RxCounter + 1;
                            }
                        }

                        if (weaponNodeId == 137) //g3
                        {
                            foreach (G3_WeaponRegister register in Enum.GetValues(typeof(G3_WeaponRegister)))
                            {
                                for (int attempts = 0; attempts < 3; attempts++)
                                {
                                    canConnection.SendRegisterReadRequest(weaponChannel, weaponNodeId, (byte)register);
                                    RegisterKey regKey = new RegisterKey(weaponNodeId, (byte)register);
                                    CanData registerData = null;
                                    Thread.Sleep(1000);
                                    if (canConnection.GetRegisterValue(regKey, out registerData) &&
                                        registerData.GetDataType() != CanData.DataType.DT_NODATA)
                                    {
                                        switch (register)
                                        {
                                            case (G3_WeaponRegister.TresholdLow):
                                                TresholdLow = registerData.GetAsUchar();
                                                break;

                                            case (G3_WeaponRegister.TresholdHigh):
                                                TresholdHigh = registerData.GetAsUchar();
                                                break;

                                            case (G3_WeaponRegister.Sensor1aLow):
                                                Sensor1aLow = registerData.GetAsShort();
                                                break;

                                            case (G3_WeaponRegister.Sensor1aHigh):
                                                SensorMax = registerData.GetAsShort();
                                                break;

                                            case (G3_WeaponRegister.Sensor1bLow):
                                                Sensor1aHigh = registerData.GetAsShort();
                                                break;

                                            case (G3_WeaponRegister.Sensor1bHigh):
                                                Sensor1bHigh = registerData.GetAsShort();
                                                break;
                                        }
                                        break;
                                    }
                                    // pockat pred dalsim pokusom
                                    Thread.Sleep(100);
                                }
                                RxCounter = RxCounter + 1;
                            }
                        }

                        if (weaponNodeId == 146) //g36
                        {
                            foreach (G36_WeaponRegister register in Enum.GetValues(typeof(G36_WeaponRegister)))
                            {
                                for (int attempts = 0; attempts < 3; attempts++)
                                {
                                    canConnection.SendRegisterReadRequest(weaponChannel, weaponNodeId, (byte)register);
                                    RegisterKey regKey = new RegisterKey(weaponNodeId, (byte)register);
                                    CanData registerData = null;
                                    Thread.Sleep(1000);
                                    if (canConnection.GetRegisterValue(regKey, out registerData) &&
                                        registerData.GetDataType() != CanData.DataType.DT_NODATA)
                                    {
                                        switch (register)
                                        {
                                            case (G36_WeaponRegister.TresholdLow):
                                                TresholdLow = registerData.GetAsUchar();
                                                break;

                                            case (G36_WeaponRegister.TresholdHigh):
                                                TresholdHigh = registerData.GetAsUchar();
                                                break;

                                            case (G36_WeaponRegister.Sensor1aLow):
                                                Sensor1aLow = registerData.GetAsShort();
                                                break;

                                            case (G36_WeaponRegister.Sensor1aHigh):
                                                SensorMax = registerData.GetAsShort();
                                                break;

                                            case (G36_WeaponRegister.Sensor1bLow):
                                                Sensor1aHigh = registerData.GetAsShort();
                                                break;

                                            case (G36_WeaponRegister.Sensor1bHigh):
                                                Sensor1bHigh = registerData.GetAsShort();
                                                break;
                                        }
                                        break;
                                    }
                                    // pockat pred dalsim pokusom
                                    Thread.Sleep(100);
                                }
                                RxCounter = RxCounter + 1;
                            }
                        }

                        if (weaponNodeId == 141) //lrt3
                        {
                            foreach (LRT3_WeaponRegister register in Enum.GetValues(typeof(LRT3_WeaponRegister)))
                            {
                                for (int attempts = 0; attempts < 3; attempts++)
                                {
                                    canConnection.SendRegisterReadRequest(weaponChannel, weaponNodeId, (byte)register);
                                    RegisterKey regKey = new RegisterKey(weaponNodeId, (byte)register);
                                    CanData registerData = null;
                                    Thread.Sleep(1000);
                                    if (canConnection.GetRegisterValue(regKey, out registerData) &&
                                        registerData.GetDataType() != CanData.DataType.DT_NODATA)
                                    {
                                        switch (register)
                                        {
                                            case (LRT3_WeaponRegister.TresholdLow):
                                                TresholdLow = registerData.GetAsUchar();
                                                break;

                                            case (LRT3_WeaponRegister.TresholdHigh):
                                                TresholdHigh = registerData.GetAsUchar();
                                                break;

                                            case (LRT3_WeaponRegister.TriggerRelease):
                                                TriggerRelease = registerData.GetAsShort();
                                                break;

                                            case (LRT3_WeaponRegister.TriggerHold):
                                                TriggerHold = registerData.GetAsShort();
                                                break;

                                            case (LRT3_WeaponRegister.BoltLockTreshold):
                                                BoltLockTreshold = registerData.GetAsShort();
                                                break;

                                            case (LRT3_WeaponRegister.BoltUnlockTreshold):
                                                BoltUnlockTreshold = registerData.GetAsShort();
                                                break;

                                            case (LRT3_WeaponRegister.FiringPinTreshold):
                                                FiringPinTreshold = registerData.GetAsShort();
                                                break;

                                            case (LRT3_WeaponRegister.FiringPinDAOffset):
                                                FiringPinDAOffset = registerData.GetAsShort();
                                                break;
                                            case (LRT3_WeaponRegister.SafeTreshold):
                                                SafeTreshold = registerData.GetAsShort();
                                                break;
                                            case (LRT3_WeaponRegister.SafeDAOffset):
                                                SafeDAOffset = registerData.GetAsShort();
                                                break;
                                        }
                                        break;
                                    }
                                    // pockat pred dalsim pokusom
                                    Thread.Sleep(100);
                                }
                                RxCounter = RxCounter + 1;
                            }
                        }

                        if (weaponNodeId == 138) //m60
                        {
                            foreach (M60_WeaponRegister register in Enum.GetValues(typeof(M60_WeaponRegister)))
                            {
                                for (int attempts = 0; attempts < 3; attempts++)
                                {
                                    canConnection.SendRegisterReadRequest(weaponChannel, weaponNodeId, (byte)register);
                                    RegisterKey regKey = new RegisterKey(weaponNodeId, (byte)register);
                                    CanData registerData = null;
                                    Thread.Sleep(1000);
                                    if (canConnection.GetRegisterValue(regKey, out registerData) &&
                                        registerData.GetDataType() != CanData.DataType.DT_NODATA)
                                    {
                                        switch (register)
                                        {
                                            case (M60_WeaponRegister.BeltReloads):
                                                BeltReloads = registerData.GetAsUlong();
                                                break;

                                            case (M60_WeaponRegister.TresholdLow):
                                                TresholdLow = registerData.GetAsUchar();
                                                break;

                                            case (M60_WeaponRegister.TresholdHigh):
                                                TresholdHigh = registerData.GetAsUchar();
                                                break;

                                            case (M60_WeaponRegister.HS3Release):
                                                HS3Release = registerData.GetAsShort();
                                                break;

                                            case (M60_WeaponRegister.HS3Hold):
                                                HS3Hold = registerData.GetAsShort();
                                                break;

                                            case (M60_WeaponRegister.TempDown):
                                                TempDown = registerData.GetAsShort();
                                                break;

                                            case (M60_WeaponRegister.TempUp):
                                                TempUp = registerData.GetAsShort();
                                                break;

                                            case (M60_WeaponRegister.MaxLedPWM):
                                                MaxLedPWM = registerData.GetAsShort();
                                                break;

                                            case (M60_WeaponRegister.DownStep1):
                                                DownStep1 = registerData.GetAsShort();
                                                break;

                                            case (M60_WeaponRegister.DownStep2):
                                                DownStep2 = registerData.GetAsShort();
                                                break;

                                            case (M60_WeaponRegister.DownStep3):
                                                DownStep3 = registerData.GetAsShort();
                                                break;

                                            case (M60_WeaponRegister.UpStep1):
                                                UpStep1 = registerData.GetAsShort();
                                                break;

                                            case (M60_WeaponRegister.UpStep2):
                                                UpStep2 = registerData.GetAsShort();
                                                break;

                                            case (M60_WeaponRegister.UpStep3):
                                                UpStep3 = registerData.GetAsShort();
                                                break;

                                        }
                                        break;
                                    }
                                    // pockat pred dalsim pokusom
                                    Thread.Sleep(100);
                                }
                                RxCounter = RxCounter + 1;
                            }
                        }

                        if (weaponNodeId == 136) //mg3
                        {
                            foreach (MG3_WeaponRegister register in Enum.GetValues(typeof(MG3_WeaponRegister)))
                            {
                                for (int attempts = 0; attempts < 3; attempts++)
                                {
                                    canConnection.SendRegisterReadRequest(weaponChannel, weaponNodeId, (byte)register);
                                    RegisterKey regKey = new RegisterKey(weaponNodeId, (byte)register);
                                    CanData registerData = null;
                                    Thread.Sleep(1000);
                                    if (canConnection.GetRegisterValue(regKey, out registerData) &&
                                        registerData.GetDataType() != CanData.DataType.DT_NODATA)
                                    {
                                        switch (register)
                                        {
                                            case (MG3_WeaponRegister.BeltReloads):
                                                BeltReloads = registerData.GetAsUlong();
                                                break;

                                            case (MG3_WeaponRegister.TresholdLow):
                                                TresholdLow = registerData.GetAsUchar();
                                                break;

                                            case (MG3_WeaponRegister.TresholdHigh):
                                                TresholdHigh = registerData.GetAsUchar();
                                                break;

                                            case (MG3_WeaponRegister.HS3Release):
                                                HS3Release = registerData.GetAsShort();
                                                break;

                                            case (MG3_WeaponRegister.HS3Hold):
                                                HS3Hold = registerData.GetAsShort();
                                                break;

                                            case (MG3_WeaponRegister.TempDown):
                                                TempDown = registerData.GetAsShort();
                                                break;

                                            case (MG3_WeaponRegister.TempUp):
                                                TempUp = registerData.GetAsShort();
                                                break;

                                            case (MG3_WeaponRegister.MaxLedPWM):
                                                MaxLedPWM = registerData.GetAsShort();
                                                break;

                                            case (MG3_WeaponRegister.DownStep1):
                                                DownStep1 = registerData.GetAsShort();
                                                break;

                                            case (MG3_WeaponRegister.DownStep2):
                                                DownStep2 = registerData.GetAsShort();
                                                break;

                                            case (MG3_WeaponRegister.DownStep3):
                                                DownStep3 = registerData.GetAsShort();
                                                break;

                                            case (MG3_WeaponRegister.UpStep1):
                                                UpStep1 = registerData.GetAsShort();
                                                break;

                                            case (MG3_WeaponRegister.UpStep2):
                                                UpStep2 = registerData.GetAsShort();
                                                break;

                                            case (MG3_WeaponRegister.UpStep3):
                                                UpStep3 = registerData.GetAsShort();
                                                break;

                                        }
                                        break;
                                    }
                                    // pockat pred dalsim pokusom
                                    Thread.Sleep(100);
                                }
                                RxCounter = RxCounter + 1;
                            }
                        }

                        if (weaponNodeId == 135) //rpg7
                        {
                            foreach (RPG7_WeaponRegister register in Enum.GetValues(typeof(RPG7_WeaponRegister)))
                            {
                                for (int attempts = 0; attempts < 3; attempts++)
                                {
                                    canConnection.SendRegisterReadRequest(weaponChannel, weaponNodeId, (byte)register);
                                    RegisterKey regKey = new RegisterKey(weaponNodeId, (byte)register);
                                    CanData registerData = null;
                                    Thread.Sleep(1000);
                                    if (canConnection.GetRegisterValue(regKey, out registerData) &&
                                        registerData.GetDataType() != CanData.DataType.DT_NODATA)
                                    {
                                        switch (register)
                                        {
                                            case (RPG7_WeaponRegister.TresholdLow):
                                                TresholdLow = registerData.GetAsUchar();
                                                break;

                                            case (RPG7_WeaponRegister.TresholdHigh):
                                                TresholdHigh = registerData.GetAsUchar();
                                                break;

                                            case (RPG7_WeaponRegister.VoltOffset):
                                                VoltOffset = registerData.GetAsShort();
                                                break;

                                            case (RPG7_WeaponRegister.DAGain):
                                                DAGain = registerData.GetAsShort();
                                                break;
                                        }
                                        break;
                                    }
                                    // pockat pred dalsim pokusom
                                    Thread.Sleep(100);
                                }
                                RxCounter = RxCounter + 1;
                            }
                        }

                        if (weaponNodeId == 143) //timber
                        {
                            foreach (TIMBER_WeaponRegister register in Enum.GetValues(typeof(TIMBER_WeaponRegister)))
                            {
                                for (int attempts = 0; attempts < 3; attempts++)
                                {
                                    canConnection.SendRegisterReadRequest(weaponChannel, weaponNodeId, (byte)register);
                                    RegisterKey regKey = new RegisterKey(weaponNodeId, (byte)register);
                                    CanData registerData = null;
                                    Thread.Sleep(1000);
                                    if (canConnection.GetRegisterValue(regKey, out registerData) &&
                                        registerData.GetDataType() != CanData.DataType.DT_NODATA)
                                    {
                                        switch (register)
                                        {
                                            case (TIMBER_WeaponRegister.TresholdLow):
                                                TresholdLow = registerData.GetAsUchar();
                                                break;

                                            case (TIMBER_WeaponRegister.TresholdHigh):
                                                TresholdHigh = registerData.GetAsUchar();
                                                break;

                                            case (TIMBER_WeaponRegister.TriggerRelease):
                                                TriggerRelease = registerData.GetAsShort();
                                                break;

                                            case (TIMBER_WeaponRegister.TriggerHold):
                                                TriggerHold = registerData.GetAsShort();
                                                break;

                                            case (TIMBER_WeaponRegister.BoltLockTreshold):
                                                BoltLockTreshold = registerData.GetAsShort();
                                                break;

                                            case (TIMBER_WeaponRegister.BoltUnlockTreshold):
                                                BoltUnlockTreshold = registerData.GetAsShort();
                                                break;

                                            case (TIMBER_WeaponRegister.FiringPinTreshold):
                                                FiringPinTreshold = registerData.GetAsShort();
                                                break;

                                            case (TIMBER_WeaponRegister.FiringPinDAOffset):
                                                FiringPinDAOffset = registerData.GetAsShort();
                                                break;
                                            case (TIMBER_WeaponRegister.SafeTreshold):
                                                SafeTreshold = registerData.GetAsShort();
                                                break;
                                            case (TIMBER_WeaponRegister.SafeDAOffset):
                                                SafeDAOffset = registerData.GetAsShort();
                                                break;
                                        }
                                        break;
                                    }
                                    // pockat pred dalsim pokusom
                                    Thread.Sleep(100);
                                }
                                RxCounter = RxCounter + 1;
                            }
                        }

                        if (weaponNodeId == 254) //rezerva a
                        {
                            foreach (RezervaA_WeaponRegister register in Enum.GetValues(typeof(RezervaA_WeaponRegister)))
                            {
                                for (int attempts = 0; attempts < 3; attempts++)
                                {
                                    canConnection.SendRegisterReadRequest(weaponChannel, weaponNodeId, (byte)register);
                                    RegisterKey regKey = new RegisterKey(weaponNodeId, (byte)register);
                                    CanData registerData = null;
                                    Thread.Sleep(1000);
                                    if (canConnection.GetRegisterValue(regKey, out registerData) &&
                                        registerData.GetDataType() != CanData.DataType.DT_NODATA)
                                    {
                                        switch (register)
                                        {
                                            case (RezervaA_WeaponRegister.BoltCatches):
                                                BoltCatches = registerData.GetAsUlong();
                                                break;

                                            case (RezervaA_WeaponRegister.TresholdLow):
                                                TresholdLow = registerData.GetAsUchar();
                                                break;

                                            case (RezervaA_WeaponRegister.TresholdHigh):
                                                TresholdHigh = registerData.GetAsUchar();
                                                break;

                                            case (RezervaA_WeaponRegister.TriggerRelease):
                                                TriggerRelease = registerData.GetAsShort();
                                                break;

                                            case (RezervaA_WeaponRegister.TriggerHold):
                                                TriggerHold = registerData.GetAsShort();
                                                break;

                                        }
                                        break;
                                    }
                                    // pockat pred dalsim pokusom
                                    Thread.Sleep(100);
                                }
                                RxCounter = RxCounter + 1;
                            }
                        }

                        if (weaponNodeId == 255) //rezerva b
                        {
                            foreach (RezervaB_WeaponRegister register in Enum.GetValues(typeof(RezervaB_WeaponRegister)))
                            {
                                for (int attempts = 0; attempts < 3; attempts++)
                                {
                                    canConnection.SendRegisterReadRequest(weaponChannel, weaponNodeId, (byte)register);
                                    RegisterKey regKey = new RegisterKey(weaponNodeId, (byte)register);
                                    CanData registerData = null;
                                    Thread.Sleep(1000);
                                    if (canConnection.GetRegisterValue(regKey, out registerData) &&
                                        registerData.GetDataType() != CanData.DataType.DT_NODATA)
                                    {
                                        switch (register)
                                        {
                                            case (RezervaB_WeaponRegister.BoltCatches):
                                                BoltCatches = registerData.GetAsUlong();
                                                break;

                                            case (RezervaB_WeaponRegister.TresholdLow):
                                                TresholdLow = registerData.GetAsUchar();
                                                break;

                                            case (RezervaB_WeaponRegister.TresholdHigh):
                                                TresholdHigh = registerData.GetAsUchar();
                                                break;

                                            case (RezervaB_WeaponRegister.TriggerRelease):
                                                TriggerRelease = registerData.GetAsShort();
                                                break;

                                            case (RezervaB_WeaponRegister.TriggerHold):
                                                TriggerHold = registerData.GetAsShort();
                                                break;

                                        }
                                        break;
                                    }
                                    // pockat pred dalsim pokusom
                                    Thread.Sleep(100);
                                }
                                RxCounter = RxCounter + 1;
                            }
                        }

                        //------vycitanie HW a SW version z prislusneho registru v zbrani
                        CanData idsData = new CanData();
                        byte[] byteIdsData = null;


                        canConnection.SendIdsRequest(weaponChannel, weaponNodeId);

                        Thread.Sleep(2000);

                        if (canConnection.GetIdsValue(weaponNodeId, out idsData)
                            && idsData.GetDataType() != CanData.DataType.DT_NODATA)
                        {
                            byteIdsData = idsData.GetRawData();
                        }
                        if (byteIdsData != null)
                        {
                            HwVersion = byteIdsData[0].ToString() + "." + byteIdsData[1].ToString();
                            SwVersion = byteIdsData[2].ToString() + "." + byteIdsData[3].ToString();

                            RxCounter = RxCounter + 1;
                        }

                        //------priradenie hodnot
                        if (Application.OpenForms.OfType<Form1>().Any())
                        {
                            Form1 mainform = Application.OpenForms.OfType<Form1>().First();
                        }
                        //zatriedenie zbrane
                        switch (weaponNodeId)
                        {
                            case (132):
                                label1.Text = " MP5 weapon found";
                                MP5.MP5Form MP5Form2 = new MP5.MP5Form();
                                MP5Form2.Show();
                                //vypnutie eventu pri zmene numericupdown
                                MP5Form2.MP5_treshlow.ValueChanged -= MP5Form2.MP5_numericUpDown_ValueChanged;
                                MP5Form2.MP5_treshhigh.ValueChanged -= MP5Form2.MP5_numericUpDown_ValueChanged;
                                MP5Form2.MP5_sensormin.ValueChanged -= MP5Form2.MP5_numericUpDown_ValueChanged;
                                MP5Form2.MP5_sensormax.ValueChanged -= MP5Form2.MP5_numericUpDown_ValueChanged;
                                MP5Form2.MP5_hallmax.ValueChanged -= MP5Form2.MP5_numericUpDown_ValueChanged;
                                MP5Form2.MP5_halfrange.ValueChanged -= MP5Form2.MP5_numericUpDown_ValueChanged;
                                MP5Form2.MP5_peakfilter.ValueChanged -= MP5Form2.MP5_numericUpDown_ValueChanged;
                                //
                                ActiveForm2 = MP5Form2;
                                HwName = "MP5";
                                MP5Form2.MP5_device.Text = HwName;
                                MP5Form2.MP5_serial.Text = SerialNumber;
                                MP5Form2.MP5_year.Text = "" + ProductionYear;
                                MP5Form2.MP5_address.Text = "" + BaseAddress;
                                MP5Form2.MP5_hw.Text = HwVersion;
                                MP5Form2.MP5_sw.Text = SwVersion;
                                MP5Form2.MP5_shots.Text = "" + TotalShots;
                                MP5Form2.MP5_powerons.Text = "" + Powerons;
                                MP5Form2.MP5_treshlow.Text = "" + TresholdLow;
                                MP5Form2.MP5_treshhigh.Text = "" + TresholdHigh;
                                MP5Form2.MP5_sensormin.Text = "" + SensorMin;
                                MP5Form2.MP5_sensormax.Text = "" + SensorMax;
                                MP5Form2.MP5_hallmax.Text = "" + HallMax;
                                MP5Form2.MP5_halfrange.Text = "" + HalfRange;
                                MP5Form2.MP5_peakfilter.Text = "" + PeakFilter;
                                //zapnutie eventu pri zmene numericupdown
                                MP5Form2.MP5_treshlow.ValueChanged += MP5Form2.MP5_numericUpDown_ValueChanged;
                                MP5Form2.MP5_treshhigh.ValueChanged += MP5Form2.MP5_numericUpDown_ValueChanged;
                                MP5Form2.MP5_sensormin.ValueChanged += MP5Form2.MP5_numericUpDown_ValueChanged;
                                MP5Form2.MP5_sensormax.ValueChanged += MP5Form2.MP5_numericUpDown_ValueChanged;
                                MP5Form2.MP5_hallmax.ValueChanged += MP5Form2.MP5_numericUpDown_ValueChanged;
                                MP5Form2.MP5_halfrange.ValueChanged += MP5Form2.MP5_numericUpDown_ValueChanged;
                                MP5Form2.MP5_peakfilter.ValueChanged += MP5Form2.MP5_numericUpDown_ValueChanged;
                                //
                                break;
                            case (137):
                                label1.Text = " G3 weapon found";
                                G3.G3Form G3Form2 = new G3.G3Form();
                                G3Form2.Show();
                                //vypnutie eventu pri zmene numericupdown
                                G3Form2.G3_treshlow.ValueChanged -= G3Form2.G3_numericUpDown_ValueChanged;
                                G3Form2.G3_treshhigh.ValueChanged -= G3Form2.G3_numericUpDown_ValueChanged;
                                G3Form2.G3_sensor1alow.ValueChanged -= G3Form2.G3_numericUpDown_ValueChanged;
                                G3Form2.G3_sensor1ahigh.ValueChanged -= G3Form2.G3_numericUpDown_ValueChanged;
                                G3Form2.G3_sensor1blow.ValueChanged -= G3Form2.G3_numericUpDown_ValueChanged;
                                G3Form2.G3_sensor1bhigh.ValueChanged -= G3Form2.G3_numericUpDown_ValueChanged;
                                //
                                ActiveForm2 = G3Form2;
                                HwName = "G3";
                                G3Form2.G3_device.Text = HwName;
                                G3Form2.G3_serial.Text = SerialNumber;
                                G3Form2.G3_year.Text = "" + ProductionYear;
                                G3Form2.G3_address.Text = "" + BaseAddress;
                                G3Form2.G3_hw.Text = HwVersion;
                                G3Form2.G3_sw.Text = SwVersion;
                                G3Form2.G3_shots.Text = "" + TotalShots;
                                G3Form2.G3_powerons.Text = "" + Powerons;
                                G3Form2.G3_treshlow.Text = "" + TresholdLow;
                                G3Form2.G3_treshhigh.Text = "" + TresholdHigh;
                                G3Form2.G3_sensor1alow.Text = "" + Sensor1aLow;
                                G3Form2.G3_sensor1ahigh.Text = "" + Sensor1aHigh;
                                G3Form2.G3_sensor1blow.Text = "" + Sensor1bLow;
                                G3Form2.G3_sensor1bhigh.Text = "" + Sensor1bHigh;
                                //zapnutie eventu pri zmene numericupdown
                                G3Form2.G3_treshlow.ValueChanged += G3Form2.G3_numericUpDown_ValueChanged;
                                G3Form2.G3_treshhigh.ValueChanged += G3Form2.G3_numericUpDown_ValueChanged;
                                G3Form2.G3_sensor1alow.ValueChanged += G3Form2.G3_numericUpDown_ValueChanged;
                                G3Form2.G3_sensor1ahigh.ValueChanged += G3Form2.G3_numericUpDown_ValueChanged;
                                G3Form2.G3_sensor1blow.ValueChanged += G3Form2.G3_numericUpDown_ValueChanged;
                                G3Form2.G3_sensor1bhigh.ValueChanged += G3Form2.G3_numericUpDown_ValueChanged;
                                //
                                break;
                            case (146):
                                label1.Text = " G36 weapon found";
                                G36.G36Form G36Form2 = new G36.G36Form();
                                G36Form2.Show();
                                //vypnutie eventu pri zmene numericupdown
                                G36Form2.G36_treshlow.ValueChanged -= G36Form2.G36_numericUpDown_ValueChanged;
                                G36Form2.G36_treshhigh.ValueChanged -= G36Form2.G36_numericUpDown_ValueChanged;
                                G36Form2.G36_sensor1alow.ValueChanged -= G36Form2.G36_numericUpDown_ValueChanged;
                                G36Form2.G36_sensor1ahigh.ValueChanged -= G36Form2.G36_numericUpDown_ValueChanged;
                                G36Form2.G36_sensor1blow.ValueChanged -= G36Form2.G36_numericUpDown_ValueChanged;
                                G36Form2.G36_sensor1bhigh.ValueChanged -= G36Form2.G36_numericUpDown_ValueChanged;
                                //
                                ActiveForm2 = G36Form2;
                                HwName = "G36";
                                G36Form2.G36_device.Text = HwName;
                                G36Form2.G36_serial.Text = SerialNumber;
                                G36Form2.G36_year.Text = "" + ProductionYear;
                                G36Form2.G36_address.Text = "" + BaseAddress;
                                G36Form2.G36_hw.Text = HwVersion;
                                G36Form2.G36_sw.Text = SwVersion;
                                G36Form2.G36_shots.Text = "" + TotalShots;
                                G36Form2.G36_powerons.Text = "" + Powerons;
                                G36Form2.G36_treshlow.Text = "" + TresholdLow;
                                G36Form2.G36_treshhigh.Text = "" + TresholdHigh;
                                G36Form2.G36_sensor1alow.Text = "" + Sensor1aLow;
                                G36Form2.G36_sensor1ahigh.Text = "" + Sensor1aHigh;
                                G36Form2.G36_sensor1blow.Text = "" + Sensor1bLow;
                                G36Form2.G36_sensor1bhigh.Text = "" + Sensor1bHigh;
                                //zapnutie eventu pri zmene numericupdown
                                G36Form2.G36_treshlow.ValueChanged += G36Form2.G36_numericUpDown_ValueChanged;
                                G36Form2.G36_treshhigh.ValueChanged += G36Form2.G36_numericUpDown_ValueChanged;
                                G36Form2.G36_sensor1alow.ValueChanged += G36Form2.G36_numericUpDown_ValueChanged;
                                G36Form2.G36_sensor1ahigh.ValueChanged += G36Form2.G36_numericUpDown_ValueChanged;
                                G36Form2.G36_sensor1blow.ValueChanged += G36Form2.G36_numericUpDown_ValueChanged;
                                G36Form2.G36_sensor1bhigh.ValueChanged += G36Form2.G36_numericUpDown_ValueChanged;
                                //
                                break;
                            case (139):
                                label1.Text = " AK103 weapon found";
                                AK103.AK103Form AK103Form2 = new AK103.AK103Form();
                                AK103Form2.Show();
                                //vypnutie eventu pri zmene numericupdown
                                AK103Form2.AK103_treshlow.ValueChanged -= AK103Form2.AK103_numericUpDown_ValueChanged;
                                AK103Form2.AK103_treshhigh.ValueChanged -= AK103Form2.AK103_numericUpDown_ValueChanged;
                                AK103Form2.AK103_voltoffset.ValueChanged -= AK103Form2.AK103_numericUpDown_ValueChanged;
                                AK103Form2.AK103_dagain.ValueChanged -= AK103Form2.AK103_numericUpDown_ValueChanged;
                                AK103Form2.AK103_rs100m.ValueChanged -= AK103Form2.AK103_numericUpDown_ValueChanged;
                                AK103Form2.AK103_rs200m.ValueChanged -= AK103Form2.AK103_numericUpDown_ValueChanged;
                                AK103Form2.AK103_rs300m.ValueChanged -= AK103Form2.AK103_numericUpDown_ValueChanged;
                                AK103Form2.AK103_rs400m.ValueChanged -= AK103Form2.AK103_numericUpDown_ValueChanged;
                                AK103Form2.AK103_rs500m.ValueChanged -= AK103Form2.AK103_numericUpDown_ValueChanged;
                                AK103Form2.AK103_rs600m.ValueChanged -= AK103Form2.AK103_numericUpDown_ValueChanged;
                                AK103Form2.AK103_rs700m.ValueChanged -= AK103Form2.AK103_numericUpDown_ValueChanged;
                                AK103Form2.AK103_rs800m.ValueChanged -= AK103Form2.AK103_numericUpDown_ValueChanged;
                                //
                                ActiveForm2 = AK103Form2;
                                HwName = "AK103";
                                AK103Form2.AK103_device.Text = HwName;
                                AK103Form2.AK103_serial.Text = SerialNumber;
                                AK103Form2.AK103_year.Text = "" + ProductionYear;
                                AK103Form2.AK103_address.Text = "" + BaseAddress;
                                AK103Form2.AK103_hw.Text = HwVersion;
                                AK103Form2.AK103_sw.Text = SwVersion;
                                AK103Form2.AK103_shots.Text = "" + TotalShots;
                                AK103Form2.AK103_powerons.Text = "" + Powerons;
                                AK103Form2.AK103_treshlow.Text = "" + TresholdLow;
                                AK103Form2.AK103_treshhigh.Text = "" + TresholdHigh;
                                AK103Form2.AK103_voltoffset.Text = "" + VoltOffset;
                                AK103Form2.AK103_dagain.Text = "" + DAGain;
                                AK103Form2.AK103_rs100m.Text = "" + RS100m;
                                AK103Form2.AK103_rs100m.Text = "" + RS200m;
                                AK103Form2.AK103_rs100m.Text = "" + RS300m;
                                AK103Form2.AK103_rs100m.Text = "" + RS400m;
                                AK103Form2.AK103_rs100m.Text = "" + RS500m;
                                AK103Form2.AK103_rs100m.Text = "" + RS600m;
                                AK103Form2.AK103_rs100m.Text = "" + RS700m;
                                AK103Form2.AK103_rs100m.Text = "" + RS800m;
                                //zapnutie eventu pri zmene numericupdown
                                AK103Form2.AK103_treshlow.ValueChanged += AK103Form2.AK103_numericUpDown_ValueChanged;
                                AK103Form2.AK103_treshhigh.ValueChanged += AK103Form2.AK103_numericUpDown_ValueChanged;
                                AK103Form2.AK103_voltoffset.ValueChanged += AK103Form2.AK103_numericUpDown_ValueChanged;
                                AK103Form2.AK103_dagain.ValueChanged += AK103Form2.AK103_numericUpDown_ValueChanged;
                                AK103Form2.AK103_rs100m.ValueChanged += AK103Form2.AK103_numericUpDown_ValueChanged;
                                AK103Form2.AK103_rs200m.ValueChanged += AK103Form2.AK103_numericUpDown_ValueChanged;
                                AK103Form2.AK103_rs300m.ValueChanged += AK103Form2.AK103_numericUpDown_ValueChanged;
                                AK103Form2.AK103_rs400m.ValueChanged += AK103Form2.AK103_numericUpDown_ValueChanged;
                                AK103Form2.AK103_rs500m.ValueChanged += AK103Form2.AK103_numericUpDown_ValueChanged;
                                AK103Form2.AK103_rs600m.ValueChanged += AK103Form2.AK103_numericUpDown_ValueChanged;
                                AK103Form2.AK103_rs700m.ValueChanged += AK103Form2.AK103_numericUpDown_ValueChanged;
                                AK103Form2.AK103_rs800m.ValueChanged += AK103Form2.AK103_numericUpDown_ValueChanged;
                                //
                                break;
                            case (136):
                                label1.Text = " MG3 weapon found";
                                MG3.MG3Form MG3Form2 = new MG3.MG3Form();
                                MG3Form2.Show();
                                //vypnutie eventu pri zmene numericupdown
                                MG3Form2.MG3_treshlow.ValueChanged -= MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_treshhigh.ValueChanged -= MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_hs3release.ValueChanged -= MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_hs3hold.ValueChanged -= MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_tempdown.ValueChanged -= MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_tempup.ValueChanged -= MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_maxledpwm.ValueChanged -= MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_downstep1.ValueChanged -= MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_downstep2.ValueChanged -= MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_downstep3.ValueChanged -= MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_upstep1.ValueChanged -= MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_upstep2.ValueChanged -= MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_upstep3.ValueChanged -= MG3Form2.MG3_numericUpDown_ValueChanged;
                                //
                                ActiveForm2 = MG3Form2;
                                HwName = "MG3";
                                MG3Form2.MG3_device.Text = HwName;
                                MG3Form2.MG3_serial.Text = SerialNumber;
                                MG3Form2.MG3_year.Text = "" + ProductionYear;
                                MG3Form2.MG3_address.Text = "" + BaseAddress;
                                MG3Form2.MG3_hw.Text = HwVersion;
                                MG3Form2.MG3_sw.Text = SwVersion;
                                MG3Form2.MG3_shots.Text = "" + TotalShots;
                                MG3Form2.MG3_powerons.Text = "" + Powerons;
                                MG3Form2.MG3_reloads.Text = "" + BeltReloads;
                                MG3Form2.MG3_treshlow.Text = "" + TresholdLow;
                                MG3Form2.MG3_treshhigh.Text = "" + TresholdHigh;
                                MG3Form2.MG3_hs3release.Text = "" + HS3Release;
                                MG3Form2.MG3_hs3hold.Text = "" + HS3Hold;
                                MG3Form2.MG3_tempdown.Text = "" + TempDown;
                                MG3Form2.MG3_tempup.Text = "" + TempUp;
                                MG3Form2.MG3_maxledpwm.Text = "" + MaxLedPWM;
                                MG3Form2.MG3_downstep1.Text = "" + DownStep1;
                                MG3Form2.MG3_downstep2.Text = "" + DownStep2;
                                MG3Form2.MG3_downstep3.Text = "" + DownStep3;
                                MG3Form2.MG3_upstep1.Text = "" + UpStep1;
                                MG3Form2.MG3_upstep2.Text = "" + UpStep2;
                                MG3Form2.MG3_upstep3.Text = "" + UpStep3;
                                //zapnutie eventu pri zmene numericupdown
                                MG3Form2.MG3_treshlow.ValueChanged += MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_treshhigh.ValueChanged += MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_hs3release.ValueChanged += MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_hs3hold.ValueChanged += MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_tempdown.ValueChanged += MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_tempup.ValueChanged += MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_maxledpwm.ValueChanged += MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_downstep1.ValueChanged += MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_downstep2.ValueChanged += MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_downstep3.ValueChanged += MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_upstep1.ValueChanged += MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_upstep2.ValueChanged += MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_upstep3.ValueChanged += MG3Form2.MG3_numericUpDown_ValueChanged;
                                //
                                break;
                            case (141):
                                label1.Text = " LRT3 weapon found";
                                LRT3.LRT3Form LRT3Form2 = new LRT3.LRT3Form();
                                LRT3Form2.Show();
                                //vypnutie eventu pri zmene numericupdown
                                LRT3Form2.LRT3_treshlow.ValueChanged -= LRT3Form2.LRT3_numericUpDown_ValueChanged;
                                LRT3Form2.LRT3_treshhigh.ValueChanged -= LRT3Form2.LRT3_numericUpDown_ValueChanged;
                                LRT3Form2.LRT3_triggerrelease.ValueChanged -= LRT3Form2.LRT3_numericUpDown_ValueChanged;
                                LRT3Form2.LRT3_triggerhold.ValueChanged -= LRT3Form2.LRT3_numericUpDown_ValueChanged;
                                LRT3Form2.LRT3_boltlocktresh.ValueChanged -= LRT3Form2.LRT3_numericUpDown_ValueChanged;
                                LRT3Form2.LRT3_boltunlocktresh.ValueChanged -= LRT3Form2.LRT3_numericUpDown_ValueChanged;
                                LRT3Form2.LRT3_firingpintresh.ValueChanged -= LRT3Form2.LRT3_numericUpDown_ValueChanged;
                                LRT3Form2.LRT3_firingpindaoffset.ValueChanged -= LRT3Form2.LRT3_numericUpDown_ValueChanged;
                                LRT3Form2.LRT3_safetresh.ValueChanged -= LRT3Form2.LRT3_numericUpDown_ValueChanged;
                                LRT3Form2.LRT3_safedaoffset.ValueChanged -= LRT3Form2.LRT3_numericUpDown_ValueChanged;
                                //
                                ActiveForm2 = LRT3Form2;
                                HwName = "LRT3";
                                LRT3Form2.LRT3_device.Text = HwName;
                                LRT3Form2.LRT3_serial.Text = SerialNumber;
                                LRT3Form2.LRT3_year.Text = "" + ProductionYear;
                                LRT3Form2.LRT3_address.Text = "" + BaseAddress;
                                LRT3Form2.LRT3_hw.Text = HwVersion;
                                LRT3Form2.LRT3_sw.Text = SwVersion;
                                LRT3Form2.LRT3_shots.Text = "" + TotalShots;
                                LRT3Form2.LRT3_powerons.Text = "" + Powerons;
                                LRT3Form2.LRT3_treshlow.Text = "" + TresholdLow;
                                LRT3Form2.LRT3_treshhigh.Text = "" + TresholdHigh;
                                LRT3Form2.LRT3_triggerrelease.Text = "" + TriggerRelease;
                                LRT3Form2.LRT3_triggerhold.Text = "" + TriggerHold;
                                LRT3Form2.LRT3_boltlocktresh.Text = "" + BoltLockTreshold;
                                LRT3Form2.LRT3_boltunlocktresh.Text = "" + BoltUnlockTreshold;
                                LRT3Form2.LRT3_firingpintresh.Text = "" + FiringPinTreshold;
                                LRT3Form2.LRT3_firingpindaoffset.Text = "" + FiringPinDAOffset;
                                LRT3Form2.LRT3_safetresh.Text = "" + SafeTreshold;
                                LRT3Form2.LRT3_safedaoffset.Text = "" + SafeDAOffset;
                                //zapnutie eventu pri zmene numericupdown
                                LRT3Form2.LRT3_treshlow.ValueChanged += LRT3Form2.LRT3_numericUpDown_ValueChanged;
                                LRT3Form2.LRT3_treshhigh.ValueChanged += LRT3Form2.LRT3_numericUpDown_ValueChanged;
                                LRT3Form2.LRT3_triggerrelease.ValueChanged += LRT3Form2.LRT3_numericUpDown_ValueChanged;
                                LRT3Form2.LRT3_triggerhold.ValueChanged += LRT3Form2.LRT3_numericUpDown_ValueChanged;
                                LRT3Form2.LRT3_boltlocktresh.ValueChanged += LRT3Form2.LRT3_numericUpDown_ValueChanged;
                                LRT3Form2.LRT3_boltunlocktresh.ValueChanged += LRT3Form2.LRT3_numericUpDown_ValueChanged;
                                LRT3Form2.LRT3_firingpintresh.ValueChanged += LRT3Form2.LRT3_numericUpDown_ValueChanged;
                                LRT3Form2.LRT3_firingpindaoffset.ValueChanged += LRT3Form2.LRT3_numericUpDown_ValueChanged;
                                LRT3Form2.LRT3_safetresh.ValueChanged += LRT3Form2.LRT3_numericUpDown_ValueChanged;
                                LRT3Form2.LRT3_safedaoffset.ValueChanged += LRT3Form2.LRT3_numericUpDown_ValueChanged;
                                //
                                break;
                            case (142):
                                label1.Text = " COYOTE weapon found";
                                COYOTE.COYOTEForm COYOTEForm2 = new COYOTE.COYOTEForm();
                                COYOTEForm2.Show();
                                //vypnutie eventu pri zmene numericupdown
                                COYOTEForm2.COYOTE_treshlow.ValueChanged -= COYOTEForm2.COYOTE_numericUpDown_ValueChanged;
                                COYOTEForm2.COYOTE_treshhigh.ValueChanged -= COYOTEForm2.COYOTE_numericUpDown_ValueChanged;
                                COYOTEForm2.COYOTE_triggerrelease.ValueChanged -= COYOTEForm2.COYOTE_numericUpDown_ValueChanged;
                                COYOTEForm2.COYOTE_triggerhold.ValueChanged -= COYOTEForm2.COYOTE_numericUpDown_ValueChanged;
                                COYOTEForm2.COYOTE_boltlocktresh.ValueChanged -= COYOTEForm2.COYOTE_numericUpDown_ValueChanged;
                                COYOTEForm2.COYOTE_boltunlocktresh.ValueChanged -= COYOTEForm2.COYOTE_numericUpDown_ValueChanged;
                                COYOTEForm2.COYOTE_firingpintresh.ValueChanged -= COYOTEForm2.COYOTE_numericUpDown_ValueChanged;
                                COYOTEForm2.COYOTE_firingpindaoffset.ValueChanged -= COYOTEForm2.COYOTE_numericUpDown_ValueChanged;
                                COYOTEForm2.COYOTE_safetresh.ValueChanged -= COYOTEForm2.COYOTE_numericUpDown_ValueChanged;
                                COYOTEForm2.COYOTE_safedaoffset.ValueChanged -= COYOTEForm2.COYOTE_numericUpDown_ValueChanged;
                                //
                                ActiveForm2 = COYOTEForm2;
                                HwName = "COYOTE";
                                COYOTEForm2.COYOTE_device.Text = HwName;
                                COYOTEForm2.COYOTE_serial.Text = SerialNumber;
                                COYOTEForm2.COYOTE_year.Text = "" + ProductionYear;
                                COYOTEForm2.COYOTE_address.Text = "" + BaseAddress;
                                COYOTEForm2.COYOTE_hw.Text = HwVersion;
                                COYOTEForm2.COYOTE_sw.Text = SwVersion;
                                COYOTEForm2.COYOTE_shots.Text = "" + TotalShots;
                                COYOTEForm2.COYOTE_powerons.Text = "" + Powerons;
                                COYOTEForm2.COYOTE_treshlow.Text = "" + TresholdLow;
                                COYOTEForm2.COYOTE_treshhigh.Text = "" + TresholdHigh;
                                COYOTEForm2.COYOTE_triggerrelease.Text = "" + TriggerRelease;
                                COYOTEForm2.COYOTE_triggerhold.Text = "" + TriggerHold;
                                COYOTEForm2.COYOTE_boltlocktresh.Text = "" + BoltLockTreshold;
                                COYOTEForm2.COYOTE_boltunlocktresh.Text = "" + BoltUnlockTreshold;
                                COYOTEForm2.COYOTE_firingpintresh.Text = "" + FiringPinTreshold;
                                COYOTEForm2.COYOTE_firingpindaoffset.Text = "" + FiringPinDAOffset;
                                COYOTEForm2.COYOTE_safetresh.Text = "" + SafeTreshold;
                                COYOTEForm2.COYOTE_safedaoffset.Text = "" + SafeDAOffset;
                                //zapnutie eventu pri zmene numericupdown
                                COYOTEForm2.COYOTE_treshlow.ValueChanged += COYOTEForm2.COYOTE_numericUpDown_ValueChanged;
                                COYOTEForm2.COYOTE_treshhigh.ValueChanged += COYOTEForm2.COYOTE_numericUpDown_ValueChanged;
                                COYOTEForm2.COYOTE_triggerrelease.ValueChanged += COYOTEForm2.COYOTE_numericUpDown_ValueChanged;
                                COYOTEForm2.COYOTE_triggerhold.ValueChanged += COYOTEForm2.COYOTE_numericUpDown_ValueChanged;
                                COYOTEForm2.COYOTE_boltlocktresh.ValueChanged += COYOTEForm2.COYOTE_numericUpDown_ValueChanged;
                                COYOTEForm2.COYOTE_boltunlocktresh.ValueChanged += COYOTEForm2.COYOTE_numericUpDown_ValueChanged;
                                COYOTEForm2.COYOTE_firingpintresh.ValueChanged += COYOTEForm2.COYOTE_numericUpDown_ValueChanged;
                                COYOTEForm2.COYOTE_firingpindaoffset.ValueChanged += COYOTEForm2.COYOTE_numericUpDown_ValueChanged;
                                COYOTEForm2.COYOTE_safetresh.ValueChanged += COYOTEForm2.COYOTE_numericUpDown_ValueChanged;
                                COYOTEForm2.COYOTE_safedaoffset.ValueChanged += COYOTEForm2.COYOTE_numericUpDown_ValueChanged;
                                //
                                break;
                            case (143):
                                label1.Text = " TIMBERWOLF weapon found";
                                TIMBER.TIMBERForm TIMBERForm2 = new TIMBER.TIMBERForm();
                                TIMBERForm2.Show();
                                //vypnutie eventu pri zmene numericupdown
                                TIMBERForm2.TIMBER_treshlow.ValueChanged -= TIMBERForm2.TIMBER_numericUpDown_ValueChanged;
                                TIMBERForm2.TIMBER_treshhigh.ValueChanged -= TIMBERForm2.TIMBER_numericUpDown_ValueChanged;
                                TIMBERForm2.TIMBER_triggerrelease.ValueChanged -= TIMBERForm2.TIMBER_numericUpDown_ValueChanged;
                                TIMBERForm2.TIMBER_triggerhold.ValueChanged -= TIMBERForm2.TIMBER_numericUpDown_ValueChanged;
                                TIMBERForm2.TIMBER_boltlocktresh.ValueChanged -= TIMBERForm2.TIMBER_numericUpDown_ValueChanged;
                                TIMBERForm2.TIMBER_boltunlocktresh.ValueChanged -= TIMBERForm2.TIMBER_numericUpDown_ValueChanged;
                                TIMBERForm2.TIMBER_firingpintresh.ValueChanged -= TIMBERForm2.TIMBER_numericUpDown_ValueChanged;
                                TIMBERForm2.TIMBER_firingpindaoffset.ValueChanged -= TIMBERForm2.TIMBER_numericUpDown_ValueChanged;
                                TIMBERForm2.TIMBER_safetresh.ValueChanged -= TIMBERForm2.TIMBER_numericUpDown_ValueChanged;
                                TIMBERForm2.TIMBER_safedaoffset.ValueChanged -= TIMBERForm2.TIMBER_numericUpDown_ValueChanged;
                                //
                                ActiveForm2 = TIMBERForm2;
                                HwName = "TIMBERWOLF";
                                TIMBERForm2.TIMBER_device.Text = HwName;
                                TIMBERForm2.TIMBER_serial.Text = SerialNumber;
                                TIMBERForm2.TIMBER_year.Text = "" + ProductionYear;
                                TIMBERForm2.TIMBER_address.Text = "" + BaseAddress;
                                TIMBERForm2.TIMBER_hw.Text = HwVersion;
                                TIMBERForm2.TIMBER_sw.Text = SwVersion;
                                TIMBERForm2.TIMBER_shots.Text = "" + TotalShots;
                                TIMBERForm2.TIMBER_powerons.Text = "" + Powerons;
                                TIMBERForm2.TIMBER_treshlow.Text = "" + TresholdLow;
                                TIMBERForm2.TIMBER_treshhigh.Text = "" + TresholdHigh;
                                TIMBERForm2.TIMBER_triggerrelease.Text = "" + TriggerRelease;
                                TIMBERForm2.TIMBER_triggerhold.Text = "" + TriggerHold;
                                TIMBERForm2.TIMBER_boltlocktresh.Text = "" + BoltLockTreshold;
                                TIMBERForm2.TIMBER_boltunlocktresh.Text = "" + BoltUnlockTreshold;
                                TIMBERForm2.TIMBER_firingpintresh.Text = "" + FiringPinTreshold;
                                TIMBERForm2.TIMBER_firingpindaoffset.Text = "" + FiringPinDAOffset;
                                TIMBERForm2.TIMBER_safetresh.Text = "" + SafeTreshold;
                                TIMBERForm2.TIMBER_safedaoffset.Text = "" + SafeDAOffset;
                                //zapnutie eventu pri zmene numericupdown
                                TIMBERForm2.TIMBER_treshlow.ValueChanged += TIMBERForm2.TIMBER_numericUpDown_ValueChanged;
                                TIMBERForm2.TIMBER_treshhigh.ValueChanged += TIMBERForm2.TIMBER_numericUpDown_ValueChanged;
                                TIMBERForm2.TIMBER_triggerrelease.ValueChanged += TIMBERForm2.TIMBER_numericUpDown_ValueChanged;
                                TIMBERForm2.TIMBER_triggerhold.ValueChanged += TIMBERForm2.TIMBER_numericUpDown_ValueChanged;
                                TIMBERForm2.TIMBER_boltlocktresh.ValueChanged += TIMBERForm2.TIMBER_numericUpDown_ValueChanged;
                                TIMBERForm2.TIMBER_boltunlocktresh.ValueChanged += TIMBERForm2.TIMBER_numericUpDown_ValueChanged;
                                TIMBERForm2.TIMBER_firingpintresh.ValueChanged += TIMBERForm2.TIMBER_numericUpDown_ValueChanged;
                                TIMBERForm2.TIMBER_firingpindaoffset.ValueChanged += TIMBERForm2.TIMBER_numericUpDown_ValueChanged;
                                TIMBERForm2.TIMBER_safetresh.ValueChanged += TIMBERForm2.TIMBER_numericUpDown_ValueChanged;
                                TIMBERForm2.TIMBER_safedaoffset.ValueChanged += TIMBERForm2.TIMBER_numericUpDown_ValueChanged;
                                //
                                break;
                            case (135):
                                label1.Text = " RPG7 weapon found";
                                RPG7.RPG7Form RPG7Form2 = new RPG7.RPG7Form();
                                RPG7Form2.Show();
                                //vypnutie eventu pri zmene numericupdown
                                RPG7Form2.RPG7_treshlow.ValueChanged -= RPG7Form2.RPG7_numericUpDown_ValueChanged;
                                RPG7Form2.RPG7_treshhigh.ValueChanged -= RPG7Form2.RPG7_numericUpDown_ValueChanged;
                                RPG7Form2.RPG7_voltoffset.ValueChanged -= RPG7Form2.RPG7_numericUpDown_ValueChanged;
                                RPG7Form2.RPG7_dagain.ValueChanged -= RPG7Form2.RPG7_numericUpDown_ValueChanged;
                                //
                                ActiveForm2 = RPG7Form2;
                                HwName = "RPG7";
                                RPG7Form2.RPG7_device.Text = HwName;
                                RPG7Form2.RPG7_serial.Text = SerialNumber;
                                RPG7Form2.RPG7_year.Text = "" + ProductionYear;
                                RPG7Form2.RPG7_address.Text = "" + BaseAddress;
                                RPG7Form2.RPG7_hw.Text = HwVersion;
                                RPG7Form2.RPG7_sw.Text = SwVersion;
                                RPG7Form2.RPG7_shots.Text = "" + TotalShots;
                                RPG7Form2.RPG7_powerons.Text = "" + Powerons;
                                RPG7Form2.RPG7_treshlow.Text = "" + TresholdLow;
                                RPG7Form2.RPG7_treshhigh.Text = "" + TresholdHigh;
                                RPG7Form2.RPG7_voltoffset.Text = "" + VoltOffset;
                                RPG7Form2.RPG7_dagain.Text = "" + DAGain;
                                //zapnutie eventu pri zmene numericupdown
                                RPG7Form2.RPG7_treshlow.ValueChanged += RPG7Form2.RPG7_numericUpDown_ValueChanged;
                                RPG7Form2.RPG7_treshhigh.ValueChanged += RPG7Form2.RPG7_numericUpDown_ValueChanged;
                                RPG7Form2.RPG7_voltoffset.ValueChanged += RPG7Form2.RPG7_numericUpDown_ValueChanged;
                                RPG7Form2.RPG7_dagain.ValueChanged += RPG7Form2.RPG7_numericUpDown_ValueChanged;
                                //
                                break;
                            case (2):
                                label1.Text = " GLOCK weapon found";
                                GLOCK.GLOCKForm GLOCKForm2 = new GLOCK.GLOCKForm();
                                GLOCKForm2.Show();
                                //vypnutie eventu pri zmene numericupdown
                                GLOCKForm2.GLOCK_treshlow.ValueChanged -= GLOCKForm2.GLOCK_numericUpDown_ValueChanged;
                                GLOCKForm2.GLOCK_treshhigh.ValueChanged -= GLOCKForm2.GLOCK_numericUpDown_ValueChanged;
                                GLOCKForm2.GLOCK_triggerrelease.ValueChanged -= GLOCKForm2.GLOCK_numericUpDown_ValueChanged;
                                GLOCKForm2.GLOCK_triggerhold.ValueChanged -= GLOCKForm2.GLOCK_numericUpDown_ValueChanged;
                                //
                                ActiveForm2 = GLOCKForm2;
                                HwName = "GLOCK";
                                GLOCKForm2.GLOCK_device.Text = HwName;
                                GLOCKForm2.GLOCK_serial.Text = SerialNumber;
                                GLOCKForm2.GLOCK_year.Text = "" + ProductionYear;
                                GLOCKForm2.GLOCK_address.Text = "" + BaseAddress;
                                GLOCKForm2.GLOCK_hw.Text = HwVersion;
                                GLOCKForm2.GLOCK_sw.Text = SwVersion;
                                GLOCKForm2.GLOCK_shots.Text = "" + TotalShots;
                                GLOCKForm2.GLOCK_powerons.Text = "" + Powerons;
                                GLOCKForm2.GLOCK_boltcatches.Text = "" + BoltCatches;
                                GLOCKForm2.GLOCK_treshlow.Text = "" + TresholdLow;
                                GLOCKForm2.GLOCK_treshhigh.Text = "" + TresholdHigh;
                                GLOCKForm2.GLOCK_triggerrelease.Text = "" + TriggerRelease;
                                GLOCKForm2.GLOCK_triggerhold.Text = "" + TriggerHold;
                                //zapnutie eventu pri zmene numericupdown
                                GLOCKForm2.GLOCK_treshlow.ValueChanged += GLOCKForm2.GLOCK_numericUpDown_ValueChanged;
                                GLOCKForm2.GLOCK_treshhigh.ValueChanged += GLOCKForm2.GLOCK_numericUpDown_ValueChanged;
                                GLOCKForm2.GLOCK_triggerrelease.ValueChanged += GLOCKForm2.GLOCK_numericUpDown_ValueChanged;
                                GLOCKForm2.GLOCK_triggerhold.ValueChanged += GLOCKForm2.GLOCK_numericUpDown_ValueChanged;
                                //134
                                break;
                            case (140):
                                label1.Text = " BROWNING weapon found";
                                BROWN.BROWNForm BROWNForm2 = new BROWN.BROWNForm();
                                BROWNForm2.Show();
                                //vypnutie eventu pri zmene numericupdown
                                BROWNForm2.BROWN_treshlow.ValueChanged -= BROWNForm2.BROWN_numericUpDown_ValueChanged;
                                BROWNForm2.BROWN_treshhigh.ValueChanged -= BROWNForm2.BROWN_numericUpDown_ValueChanged;
                                BROWNForm2.BROWN_triggerrelease.ValueChanged -= BROWNForm2.BROWN_numericUpDown_ValueChanged;
                                BROWNForm2.BROWN_triggerhold.ValueChanged -= BROWNForm2.BROWN_numericUpDown_ValueChanged;
                                //
                                ActiveForm2 = BROWNForm2;
                                HwName = "BROWNING";
                                BROWNForm2.BROWN_device.Text = HwName;
                                BROWNForm2.BROWN_serial.Text = SerialNumber;
                                BROWNForm2.BROWN_year.Text = "" + ProductionYear;
                                BROWNForm2.BROWN_address.Text = "" + BaseAddress;
                                BROWNForm2.BROWN_hw.Text = HwVersion;
                                BROWNForm2.BROWN_sw.Text = SwVersion;
                                BROWNForm2.BROWN_shots.Text = "" + TotalShots;
                                BROWNForm2.BROWN_powerons.Text = "" + Powerons;
                                BROWNForm2.BROWN_boltcatches.Text = "" + BoltCatches;
                                BROWNForm2.BROWN_treshlow.Text = "" + TresholdLow;
                                BROWNForm2.BROWN_treshhigh.Text = "" + TresholdHigh;
                                BROWNForm2.BROWN_triggerrelease.Text = "" + TriggerRelease;
                                BROWNForm2.BROWN_triggerhold.Text = "" + TriggerHold;
                                //zapnutie eventu pri zmene numericupdown
                                BROWNForm2.BROWN_treshlow.ValueChanged += BROWNForm2.BROWN_numericUpDown_ValueChanged;
                                BROWNForm2.BROWN_treshhigh.ValueChanged += BROWNForm2.BROWN_numericUpDown_ValueChanged;
                                BROWNForm2.BROWN_triggerrelease.ValueChanged += BROWNForm2.BROWN_numericUpDown_ValueChanged;
                                BROWNForm2.BROWN_triggerhold.ValueChanged += BROWNForm2.BROWN_numericUpDown_ValueChanged;
                                //
                                break;
                            case (150):
                                label1.Text = " GP34 weapon found";
                                AK103.GP34Form GP34Form2 = new AK103.GP34Form();
                                GP34Form2.Show();
                                //vypnutie eventu pri zmene numericupdown
                                GP34Form2.GP34_trigger1low.ValueChanged -= GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_trigger1high.ValueChanged -= GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_trigger2low.ValueChanged -= GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_trigger2high.ValueChanged -= GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rs0m.ValueChanged -= GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rs100m.ValueChanged -= GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rs150m.ValueChanged -= GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rs200m.ValueChanged -= GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rs250m.ValueChanged -= GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rs300m.ValueChanged -= GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rs350m.ValueChanged -= GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rs400m.ValueChanged -= GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rsx350m.ValueChanged -= GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rsx300m.ValueChanged -= GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rsx250m.ValueChanged -= GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rsx200m.ValueChanged -= GP34Form2.GP34_numericUpDown_ValueChanged;
                                //
                                ActiveForm2 = GP34Form2;
                                HwName = "GP34";
                                GP34Form2.GP34_device.Text = HwName;
                                GP34Form2.GP34_serial.Text = SerialNumber;
                                GP34Form2.GP34_year.Text = "" + ProductionYear;
                                GP34Form2.GP34_address.Text = "" + BaseAddress;
                                GP34Form2.GP34_hw.Text = HwVersion;
                                GP34Form2.GP34_sw.Text = SwVersion;
                                GP34Form2.GP34_shots.Text = "" + TotalShots;
                                GP34Form2.GP34_powerons.Text = "" + Powerons;
                                GP34Form2.GP34_trigger1low.Text = "" + Trigger1Low;
                                GP34Form2.GP34_trigger1high.Text = "" + Trigger1High;
                                GP34Form2.GP34_trigger2low.Text = "" + Trigger2Low;
                                GP34Form2.GP34_trigger2high.Text = "" + Trigger2High;
                                GP34Form2.GP34_rs0m.Text = "" + RS0m;
                                GP34Form2.GP34_rs100m.Text = "" + RS100m;
                                GP34Form2.GP34_rs150m.Text = "" + RS150m;
                                GP34Form2.GP34_rs200m.Text = "" + RS200m;
                                GP34Form2.GP34_rs250m.Text = "" + RS250m;
                                GP34Form2.GP34_rs300m.Text = "" + RS300m;
                                GP34Form2.GP34_rs350m.Text = "" + RS350m;
                                GP34Form2.GP34_rs400m.Text = "" + RS400m;
                                GP34Form2.GP34_rsx350m.Text = "" + RSx350m;
                                GP34Form2.GP34_rsx300m.Text = "" + RSx300m;
                                GP34Form2.GP34_rsx250m.Text = "" + RSx250m;
                                GP34Form2.GP34_rsx200m.Text = "" + RSx200m;
                                //zapnutie eventu pri zmene numericupdown
                                GP34Form2.GP34_trigger1low.ValueChanged += GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_trigger1high.ValueChanged += GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_trigger2low.ValueChanged += GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_trigger2high.ValueChanged += GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rs0m.ValueChanged += GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rs100m.ValueChanged += GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rs150m.ValueChanged += GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rs200m.ValueChanged += GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rs250m.ValueChanged += GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rs300m.ValueChanged += GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rs350m.ValueChanged += GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rs400m.ValueChanged += GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rsx350m.ValueChanged += GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rsx300m.ValueChanged += GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rsx250m.ValueChanged += GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rsx200m.ValueChanged += GP34Form2.GP34_numericUpDown_ValueChanged;
                                //
                                break;
                            case (138):
                                label1.Text = " M60 weapon found";
                                M60.M60Form M60Form2 = new M60.M60Form();
                                M60Form2.Show();
                                //vypnutie eventu pri zmene numericupdown
                                M60Form2.M60_treshlow.ValueChanged -= M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_treshhigh.ValueChanged -= M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_hs3release.ValueChanged -= M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_hs3hold.ValueChanged -= M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_tempdown.ValueChanged -= M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_tempup.ValueChanged -= M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_maxledpwm.ValueChanged -= M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_downstep1.ValueChanged -= M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_downstep2.ValueChanged -= M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_downstep3.ValueChanged -= M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_upstep1.ValueChanged -= M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_upstep2.ValueChanged -= M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_upstep3.ValueChanged -= M60Form2.M60_numericUpDown_ValueChanged;
                                //
                                ActiveForm2 = M60Form2;
                                HwName = "M60";
                                M60Form2.M60_device.Text = HwName;
                                M60Form2.M60_serial.Text = SerialNumber;
                                M60Form2.M60_year.Text = "" + ProductionYear;
                                M60Form2.M60_address.Text = "" + BaseAddress;
                                M60Form2.M60_hw.Text = HwVersion;
                                M60Form2.M60_sw.Text = SwVersion;
                                M60Form2.M60_shots.Text = "" + TotalShots;
                                M60Form2.M60_powerons.Text = "" + Powerons;
                                M60Form2.M60_reloads.Text = "" + BeltReloads;
                                M60Form2.M60_treshlow.Text = "" + TresholdLow;
                                M60Form2.M60_treshhigh.Text = "" + TresholdHigh;
                                M60Form2.M60_hs3release.Text = "" + HS3Release;
                                M60Form2.M60_hs3hold.Text = "" + HS3Hold;
                                M60Form2.M60_tempdown.Text = "" + TempDown;
                                M60Form2.M60_tempup.Text = "" + TempUp;
                                M60Form2.M60_maxledpwm.Text = "" + MaxLedPWM;
                                M60Form2.M60_downstep1.Text = "" + DownStep1;
                                M60Form2.M60_downstep2.Text = "" + DownStep2;
                                M60Form2.M60_downstep3.Text = "" + DownStep3;
                                M60Form2.M60_upstep1.Text = "" + UpStep1;
                                M60Form2.M60_upstep2.Text = "" + UpStep2;
                                M60Form2.M60_upstep3.Text = "" + UpStep3;
                                //zapnutie eventu pri zmene numericupdown
                                M60Form2.M60_treshlow.ValueChanged += M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_treshhigh.ValueChanged += M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_hs3release.ValueChanged += M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_hs3hold.ValueChanged += M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_tempdown.ValueChanged += M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_tempup.ValueChanged += M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_maxledpwm.ValueChanged += M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_downstep1.ValueChanged += M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_downstep2.ValueChanged += M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_downstep3.ValueChanged += M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_upstep1.ValueChanged += M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_upstep2.ValueChanged += M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_upstep3.ValueChanged += M60Form2.M60_numericUpDown_ValueChanged;
                                //
                                break;
                            case (254):
                                label1.Text = " RezervaA weapon found";
                                RezervaA.RezervaAForm RezervaAForm2 = new RezervaA.RezervaAForm();
                                RezervaAForm2.Show();
                                //vypnutie eventu pri zmene numericupdown
                                RezervaAForm2.RezervaA_treshlow.ValueChanged -= RezervaAForm2.RezervaA_numericUpDown_ValueChanged;
                                RezervaAForm2.RezervaA_treshhigh.ValueChanged -= RezervaAForm2.RezervaA_numericUpDown_ValueChanged;
                                RezervaAForm2.RezervaA_triggerrelease.ValueChanged -= RezervaAForm2.RezervaA_numericUpDown_ValueChanged;
                                RezervaAForm2.RezervaA_triggerhold.ValueChanged -= RezervaAForm2.RezervaA_numericUpDown_ValueChanged;
                                //
                                ActiveForm2 = RezervaAForm2;
                                HwName = "RezervaA";
                                RezervaAForm2.RezervaA_device.Text = HwName;
                                RezervaAForm2.RezervaA_serial.Text = SerialNumber;
                                RezervaAForm2.RezervaA_year.Text = "" + ProductionYear;
                                RezervaAForm2.RezervaA_address.Text = "" + BaseAddress;
                                RezervaAForm2.RezervaA_hw.Text = HwVersion;
                                RezervaAForm2.RezervaA_sw.Text = SwVersion;
                                RezervaAForm2.RezervaA_shots.Text = "" + TotalShots;
                                RezervaAForm2.RezervaA_powerons.Text = "" + Powerons;
                                RezervaAForm2.RezervaA_boltcatches.Text = "" + BoltCatches;
                                RezervaAForm2.RezervaA_treshlow.Text = "" + TresholdLow;
                                RezervaAForm2.RezervaA_treshhigh.Text = "" + TresholdHigh;
                                RezervaAForm2.RezervaA_triggerrelease.Text = "" + TriggerRelease;
                                RezervaAForm2.RezervaA_triggerhold.Text = "" + TriggerHold;
                                //zapnutie eventu pri zmene numericupdown
                                RezervaAForm2.RezervaA_treshlow.ValueChanged += RezervaAForm2.RezervaA_numericUpDown_ValueChanged;
                                RezervaAForm2.RezervaA_treshhigh.ValueChanged += RezervaAForm2.RezervaA_numericUpDown_ValueChanged;
                                RezervaAForm2.RezervaA_triggerrelease.ValueChanged += RezervaAForm2.RezervaA_numericUpDown_ValueChanged;
                                RezervaAForm2.RezervaA_triggerhold.ValueChanged += RezervaAForm2.RezervaA_numericUpDown_ValueChanged;
                                //
                                break;
                            case (255):
                                label1.Text = " RezervaB weapon found";
                                RezervaB.RezervaBForm RezervaBForm2 = new RezervaB.RezervaBForm();
                                RezervaBForm2.Show();
                                //vypnutie eventu pri zmene numericupdown
                                RezervaBForm2.RezervaB_treshlow.ValueChanged -= RezervaBForm2.RezervaB_numericUpDown_ValueChanged;
                                RezervaBForm2.RezervaB_treshhigh.ValueChanged -= RezervaBForm2.RezervaB_numericUpDown_ValueChanged;
                                RezervaBForm2.RezervaB_triggerrelease.ValueChanged -= RezervaBForm2.RezervaB_numericUpDown_ValueChanged;
                                RezervaBForm2.RezervaB_triggerhold.ValueChanged -= RezervaBForm2.RezervaB_numericUpDown_ValueChanged;
                                //
                                ActiveForm2 = RezervaBForm2;
                                HwName = "RezervaB";
                                RezervaBForm2.RezervaB_device.Text = HwName;
                                RezervaBForm2.RezervaB_serial.Text = SerialNumber;
                                RezervaBForm2.RezervaB_year.Text = "" + ProductionYear;
                                RezervaBForm2.RezervaB_address.Text = "" + BaseAddress;
                                RezervaBForm2.RezervaB_hw.Text = HwVersion;
                                RezervaBForm2.RezervaB_sw.Text = SwVersion;
                                RezervaBForm2.RezervaB_shots.Text = "" + TotalShots;
                                RezervaBForm2.RezervaB_powerons.Text = "" + Powerons;
                                RezervaBForm2.RezervaB_boltcatches.Text = "" + BoltCatches;
                                RezervaBForm2.RezervaB_treshlow.Text = "" + TresholdLow;
                                RezervaBForm2.RezervaB_treshhigh.Text = "" + TresholdHigh;
                                RezervaBForm2.RezervaB_triggerrelease.Text = "" + TriggerRelease;
                                RezervaBForm2.RezervaB_triggerhold.Text = "" + TriggerHold;
                                //zapnutie eventu pri zmene numericupdown
                                RezervaBForm2.RezervaB_treshlow.ValueChanged += RezervaBForm2.RezervaB_numericUpDown_ValueChanged;
                                RezervaBForm2.RezervaB_treshhigh.ValueChanged += RezervaBForm2.RezervaB_numericUpDown_ValueChanged;
                                RezervaBForm2.RezervaB_triggerrelease.ValueChanged += RezervaBForm2.RezervaB_numericUpDown_ValueChanged;
                                RezervaBForm2.RezervaB_triggerhold.ValueChanged += RezervaBForm2.RezervaB_numericUpDown_ValueChanged;
                                //
                                break;
                            default:
                                label1.Text = "Unknown weapon found";
                                break;
                        }



                    }
                }

                toolStripStatusLabel2.Text = "RX: " + RxCounter;
            }
            catch (Exception ee)
            {
                MessageBox.Show("CANaerospace server is offline.");
            }

        }


        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void mP5ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MP5.MP5Form MP5Form1 = new MP5.MP5Form();
            MP5Form1.Show();
            MP5Form1.MP5_device.Text = "MP5 - OFFLINE";
            MP5Form1.MP5_shot.Enabled = false;
            MP5Form1.MP5_refresh.Enabled = false;
            MP5Form1.MP5_treshlow.ValueChanged -= MP5Form1.MP5_numericUpDown_ValueChanged;
            MP5Form1.MP5_treshhigh.ValueChanged -= MP5Form1.MP5_numericUpDown_ValueChanged;
            MP5Form1.MP5_sensormin.ValueChanged -= MP5Form1.MP5_numericUpDown_ValueChanged;
            MP5Form1.MP5_sensormax.ValueChanged -= MP5Form1.MP5_numericUpDown_ValueChanged;
            MP5Form1.MP5_hallmax.ValueChanged -= MP5Form1.MP5_numericUpDown_ValueChanged;
            MP5Form1.MP5_halfrange.ValueChanged -= MP5Form1.MP5_numericUpDown_ValueChanged;
            MP5Form1.MP5_peakfilter.ValueChanged -= MP5Form1.MP5_numericUpDown_ValueChanged;
        }

        private void aK103GP34ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AK103.AK103Form AK103Form1 = new AK103.AK103Form();
            AK103Form1.Show();
            AK103Form1.AK103_device.Text = "AK103 - OFFLINE";
            AK103Form1.AK103_shot.Enabled = false;
            AK103Form1.AK103_refresh.Enabled = false;
            AK103Form1.AK103_treshlow.ValueChanged -= AK103Form1.AK103_numericUpDown_ValueChanged;
            AK103Form1.AK103_treshhigh.ValueChanged -= AK103Form1.AK103_numericUpDown_ValueChanged;
            AK103Form1.AK103_voltoffset.ValueChanged -= AK103Form1.AK103_numericUpDown_ValueChanged;
            AK103Form1.AK103_dagain.ValueChanged -= AK103Form1.AK103_numericUpDown_ValueChanged;
            AK103Form1.AK103_rs100m.ValueChanged -= AK103Form1.AK103_numericUpDown_ValueChanged;
            AK103Form1.AK103_rs200m.ValueChanged -= AK103Form1.AK103_numericUpDown_ValueChanged;
            AK103Form1.AK103_rs300m.ValueChanged -= AK103Form1.AK103_numericUpDown_ValueChanged;
            AK103Form1.AK103_rs400m.ValueChanged -= AK103Form1.AK103_numericUpDown_ValueChanged;
            AK103Form1.AK103_rs500m.ValueChanged -= AK103Form1.AK103_numericUpDown_ValueChanged;
            AK103Form1.AK103_rs600m.ValueChanged -= AK103Form1.AK103_numericUpDown_ValueChanged;
            AK103Form1.AK103_rs700m.ValueChanged -= AK103Form1.AK103_numericUpDown_ValueChanged;
            AK103Form1.AK103_rs800m.ValueChanged -= AK103Form1.AK103_numericUpDown_ValueChanged;
        }

        private void gP34ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AK103.GP34Form GP34Form1 = new AK103.GP34Form();
            GP34Form1.Show();
            GP34Form1.GP34_device.Text = "GP34 - OFFLINE";
            GP34Form1.GP34_shot.Enabled = false;
            GP34Form1.GP34_refresh.Enabled = false;
            GP34Form1.GP34_trigger1low.ValueChanged -= GP34Form1.GP34_numericUpDown_ValueChanged;
            GP34Form1.GP34_trigger1high.ValueChanged -= GP34Form1.GP34_numericUpDown_ValueChanged;
            GP34Form1.GP34_trigger2low.ValueChanged -= GP34Form1.GP34_numericUpDown_ValueChanged;
            GP34Form1.GP34_trigger2high.ValueChanged -= GP34Form1.GP34_numericUpDown_ValueChanged;
            GP34Form1.GP34_rs0m.ValueChanged -= GP34Form1.GP34_numericUpDown_ValueChanged;
            GP34Form1.GP34_rs100m.ValueChanged -= GP34Form1.GP34_numericUpDown_ValueChanged;
            GP34Form1.GP34_rs150m.ValueChanged -= GP34Form1.GP34_numericUpDown_ValueChanged;
            GP34Form1.GP34_rs200m.ValueChanged -= GP34Form1.GP34_numericUpDown_ValueChanged;
            GP34Form1.GP34_rs250m.ValueChanged -= GP34Form1.GP34_numericUpDown_ValueChanged;
            GP34Form1.GP34_rs300m.ValueChanged -= GP34Form1.GP34_numericUpDown_ValueChanged;
            GP34Form1.GP34_rs350m.ValueChanged -= GP34Form1.GP34_numericUpDown_ValueChanged;
            GP34Form1.GP34_rs400m.ValueChanged -= GP34Form1.GP34_numericUpDown_ValueChanged;
            GP34Form1.GP34_rsx350m.ValueChanged -= GP34Form1.GP34_numericUpDown_ValueChanged;
            GP34Form1.GP34_rsx300m.ValueChanged -= GP34Form1.GP34_numericUpDown_ValueChanged;
            GP34Form1.GP34_rsx250m.ValueChanged -= GP34Form1.GP34_numericUpDown_ValueChanged;
            GP34Form1.GP34_rsx200m.ValueChanged -= GP34Form1.GP34_numericUpDown_ValueChanged;
        }

        private void g3ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            G3.G3Form G3Form1 = new G3.G3Form();
            G3Form1.Show();
            G3Form1.G3_device.Text = "G3 - OFFLINE";
            G3Form1.G3_shot.Enabled = false;
            G3Form1.G3_refresh.Enabled = false;
            G3Form1.G3_treshlow.ValueChanged -= G3Form1.G3_numericUpDown_ValueChanged;
            G3Form1.G3_treshhigh.ValueChanged -= G3Form1.G3_numericUpDown_ValueChanged;
            G3Form1.G3_sensor1alow.ValueChanged -= G3Form1.G3_numericUpDown_ValueChanged;
            G3Form1.G3_sensor1ahigh.ValueChanged -= G3Form1.G3_numericUpDown_ValueChanged;
            G3Form1.G3_sensor1blow.ValueChanged -= G3Form1.G3_numericUpDown_ValueChanged;
            G3Form1.G3_sensor1bhigh.ValueChanged -= G3Form1.G3_numericUpDown_ValueChanged;
        }

        private void g36ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            G36.G36Form G36Form1 = new G36.G36Form();
            G36Form1.Show();
            G36Form1.G36_device.Text = "G36 - OFFLINE";
            G36Form1.G36_shot.Enabled = false;
            G36Form1.G36_refresh.Enabled = false;
            G36Form1.G36_treshlow.ValueChanged -= G36Form1.G36_numericUpDown_ValueChanged;
            G36Form1.G36_treshhigh.ValueChanged -= G36Form1.G36_numericUpDown_ValueChanged;
            G36Form1.G36_sensor1alow.ValueChanged -= G36Form1.G36_numericUpDown_ValueChanged;
            G36Form1.G36_sensor1ahigh.ValueChanged -= G36Form1.G36_numericUpDown_ValueChanged;
            G36Form1.G36_sensor1blow.ValueChanged -= G36Form1.G36_numericUpDown_ValueChanged;
            G36Form1.G36_sensor1bhigh.ValueChanged -= G36Form1.G36_numericUpDown_ValueChanged;
        }

        private void m60ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            M60.M60Form M60Form1 = new M60.M60Form();
            M60Form1.Show();
            M60Form1.M60_device.Text = "M60 - OFFLINE";
            M60Form1.M60_shot.Enabled = false;
            M60Form1.M60_release.Enabled = false;
            M60Form1.M60_refresh.Enabled = false;
            M60Form1.M60_treshlow.ValueChanged -= M60Form1.M60_numericUpDown_ValueChanged;
            M60Form1.M60_treshhigh.ValueChanged -= M60Form1.M60_numericUpDown_ValueChanged;
            M60Form1.M60_hs3release.ValueChanged -= M60Form1.M60_numericUpDown_ValueChanged;
            M60Form1.M60_hs3hold.ValueChanged -= M60Form1.M60_numericUpDown_ValueChanged;
            M60Form1.M60_tempdown.ValueChanged -= M60Form1.M60_numericUpDown_ValueChanged;
            M60Form1.M60_tempup.ValueChanged -= M60Form1.M60_numericUpDown_ValueChanged;
            M60Form1.M60_maxledpwm.ValueChanged -= M60Form1.M60_numericUpDown_ValueChanged;
            M60Form1.M60_downstep1.ValueChanged -= M60Form1.M60_numericUpDown_ValueChanged;
            M60Form1.M60_downstep2.ValueChanged -= M60Form1.M60_numericUpDown_ValueChanged;
            M60Form1.M60_downstep3.ValueChanged -= M60Form1.M60_numericUpDown_ValueChanged;
            M60Form1.M60_upstep1.ValueChanged -= M60Form1.M60_numericUpDown_ValueChanged;
            M60Form1.M60_upstep2.ValueChanged -= M60Form1.M60_numericUpDown_ValueChanged;
            M60Form1.M60_upstep3.ValueChanged -= M60Form1.M60_numericUpDown_ValueChanged;
        }

        private void mG30ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MG3.MG3Form MG3Form1 = new MG3.MG3Form();
            MG3Form1.Show();
            MG3Form1.MG3_device.Text = "MG3 - OFFLINE";
            MG3Form1.MG3_shot.Enabled = false;
            MG3Form1.MG3_release.Enabled = false;
            MG3Form1.MG3_refresh.Enabled = false;
            MG3Form1.MG3_treshlow.ValueChanged -= MG3Form1.MG3_numericUpDown_ValueChanged;
            MG3Form1.MG3_treshhigh.ValueChanged -= MG3Form1.MG3_numericUpDown_ValueChanged;
            MG3Form1.MG3_hs3release.ValueChanged -= MG3Form1.MG3_numericUpDown_ValueChanged;
            MG3Form1.MG3_hs3hold.ValueChanged -= MG3Form1.MG3_numericUpDown_ValueChanged;
            MG3Form1.MG3_tempdown.ValueChanged -= MG3Form1.MG3_numericUpDown_ValueChanged;
            MG3Form1.MG3_tempup.ValueChanged -= MG3Form1.MG3_numericUpDown_ValueChanged;
            MG3Form1.MG3_maxledpwm.ValueChanged -= MG3Form1.MG3_numericUpDown_ValueChanged;
            MG3Form1.MG3_downstep1.ValueChanged -= MG3Form1.MG3_numericUpDown_ValueChanged;
            MG3Form1.MG3_downstep2.ValueChanged -= MG3Form1.MG3_numericUpDown_ValueChanged;
            MG3Form1.MG3_downstep3.ValueChanged -= MG3Form1.MG3_numericUpDown_ValueChanged;
            MG3Form1.MG3_upstep1.ValueChanged -= MG3Form1.MG3_numericUpDown_ValueChanged;
            MG3Form1.MG3_upstep2.ValueChanged -= MG3Form1.MG3_numericUpDown_ValueChanged;
            MG3Form1.MG3_upstep3.ValueChanged -= MG3Form1.MG3_numericUpDown_ValueChanged;
        }

        private void lRT3ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LRT3.LRT3Form LRT3Form1 = new LRT3.LRT3Form();
            LRT3Form1.Show();
            LRT3Form1.LRT3_device.Text = "LRT3 - OFFLINE";
            LRT3Form1.LRT3_shot.Enabled = false;
            LRT3Form1.LRT3_refresh.Enabled = false;
            LRT3Form1.LRT3_treshlow.ValueChanged -= LRT3Form1.LRT3_numericUpDown_ValueChanged;
            LRT3Form1.LRT3_treshhigh.ValueChanged -= LRT3Form1.LRT3_numericUpDown_ValueChanged;
            LRT3Form1.LRT3_triggerrelease.ValueChanged -= LRT3Form1.LRT3_numericUpDown_ValueChanged;
            LRT3Form1.LRT3_triggerhold.ValueChanged -= LRT3Form1.LRT3_numericUpDown_ValueChanged;
            LRT3Form1.LRT3_boltlocktresh.ValueChanged -= LRT3Form1.LRT3_numericUpDown_ValueChanged;
            LRT3Form1.LRT3_boltunlocktresh.ValueChanged -= LRT3Form1.LRT3_numericUpDown_ValueChanged;
            LRT3Form1.LRT3_firingpintresh.ValueChanged -= LRT3Form1.LRT3_numericUpDown_ValueChanged;
            LRT3Form1.LRT3_firingpindaoffset.ValueChanged -= LRT3Form1.LRT3_numericUpDown_ValueChanged;
            LRT3Form1.LRT3_safetresh.ValueChanged -= LRT3Form1.LRT3_numericUpDown_ValueChanged;
            LRT3Form1.LRT3_safedaoffset.ValueChanged -= LRT3Form1.LRT3_numericUpDown_ValueChanged;
        }

        private void cOYOTEToolStripMenuItem_Click(object sender, EventArgs e)
        {
            COYOTE.COYOTEForm COYOTEForm1 = new COYOTE.COYOTEForm();
            COYOTEForm1.Show();
            COYOTEForm1.COYOTE_device.Text = "COYOTE - OFFLINE";
            COYOTEForm1.COYOTE_shot.Enabled = false;
            COYOTEForm1.COYOTE_refresh.Enabled = false;
            COYOTEForm1.COYOTE_treshlow.ValueChanged -= COYOTEForm1.COYOTE_numericUpDown_ValueChanged;
            COYOTEForm1.COYOTE_treshhigh.ValueChanged -= COYOTEForm1.COYOTE_numericUpDown_ValueChanged;
            COYOTEForm1.COYOTE_triggerrelease.ValueChanged -= COYOTEForm1.COYOTE_numericUpDown_ValueChanged;
            COYOTEForm1.COYOTE_triggerhold.ValueChanged -= COYOTEForm1.COYOTE_numericUpDown_ValueChanged;
            COYOTEForm1.COYOTE_boltlocktresh.ValueChanged -= COYOTEForm1.COYOTE_numericUpDown_ValueChanged;
            COYOTEForm1.COYOTE_boltunlocktresh.ValueChanged -= COYOTEForm1.COYOTE_numericUpDown_ValueChanged;
            COYOTEForm1.COYOTE_firingpintresh.ValueChanged -= COYOTEForm1.COYOTE_numericUpDown_ValueChanged;
            COYOTEForm1.COYOTE_firingpindaoffset.ValueChanged -= COYOTEForm1.COYOTE_numericUpDown_ValueChanged;
            COYOTEForm1.COYOTE_safetresh.ValueChanged -= COYOTEForm1.COYOTE_numericUpDown_ValueChanged;
            COYOTEForm1.COYOTE_safedaoffset.ValueChanged -= COYOTEForm1.COYOTE_numericUpDown_ValueChanged;
        }

        private void tIMBERWOLFToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TIMBER.TIMBERForm TIMBERForm1 = new TIMBER.TIMBERForm();
            TIMBERForm1.Show();
            TIMBERForm1.TIMBER_device.Text = "TIMBERWOLF - OFFLINE";
            TIMBERForm1.TIMBER_shot.Enabled = false;
            TIMBERForm1.TIMBER_refresh.Enabled = false;
            TIMBERForm1.TIMBER_treshlow.ValueChanged -= TIMBERForm1.TIMBER_numericUpDown_ValueChanged;
            TIMBERForm1.TIMBER_treshhigh.ValueChanged -= TIMBERForm1.TIMBER_numericUpDown_ValueChanged;
            TIMBERForm1.TIMBER_triggerrelease.ValueChanged -= TIMBERForm1.TIMBER_numericUpDown_ValueChanged;
            TIMBERForm1.TIMBER_triggerhold.ValueChanged -= TIMBERForm1.TIMBER_numericUpDown_ValueChanged;
            TIMBERForm1.TIMBER_boltlocktresh.ValueChanged -= TIMBERForm1.TIMBER_numericUpDown_ValueChanged;
            TIMBERForm1.TIMBER_boltunlocktresh.ValueChanged -= TIMBERForm1.TIMBER_numericUpDown_ValueChanged;
            TIMBERForm1.TIMBER_firingpintresh.ValueChanged -= TIMBERForm1.TIMBER_numericUpDown_ValueChanged;
            TIMBERForm1.TIMBER_firingpindaoffset.ValueChanged -= TIMBERForm1.TIMBER_numericUpDown_ValueChanged;
            TIMBERForm1.TIMBER_safetresh.ValueChanged -= TIMBERForm1.TIMBER_numericUpDown_ValueChanged;
            TIMBERForm1.TIMBER_safedaoffset.ValueChanged -= TIMBERForm1.TIMBER_numericUpDown_ValueChanged;
        }

        private void gLOCKToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GLOCK.GLOCKForm GLOCKForm1 = new GLOCK.GLOCKForm();
            GLOCKForm1.Show();
            GLOCKForm1.GLOCK_device.Text = "GLOCK - OFFLINE";
            GLOCKForm1.GLOCK_valve.Enabled = false;
            GLOCKForm1.GLOCK_shot.Enabled = false;
            GLOCKForm1.GLOCK_refresh.Enabled = false;
            GLOCKForm1.GLOCK_mainmagshot.Enabled = false;
            GLOCKForm1.GLOCK_treshlow.ValueChanged -= GLOCKForm1.GLOCK_numericUpDown_ValueChanged;
            GLOCKForm1.GLOCK_treshhigh.ValueChanged -= GLOCKForm1.GLOCK_numericUpDown_ValueChanged;
            GLOCKForm1.GLOCK_triggerrelease.ValueChanged -= GLOCKForm1.GLOCK_numericUpDown_ValueChanged;
            GLOCKForm1.GLOCK_triggerhold.ValueChanged -= GLOCKForm1.GLOCK_numericUpDown_ValueChanged;
        }

        private void bROWNINGToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BROWN.BROWNForm BROWNForm1 = new BROWN.BROWNForm();
            BROWNForm1.Show();
            BROWNForm1.BROWN_device.Text = "BROWNING - OFFLINE";
            BROWNForm1.BROWN_valve.Enabled = false;
            BROWNForm1.BROWN_shot.Enabled = false;
            BROWNForm1.BROWN_refresh.Enabled = false;
            BROWNForm1.BROWN_treshlow.ValueChanged -= BROWNForm1.BROWN_numericUpDown_ValueChanged;
            BROWNForm1.BROWN_treshhigh.ValueChanged -= BROWNForm1.BROWN_numericUpDown_ValueChanged;
            BROWNForm1.BROWN_triggerrelease.ValueChanged -= BROWNForm1.BROWN_numericUpDown_ValueChanged;
            BROWNForm1.BROWN_triggerhold.ValueChanged -= BROWNForm1.BROWN_numericUpDown_ValueChanged;
        }

        private void rPG7ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            RPG7.RPG7Form RPG7Form1 = new RPG7.RPG7Form();
            RPG7Form1.Show();
            RPG7Form1.RPG7_device.Text = "RPG7 - OFFLINE";
            RPG7Form1.RPG7_shot.Enabled = false;
            RPG7Form1.RPG7_refresh.Enabled = false;
            RPG7Form1.RPG7_treshlow.ValueChanged -= RPG7Form1.RPG7_numericUpDown_ValueChanged;
            RPG7Form1.RPG7_treshhigh.ValueChanged -= RPG7Form1.RPG7_numericUpDown_ValueChanged;
            RPG7Form1.RPG7_voltoffset.ValueChanged -= RPG7Form1.RPG7_numericUpDown_ValueChanged;
            RPG7Form1.RPG7_dagain.ValueChanged -= RPG7Form1.RPG7_numericUpDown_ValueChanged;
        }

        private void rezervaAToolStripMenuItem_Click(object sender, EventArgs e)
        {
            RezervaA.RezervaAForm RezervaAForm1 = new RezervaA.RezervaAForm();
            RezervaAForm1.Show();
            RezervaAForm1.RezervaA_device.Text = "RezervaA - OFFLINE";
            RezervaAForm1.RezervaA_valve.Enabled = false;
            RezervaAForm1.RezervaA_shot.Enabled = false;
            RezervaAForm1.RezervaA_refresh.Enabled = false;
            RezervaAForm1.RezervaA_mainmagshot.Enabled = false;
            RezervaAForm1.RezervaA_treshlow.ValueChanged -= RezervaAForm1.RezervaA_numericUpDown_ValueChanged;
            RezervaAForm1.RezervaA_treshhigh.ValueChanged -= RezervaAForm1.RezervaA_numericUpDown_ValueChanged;
            RezervaAForm1.RezervaA_triggerrelease.ValueChanged -= RezervaAForm1.RezervaA_numericUpDown_ValueChanged;
            RezervaAForm1.RezervaA_triggerhold.ValueChanged -= RezervaAForm1.RezervaA_numericUpDown_ValueChanged;
        }

        private void rezervaBToolStripMenuItem_Click(object sender, EventArgs e)
        {
            RezervaB.RezervaBForm RezervaBForm1 = new RezervaB.RezervaBForm();
            RezervaBForm1.Show();
            RezervaBForm1.RezervaB_device.Text = "RezervaB - OFFLINE";
            RezervaBForm1.RezervaB_valve.Enabled = false;
            RezervaBForm1.RezervaB_shot.Enabled = false;
            RezervaBForm1.RezervaB_refresh.Enabled = false;
            RezervaBForm1.RezervaB_mainmagshot.Enabled = false;
            RezervaBForm1.RezervaB_treshlow.ValueChanged -= RezervaBForm1.RezervaB_numericUpDown_ValueChanged;
            RezervaBForm1.RezervaB_treshhigh.ValueChanged -= RezervaBForm1.RezervaB_numericUpDown_ValueChanged;
            RezervaBForm1.RezervaB_triggerrelease.ValueChanged -= RezervaBForm1.RezervaB_numericUpDown_ValueChanged;
            RezervaBForm1.RezervaB_triggerhold.ValueChanged -= RezervaBForm1.RezervaB_numericUpDown_ValueChanged;
        }

        private void flashFirmwareToolStripMenuItem_Click(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            label1.Text = "Flashing firmware";
            if (ActiveForm2 != null) ActiveForm2.Close();
            ActiveForm2 = null;
            RxCounter = 0;
            canConnection.Dispose();
            wasDisconected = true;
            toolStripStatusLabel2.Text = "RX: " + RxCounter;
            //toolStripStatusLabel3.Text = "TX: 0";
            try
            {
                System.Diagnostics.Process[] proc = System.Diagnostics.Process.GetProcessesByName("CanAerospaceServer");
                proc[0].Kill();
            }
            catch (Exception ee3)
            {
                MessageBox.Show("Unknown error");
            }

            FlashFirmware FlashForm = new FlashFirmware();
            FlashForm.Show();
            /*System.Diagnostics.Process.Start(@"C:\Program Files (x86)\Flash Magic\FlashMagic.exe");
            Thread.Sleep(7000);*/
            backToolStripMenuItem1.Visible = true;
            flashFirmwareToolStripMenuItem.Visible = false;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            if (RxCounter > 0)
            {
                toolStripStatusLabel1.Text = "Weapon connected...   ";
            }
            else
            {
                toolStripStatusLabel1.Text = "No device connected...";
            }

            try
            {

                if (wasDisconected)
                {
                    // MyCanAerospace 
                    canConnection = new MyCanAerospace();
                    string requesterAddress = "tcp://localhost:5555";
                    string subscriberAddress = "tcp://localhost:5556";

                    //CommunicatorZmq 
                    zmqCommunicator = new CommunicatorZmq(subscriberAddress, requesterAddress);

                    zmqCommunicator.Init();
                    canConnection.Init(zmqCommunicator);

                    wasDisconected = false;
                }

                uint weaponChannel = 100;
                //uint canId = 2000;
                

                //------prepnutie do service mode
                if (canConnection.CyclicValueStorage.Keys.Count == 0)
                {
                    if (canConnection.IsServerOnline())
                    {
                        if (canConnection.IsDeviceOpen())
                        {
                            canConnection.SendResetDevice();
                            Thread.Sleep(3000);
                        }
                    }
                }
                
                if (canConnection.IsServerOnline())
                {
                    if (canConnection.IsDeviceOpen())
                    {
                        if (ActiveForm2 == null) {
                        RxCounter = RxCounter + 1;

                        //------zistenie NodeId (aka zbran) z cyklicky vysielanych dat
                        byte weaponNodeId = canConnection.CyclicValueStorage.Keys.ToArray()[0].nodeId;

                        //------vycitanie zakladnych registrov
                        foreach (WeaponRegister register in Enum.GetValues(typeof(WeaponRegister)))
                        {
                            for (int attempts = 0; attempts < 3; attempts++)
                            {
                                canConnection.SendRegisterReadRequest(weaponChannel, weaponNodeId, (byte)register);
                                RegisterKey regKey = new RegisterKey(weaponNodeId, (byte)register);
                                CanData registerData = null;
                                Thread.Sleep(1000);
                                if (canConnection.GetRegisterValue(regKey, out registerData) &&
                                    registerData.GetDataType() != CanData.DataType.DT_NODATA)
                                {
                                    switch (register)
                                    {
                                        case (WeaponRegister.HwName):
                                            HwName = registerData.GetAsAchar4();
                                            break;

                                        case (WeaponRegister.SerialNumber):
                                            SerialNumber = registerData.GetAsAchar4();
                                            break;

                                        case (WeaponRegister.BaseAddress):
                                            BaseAddress = registerData.GetAsUchar();
                                            break;

                                        case (WeaponRegister.ProductionYear):
                                            ProductionYear = Convert.ToInt32(registerData.GetAsUshort());
                                            break;

                                        case (WeaponRegister.AccOffsetX):
                                            AccOffsetX = registerData.GetAsFloat();
                                            break;

                                        case (WeaponRegister.AccOffsetY):
                                            AccOffsetY = registerData.GetAsFloat();
                                            break;

                                        case (WeaponRegister.AccOffsetZ):
                                            AccOffsetZ = registerData.GetAsFloat();
                                            break;

                                        case (WeaponRegister.TotalShots):
                                            TotalShots = registerData.GetAsUlong();
                                            break;

                                        case (WeaponRegister.Powerons):
                                            Powerons = registerData.GetAsUlong();
                                            break;

                                    }
                                    break;
                                }
                                // pockat pred dalsim pokusom
                                Thread.Sleep(100);
                            }
                            RxCounter = RxCounter + 1;
                        }

                        //------vycitanie specialnych registrov
                        if (weaponNodeId == 2) //glock
                        {
                            foreach (GLOCK_WeaponRegister register in Enum.GetValues(typeof(GLOCK_WeaponRegister)))
                            {
                                for (int attempts = 0; attempts < 3; attempts++)
                                {
                                    canConnection.SendRegisterReadRequest(weaponChannel, weaponNodeId, (byte)register);
                                    RegisterKey regKey = new RegisterKey(weaponNodeId, (byte)register);
                                    CanData registerData = null;
                                    Thread.Sleep(1000);
                                    if (canConnection.GetRegisterValue(regKey, out registerData) &&
                                        registerData.GetDataType() != CanData.DataType.DT_NODATA)
                                    {
                                        switch (register)
                                        {
                                            case (GLOCK_WeaponRegister.BoltCatches):
                                                BoltCatches = registerData.GetAsUlong();
                                                break;

                                            case (GLOCK_WeaponRegister.TresholdLow):
                                                TresholdLow = registerData.GetAsUchar();
                                                break;

                                            case (GLOCK_WeaponRegister.TresholdHigh):
                                                TresholdHigh = registerData.GetAsUchar();
                                                break;

                                            case (GLOCK_WeaponRegister.TriggerRelease):
                                                TriggerRelease = registerData.GetAsShort();
                                                break;

                                            case (GLOCK_WeaponRegister.TriggerHold):
                                                TriggerHold = registerData.GetAsShort();
                                                break;

                                        }
                                        break;
                                    }
                                    // pockat pred dalsim pokusom
                                    Thread.Sleep(100);
                                }
                                RxCounter = RxCounter + 1;
                            }
                        }

                        if (weaponNodeId == 132) //mp5
                        {
                            foreach (MP5_WeaponRegister register in Enum.GetValues(typeof(MP5_WeaponRegister)))
                            {
                                for (int attempts = 0; attempts < 3; attempts++)
                                {
                                    canConnection.SendRegisterReadRequest(weaponChannel, weaponNodeId, (byte)register);
                                    RegisterKey regKey = new RegisterKey(weaponNodeId, (byte)register);
                                    CanData registerData = null;
                                    Thread.Sleep(1000);
                                    if (canConnection.GetRegisterValue(regKey, out registerData) &&
                                        registerData.GetDataType() != CanData.DataType.DT_NODATA)
                                    {
                                        switch (register)
                                        {
                                            case (MP5_WeaponRegister.TresholdLow):
                                                TresholdLow = registerData.GetAsUchar();
                                                break;

                                            case (MP5_WeaponRegister.TresholdHigh):
                                                TresholdHigh = registerData.GetAsUchar();
                                                break;

                                            case (MP5_WeaponRegister.SensorMin):
                                                SensorMin = registerData.GetAsShort();
                                                break;

                                            case (MP5_WeaponRegister.SensorMax):
                                                SensorMax = registerData.GetAsShort();
                                                break;

                                            case (MP5_WeaponRegister.HallMax):
                                                HallMax = registerData.GetAsShort();
                                                break;

                                            case (MP5_WeaponRegister.HalfRange):
                                                HalfRange = registerData.GetAsShort();
                                                break;

                                            case (MP5_WeaponRegister.PeakFilter):
                                                PeakFilter = registerData.GetAsShort();
                                                break;
                                        }
                                        break;
                                    }
                                    // pockat pred dalsim pokusom
                                    Thread.Sleep(100);
                                }
                                RxCounter = RxCounter + 1;
                            }
                        }

                        if (weaponNodeId == 139) //ak103
                        {
                            foreach (AK103_WeaponRegister register in Enum.GetValues(typeof(AK103_WeaponRegister)))
                            {
                                for (int attempts = 0; attempts < 3; attempts++)
                                {
                                    canConnection.SendRegisterReadRequest(weaponChannel, weaponNodeId, (byte)register);
                                    RegisterKey regKey = new RegisterKey(weaponNodeId, (byte)register);
                                    CanData registerData = null;
                                    Thread.Sleep(1000);
                                    if (canConnection.GetRegisterValue(regKey, out registerData) &&
                                        registerData.GetDataType() != CanData.DataType.DT_NODATA)
                                    {
                                        switch (register)
                                        {
                                            case (AK103_WeaponRegister.TresholdLow):
                                                TresholdLow = registerData.GetAsUchar();
                                                break;

                                            case (AK103_WeaponRegister.TresholdHigh):
                                                TresholdHigh = registerData.GetAsUchar();
                                                break;

                                            case (AK103_WeaponRegister.VoltOffset):
                                                VoltOffset = registerData.GetAsShort();
                                                break;

                                            case (AK103_WeaponRegister.DAGain):
                                                DAGain = registerData.GetAsShort();
                                                break;

                                            case (AK103_WeaponRegister.RS100m):
                                                RS100m = registerData.GetAsShort();
                                                break;

                                            case (AK103_WeaponRegister.RS200m):
                                                RS200m = registerData.GetAsShort();
                                                break;
                                            case (AK103_WeaponRegister.RS300m):
                                                RS300m = registerData.GetAsShort();
                                                break;
                                            case (AK103_WeaponRegister.RS400m):
                                                RS400m = registerData.GetAsShort();
                                                break;
                                            case (AK103_WeaponRegister.RS500m):
                                                RS500m = registerData.GetAsShort();
                                                break;
                                            case (AK103_WeaponRegister.RS600m):
                                                RS600m = registerData.GetAsShort();
                                                break;
                                            case (AK103_WeaponRegister.RS700m):
                                                RS700m = registerData.GetAsShort();
                                                break;
                                            case (AK103_WeaponRegister.RS800m):
                                                RS800m = registerData.GetAsShort();
                                                break;

                                        }
                                        break;
                                    }
                                    // pockat pred dalsim pokusom
                                    Thread.Sleep(100);
                                }
                                RxCounter = RxCounter + 1;
                            }
                        }

                        if (weaponNodeId == 150) //gp34
                        {
                            foreach (GP34_WeaponRegister register in Enum.GetValues(typeof(GP34_WeaponRegister)))
                            {
                                for (int attempts = 0; attempts < 3; attempts++)
                                {
                                    canConnection.SendRegisterReadRequest(weaponChannel, weaponNodeId, (byte)register);
                                    RegisterKey regKey = new RegisterKey(weaponNodeId, (byte)register);
                                    CanData registerData = null;
                                    Thread.Sleep(1000);
                                    if (canConnection.GetRegisterValue(regKey, out registerData) &&
                                        registerData.GetDataType() != CanData.DataType.DT_NODATA)
                                    {
                                        switch (register)
                                        {
                                            case (GP34_WeaponRegister.Trigger1Low):
                                                Trigger1Low = registerData.GetAsUchar();
                                                break;

                                            case (GP34_WeaponRegister.Trigger1High):
                                                Trigger1High = registerData.GetAsUchar();
                                                break;

                                            case (GP34_WeaponRegister.Trigger2Low):
                                                Trigger2Low = registerData.GetAsUchar();
                                                break;

                                            case (GP34_WeaponRegister.Trigger2High):
                                                Trigger2High = registerData.GetAsUchar();
                                                break;

                                            case (GP34_WeaponRegister.RS0m):
                                                RS0m = registerData.GetAsShort();
                                                break;

                                            case (GP34_WeaponRegister.RS100m):
                                                RS100m = registerData.GetAsShort();
                                                break;
                                            case (GP34_WeaponRegister.RS150m):
                                                RS150m = registerData.GetAsShort();
                                                break;
                                            case (GP34_WeaponRegister.RS200m):
                                                RS200m = registerData.GetAsShort();
                                                break;
                                            case (GP34_WeaponRegister.RS250m):
                                                RS250m = registerData.GetAsShort();
                                                break;
                                            case (GP34_WeaponRegister.RS300m):
                                                RS300m = registerData.GetAsShort();
                                                break;
                                            case (GP34_WeaponRegister.RS350m):
                                                RS350m = registerData.GetAsShort();
                                                break;
                                            case (GP34_WeaponRegister.RS400m):
                                                RS400m = registerData.GetAsShort();
                                                break;
                                            case (GP34_WeaponRegister.RSx350m):
                                                RSx350m = registerData.GetAsShort();
                                                break;
                                            case (GP34_WeaponRegister.RSx300m):
                                                RSx300m = registerData.GetAsShort();
                                                break;
                                            case (GP34_WeaponRegister.RSx250m):
                                                RSx250m = registerData.GetAsShort();
                                                break;
                                            case (GP34_WeaponRegister.RSx200m):
                                                RSx200m = registerData.GetAsShort();
                                                break;
                                        }
                                        break;
                                    }
                                    // pockat pred dalsim pokusom
                                    Thread.Sleep(100);
                                }
                                RxCounter = RxCounter + 1;
                            }
                        }

                        if (weaponNodeId == 140) //brown
                        {
                            foreach (BROWN_WeaponRegister register in Enum.GetValues(typeof(BROWN_WeaponRegister)))
                            {
                                for (int attempts = 0; attempts < 3; attempts++)
                                {
                                    canConnection.SendRegisterReadRequest(weaponChannel, weaponNodeId, (byte)register);
                                    RegisterKey regKey = new RegisterKey(weaponNodeId, (byte)register);
                                    CanData registerData = null;
                                    Thread.Sleep(1000);
                                    if (canConnection.GetRegisterValue(regKey, out registerData) &&
                                        registerData.GetDataType() != CanData.DataType.DT_NODATA)
                                    {
                                        switch (register)
                                        {
                                            case (BROWN_WeaponRegister.BoltCatches):
                                                BoltCatches = registerData.GetAsUlong();
                                                break;

                                            case (BROWN_WeaponRegister.TresholdLow):
                                                TresholdLow = registerData.GetAsUchar();
                                                break;

                                            case (BROWN_WeaponRegister.TresholdHigh):
                                                TresholdHigh = registerData.GetAsUchar();
                                                break;

                                            case (BROWN_WeaponRegister.TriggerRelease):
                                                TriggerRelease = registerData.GetAsShort();
                                                break;

                                            case (BROWN_WeaponRegister.TriggerHold):
                                                TriggerHold = registerData.GetAsShort();
                                                break;

                                        }
                                        break;
                                    }
                                    // pockat pred dalsim pokusom
                                    Thread.Sleep(100);
                                }
                                RxCounter = RxCounter + 1;
                            }
                        }

                        if (weaponNodeId == 142) //coyote
                        {
                            foreach (COYOTE_WeaponRegister register in Enum.GetValues(typeof(COYOTE_WeaponRegister)))
                            {
                                for (int attempts = 0; attempts < 3; attempts++)
                                {
                                    canConnection.SendRegisterReadRequest(weaponChannel, weaponNodeId, (byte)register);
                                    RegisterKey regKey = new RegisterKey(weaponNodeId, (byte)register);
                                    CanData registerData = null;
                                    Thread.Sleep(1000);
                                    if (canConnection.GetRegisterValue(regKey, out registerData) &&
                                        registerData.GetDataType() != CanData.DataType.DT_NODATA)
                                    {
                                        switch (register)
                                        {
                                            case (COYOTE_WeaponRegister.TresholdLow):
                                                TresholdLow = registerData.GetAsUchar();
                                                break;

                                            case (COYOTE_WeaponRegister.TresholdHigh):
                                                TresholdHigh = registerData.GetAsUchar();
                                                break;

                                            case (COYOTE_WeaponRegister.TriggerRelease):
                                                TriggerRelease = registerData.GetAsShort();
                                                break;

                                            case (COYOTE_WeaponRegister.TriggerHold):
                                                TriggerHold = registerData.GetAsShort();
                                                break;

                                            case (COYOTE_WeaponRegister.BoltLockTreshold):
                                                BoltLockTreshold = registerData.GetAsShort();
                                                break;

                                            case (COYOTE_WeaponRegister.BoltUnlockTreshold):
                                                BoltUnlockTreshold = registerData.GetAsShort();
                                                break;

                                            case (COYOTE_WeaponRegister.FiringPinTreshold):
                                                FiringPinTreshold = registerData.GetAsShort();
                                                break;

                                            case (COYOTE_WeaponRegister.FiringPinDAOffset):
                                                FiringPinDAOffset = registerData.GetAsShort();
                                                break;
                                            case (COYOTE_WeaponRegister.SafeTreshold):
                                                SafeTreshold = registerData.GetAsShort();
                                                break;
                                            case (COYOTE_WeaponRegister.SafeDAOffset):
                                                SafeDAOffset = registerData.GetAsShort();
                                                break;
                                        }
                                        break;
                                    }
                                    // pockat pred dalsim pokusom
                                    Thread.Sleep(100);
                                }
                                RxCounter = RxCounter + 1;
                            }
                        }

                        if (weaponNodeId == 137) //g3
                        {
                            foreach (G3_WeaponRegister register in Enum.GetValues(typeof(G3_WeaponRegister)))
                            {
                                for (int attempts = 0; attempts < 3; attempts++)
                                {
                                    canConnection.SendRegisterReadRequest(weaponChannel, weaponNodeId, (byte)register);
                                    RegisterKey regKey = new RegisterKey(weaponNodeId, (byte)register);
                                    CanData registerData = null;
                                    Thread.Sleep(1000);
                                    if (canConnection.GetRegisterValue(regKey, out registerData) &&
                                        registerData.GetDataType() != CanData.DataType.DT_NODATA)
                                    {
                                        switch (register)
                                        {
                                            case (G3_WeaponRegister.TresholdLow):
                                                TresholdLow = registerData.GetAsUchar();
                                                break;

                                            case (G3_WeaponRegister.TresholdHigh):
                                                TresholdHigh = registerData.GetAsUchar();
                                                break;

                                            case (G3_WeaponRegister.Sensor1aLow):
                                                Sensor1aLow = registerData.GetAsShort();
                                                break;

                                            case (G3_WeaponRegister.Sensor1aHigh):
                                                SensorMax = registerData.GetAsShort();
                                                break;

                                            case (G3_WeaponRegister.Sensor1bLow):
                                                Sensor1aHigh = registerData.GetAsShort();
                                                break;

                                            case (G3_WeaponRegister.Sensor1bHigh):
                                                Sensor1bHigh = registerData.GetAsShort();
                                                break;
                                        }
                                        break;
                                    }
                                    // pockat pred dalsim pokusom
                                    Thread.Sleep(100);
                                }
                                RxCounter = RxCounter + 1;
                            }
                        }

                        if (weaponNodeId == 146) //g36
                        {
                            foreach (G36_WeaponRegister register in Enum.GetValues(typeof(G36_WeaponRegister)))
                            {
                                for (int attempts = 0; attempts < 3; attempts++)
                                {
                                    canConnection.SendRegisterReadRequest(weaponChannel, weaponNodeId, (byte)register);
                                    RegisterKey regKey = new RegisterKey(weaponNodeId, (byte)register);
                                    CanData registerData = null;
                                    Thread.Sleep(1000);
                                    if (canConnection.GetRegisterValue(regKey, out registerData) &&
                                        registerData.GetDataType() != CanData.DataType.DT_NODATA)
                                    {
                                        switch (register)
                                        {
                                            case (G36_WeaponRegister.TresholdLow):
                                                TresholdLow = registerData.GetAsUchar();
                                                break;

                                            case (G36_WeaponRegister.TresholdHigh):
                                                TresholdHigh = registerData.GetAsUchar();
                                                break;

                                            case (G36_WeaponRegister.Sensor1aLow):
                                                Sensor1aLow = registerData.GetAsShort();
                                                break;

                                            case (G36_WeaponRegister.Sensor1aHigh):
                                                SensorMax = registerData.GetAsShort();
                                                break;

                                            case (G36_WeaponRegister.Sensor1bLow):
                                                Sensor1aHigh = registerData.GetAsShort();
                                                break;

                                            case (G36_WeaponRegister.Sensor1bHigh):
                                                Sensor1bHigh = registerData.GetAsShort();
                                                break;
                                        }
                                        break;
                                    }
                                    // pockat pred dalsim pokusom
                                    Thread.Sleep(100);
                                }
                                RxCounter = RxCounter + 1;
                            }
                        }

                        if (weaponNodeId == 141) //lrt3
                        {
                            foreach (LRT3_WeaponRegister register in Enum.GetValues(typeof(LRT3_WeaponRegister)))
                            {
                                for (int attempts = 0; attempts < 3; attempts++)
                                {
                                    canConnection.SendRegisterReadRequest(weaponChannel, weaponNodeId, (byte)register);
                                    RegisterKey regKey = new RegisterKey(weaponNodeId, (byte)register);
                                    CanData registerData = null;
                                    Thread.Sleep(1000);
                                    if (canConnection.GetRegisterValue(regKey, out registerData) &&
                                        registerData.GetDataType() != CanData.DataType.DT_NODATA)
                                    {
                                        switch (register)
                                        {
                                            case (LRT3_WeaponRegister.TresholdLow):
                                                TresholdLow = registerData.GetAsUchar();
                                                break;

                                            case (LRT3_WeaponRegister.TresholdHigh):
                                                TresholdHigh = registerData.GetAsUchar();
                                                break;

                                            case (LRT3_WeaponRegister.TriggerRelease):
                                                TriggerRelease = registerData.GetAsShort();
                                                break;

                                            case (LRT3_WeaponRegister.TriggerHold):
                                                TriggerHold = registerData.GetAsShort();
                                                break;

                                            case (LRT3_WeaponRegister.BoltLockTreshold):
                                                BoltLockTreshold = registerData.GetAsShort();
                                                break;

                                            case (LRT3_WeaponRegister.BoltUnlockTreshold):
                                                BoltUnlockTreshold = registerData.GetAsShort();
                                                break;

                                            case (LRT3_WeaponRegister.FiringPinTreshold):
                                                FiringPinTreshold = registerData.GetAsShort();
                                                break;

                                            case (LRT3_WeaponRegister.FiringPinDAOffset):
                                                FiringPinDAOffset = registerData.GetAsShort();
                                                break;
                                            case (LRT3_WeaponRegister.SafeTreshold):
                                                SafeTreshold = registerData.GetAsShort();
                                                break;
                                            case (LRT3_WeaponRegister.SafeDAOffset):
                                                SafeDAOffset = registerData.GetAsShort();
                                                break;
                                        }
                                        break;
                                    }
                                    // pockat pred dalsim pokusom
                                    Thread.Sleep(100);
                                }
                                RxCounter = RxCounter + 1;
                            }
                        }

                        if (weaponNodeId == 138) //m60
                        {
                            foreach (M60_WeaponRegister register in Enum.GetValues(typeof(M60_WeaponRegister)))
                            {
                                for (int attempts = 0; attempts < 3; attempts++)
                                {
                                    canConnection.SendRegisterReadRequest(weaponChannel, weaponNodeId, (byte)register);
                                    RegisterKey regKey = new RegisterKey(weaponNodeId, (byte)register);
                                    CanData registerData = null;
                                    Thread.Sleep(1000);
                                    if (canConnection.GetRegisterValue(regKey, out registerData) &&
                                        registerData.GetDataType() != CanData.DataType.DT_NODATA)
                                    {
                                        switch (register)
                                        {
                                            case (M60_WeaponRegister.BeltReloads):
                                                BeltReloads = registerData.GetAsUlong();
                                                break;

                                            case (M60_WeaponRegister.TresholdLow):
                                                TresholdLow = registerData.GetAsUchar();
                                                break;

                                            case (M60_WeaponRegister.TresholdHigh):
                                                TresholdHigh = registerData.GetAsUchar();
                                                break;

                                            case (M60_WeaponRegister.HS3Release):
                                                HS3Release = registerData.GetAsShort();
                                                break;

                                            case (M60_WeaponRegister.HS3Hold):
                                                HS3Hold = registerData.GetAsShort();
                                                break;

                                            case (M60_WeaponRegister.TempDown):
                                                TempDown = registerData.GetAsShort();
                                                break;

                                            case (M60_WeaponRegister.TempUp):
                                                TempUp = registerData.GetAsShort();
                                                break;

                                            case (M60_WeaponRegister.MaxLedPWM):
                                                MaxLedPWM = registerData.GetAsShort();
                                                break;

                                            case (M60_WeaponRegister.DownStep1):
                                                DownStep1 = registerData.GetAsShort();
                                                break;

                                            case (M60_WeaponRegister.DownStep2):
                                                DownStep2 = registerData.GetAsShort();
                                                break;

                                            case (M60_WeaponRegister.DownStep3):
                                                DownStep3 = registerData.GetAsShort();
                                                break;

                                            case (M60_WeaponRegister.UpStep1):
                                                UpStep1 = registerData.GetAsShort();
                                                break;

                                            case (M60_WeaponRegister.UpStep2):
                                                UpStep2 = registerData.GetAsShort();
                                                break;

                                            case (M60_WeaponRegister.UpStep3):
                                                UpStep3 = registerData.GetAsShort();
                                                break;

                                        }
                                        break;
                                    }
                                    // pockat pred dalsim pokusom
                                    Thread.Sleep(100);
                                }
                                RxCounter = RxCounter + 1;
                            }
                        }

                        if (weaponNodeId == 136) //mg3
                        {
                            foreach (MG3_WeaponRegister register in Enum.GetValues(typeof(MG3_WeaponRegister)))
                            {
                                for (int attempts = 0; attempts < 3; attempts++)
                                {
                                    canConnection.SendRegisterReadRequest(weaponChannel, weaponNodeId, (byte)register);
                                    RegisterKey regKey = new RegisterKey(weaponNodeId, (byte)register);
                                    CanData registerData = null;
                                    Thread.Sleep(1000);
                                    if (canConnection.GetRegisterValue(regKey, out registerData) &&
                                        registerData.GetDataType() != CanData.DataType.DT_NODATA)
                                    {
                                        switch (register)
                                        {
                                            case (MG3_WeaponRegister.BeltReloads):
                                                BeltReloads = registerData.GetAsUlong();
                                                break;

                                            case (MG3_WeaponRegister.TresholdLow):
                                                TresholdLow = registerData.GetAsUchar();
                                                break;

                                            case (MG3_WeaponRegister.TresholdHigh):
                                                TresholdHigh = registerData.GetAsUchar();
                                                break;

                                            case (MG3_WeaponRegister.HS3Release):
                                                HS3Release = registerData.GetAsShort();
                                                break;

                                            case (MG3_WeaponRegister.HS3Hold):
                                                HS3Hold = registerData.GetAsShort();
                                                break;

                                            case (MG3_WeaponRegister.TempDown):
                                                TempDown = registerData.GetAsShort();
                                                break;

                                            case (MG3_WeaponRegister.TempUp):
                                                TempUp = registerData.GetAsShort();
                                                break;

                                            case (MG3_WeaponRegister.MaxLedPWM):
                                                MaxLedPWM = registerData.GetAsShort();
                                                break;

                                            case (MG3_WeaponRegister.DownStep1):
                                                DownStep1 = registerData.GetAsShort();
                                                break;

                                            case (MG3_WeaponRegister.DownStep2):
                                                DownStep2 = registerData.GetAsShort();
                                                break;

                                            case (MG3_WeaponRegister.DownStep3):
                                                DownStep3 = registerData.GetAsShort();
                                                break;

                                            case (MG3_WeaponRegister.UpStep1):
                                                UpStep1 = registerData.GetAsShort();
                                                break;

                                            case (MG3_WeaponRegister.UpStep2):
                                                UpStep2 = registerData.GetAsShort();
                                                break;

                                            case (MG3_WeaponRegister.UpStep3):
                                                UpStep3 = registerData.GetAsShort();
                                                break;

                                        }
                                        break;
                                    }
                                    // pockat pred dalsim pokusom
                                    Thread.Sleep(100);
                                }
                                RxCounter = RxCounter + 1;
                            }
                        }

                        if (weaponNodeId == 135) //rpg7
                        {
                            foreach (RPG7_WeaponRegister register in Enum.GetValues(typeof(RPG7_WeaponRegister)))
                            {
                                for (int attempts = 0; attempts < 3; attempts++)
                                {
                                    canConnection.SendRegisterReadRequest(weaponChannel, weaponNodeId, (byte)register);
                                    RegisterKey regKey = new RegisterKey(weaponNodeId, (byte)register);
                                    CanData registerData = null;
                                    Thread.Sleep(1000);
                                    if (canConnection.GetRegisterValue(regKey, out registerData) &&
                                        registerData.GetDataType() != CanData.DataType.DT_NODATA)
                                    {
                                        switch (register)
                                        {
                                            case (RPG7_WeaponRegister.TresholdLow):
                                                TresholdLow = registerData.GetAsUchar();
                                                break;

                                            case (RPG7_WeaponRegister.TresholdHigh):
                                                TresholdHigh = registerData.GetAsUchar();
                                                break;

                                            case (RPG7_WeaponRegister.VoltOffset):
                                                VoltOffset = registerData.GetAsShort();
                                                break;

                                            case (RPG7_WeaponRegister.DAGain):
                                                DAGain = registerData.GetAsShort();
                                                break;
                                        }
                                        break;
                                    }
                                    // pockat pred dalsim pokusom
                                    Thread.Sleep(100);
                                }
                                RxCounter = RxCounter + 1;
                            }
                        }

                        if (weaponNodeId == 143) //timber
                        {
                            foreach (TIMBER_WeaponRegister register in Enum.GetValues(typeof(TIMBER_WeaponRegister)))
                            {
                                for (int attempts = 0; attempts < 3; attempts++)
                                {
                                    canConnection.SendRegisterReadRequest(weaponChannel, weaponNodeId, (byte)register);
                                    RegisterKey regKey = new RegisterKey(weaponNodeId, (byte)register);
                                    CanData registerData = null;
                                    Thread.Sleep(1000);
                                    if (canConnection.GetRegisterValue(regKey, out registerData) &&
                                        registerData.GetDataType() != CanData.DataType.DT_NODATA)
                                    {
                                        switch (register)
                                        {
                                            case (TIMBER_WeaponRegister.TresholdLow):
                                                TresholdLow = registerData.GetAsUchar();
                                                break;

                                            case (TIMBER_WeaponRegister.TresholdHigh):
                                                TresholdHigh = registerData.GetAsUchar();
                                                break;

                                            case (TIMBER_WeaponRegister.TriggerRelease):
                                                TriggerRelease = registerData.GetAsShort();
                                                break;

                                            case (TIMBER_WeaponRegister.TriggerHold):
                                                TriggerHold = registerData.GetAsShort();
                                                break;

                                            case (TIMBER_WeaponRegister.BoltLockTreshold):
                                                BoltLockTreshold = registerData.GetAsShort();
                                                break;

                                            case (TIMBER_WeaponRegister.BoltUnlockTreshold):
                                                BoltUnlockTreshold = registerData.GetAsShort();
                                                break;

                                            case (TIMBER_WeaponRegister.FiringPinTreshold):
                                                FiringPinTreshold = registerData.GetAsShort();
                                                break;

                                            case (TIMBER_WeaponRegister.FiringPinDAOffset):
                                                FiringPinDAOffset = registerData.GetAsShort();
                                                break;
                                            case (TIMBER_WeaponRegister.SafeTreshold):
                                                SafeTreshold = registerData.GetAsShort();
                                                break;
                                            case (TIMBER_WeaponRegister.SafeDAOffset):
                                                SafeDAOffset = registerData.GetAsShort();
                                                break;
                                        }
                                        break;
                                    }
                                    // pockat pred dalsim pokusom
                                    Thread.Sleep(100);
                                }
                                RxCounter = RxCounter + 1;
                            }
                        }

                        if (weaponNodeId == 254) //rezerva a
                        {
                            foreach (RezervaA_WeaponRegister register in Enum.GetValues(typeof(RezervaA_WeaponRegister)))
                            {
                                for (int attempts = 0; attempts < 3; attempts++)
                                {
                                    canConnection.SendRegisterReadRequest(weaponChannel, weaponNodeId, (byte)register);
                                    RegisterKey regKey = new RegisterKey(weaponNodeId, (byte)register);
                                    CanData registerData = null;
                                    Thread.Sleep(1000);
                                    if (canConnection.GetRegisterValue(regKey, out registerData) &&
                                        registerData.GetDataType() != CanData.DataType.DT_NODATA)
                                    {
                                        switch (register)
                                        {
                                            case (RezervaA_WeaponRegister.BoltCatches):
                                                BoltCatches = registerData.GetAsUlong();
                                                break;

                                            case (RezervaA_WeaponRegister.TresholdLow):
                                                TresholdLow = registerData.GetAsUchar();
                                                break;

                                            case (RezervaA_WeaponRegister.TresholdHigh):
                                                TresholdHigh = registerData.GetAsUchar();
                                                break;

                                            case (RezervaA_WeaponRegister.TriggerRelease):
                                                TriggerRelease = registerData.GetAsShort();
                                                break;

                                            case (RezervaA_WeaponRegister.TriggerHold):
                                                TriggerHold = registerData.GetAsShort();
                                                break;

                                        }
                                        break;
                                    }
                                    // pockat pred dalsim pokusom
                                    Thread.Sleep(100);
                                }
                                RxCounter = RxCounter + 1;
                            }
                        }

                        if (weaponNodeId == 255) //rezerva b
                        {
                            foreach (RezervaB_WeaponRegister register in Enum.GetValues(typeof(RezervaB_WeaponRegister)))
                            {
                                for (int attempts = 0; attempts < 3; attempts++)
                                {
                                    canConnection.SendRegisterReadRequest(weaponChannel, weaponNodeId, (byte)register);
                                    RegisterKey regKey = new RegisterKey(weaponNodeId, (byte)register);
                                    CanData registerData = null;
                                    Thread.Sleep(1000);
                                    if (canConnection.GetRegisterValue(regKey, out registerData) &&
                                        registerData.GetDataType() != CanData.DataType.DT_NODATA)
                                    {
                                        switch (register)
                                        {
                                            case (RezervaB_WeaponRegister.BoltCatches):
                                                BoltCatches = registerData.GetAsUlong();
                                                break;

                                            case (RezervaB_WeaponRegister.TresholdLow):
                                                TresholdLow = registerData.GetAsUchar();
                                                break;

                                            case (RezervaB_WeaponRegister.TresholdHigh):
                                                TresholdHigh = registerData.GetAsUchar();
                                                break;

                                            case (RezervaB_WeaponRegister.TriggerRelease):
                                                TriggerRelease = registerData.GetAsShort();
                                                break;

                                            case (RezervaB_WeaponRegister.TriggerHold):
                                                TriggerHold = registerData.GetAsShort();
                                                break;

                                        }
                                        break;
                                    }
                                    // pockat pred dalsim pokusom
                                    Thread.Sleep(100);
                                }
                                RxCounter = RxCounter + 1;
                            }
                        }

                        //------vycitanie HW a SW version z prislusneho registru v zbrani
                        CanData idsData = new CanData();
                        byte[] byteIdsData = null;


                        canConnection.SendIdsRequest(weaponChannel, weaponNodeId);

                        Thread.Sleep(2000);

                        if (canConnection.GetIdsValue(weaponNodeId, out idsData)
                            && idsData.GetDataType() != CanData.DataType.DT_NODATA)
                        {
                            byteIdsData = idsData.GetRawData();
                        }
                        if (byteIdsData != null) 
                        {
                            HwVersion = byteIdsData[0].ToString() + "." + byteIdsData[1].ToString();
                            SwVersion = byteIdsData[2].ToString() + "." + byteIdsData[3].ToString();

                            RxCounter = RxCounter + 1;
                        }

                        //------priradenie hodnot
                        if (Application.OpenForms.OfType<Form1>().Any())
                        {
                            Form1 mainform = Application.OpenForms.OfType<Form1>().First();
                        }
                        //zatriedenie zbrane
                        switch (weaponNodeId)
                        {
                            case (132):
                                label1.Text = " MP5 weapon found";
                                MP5.MP5Form MP5Form2 = new MP5.MP5Form();
                                MP5Form2.Show();
                                //vypnutie eventu pri zmene numericupdown
                                MP5Form2.MP5_treshlow.ValueChanged -= MP5Form2.MP5_numericUpDown_ValueChanged;
                                MP5Form2.MP5_treshhigh.ValueChanged -= MP5Form2.MP5_numericUpDown_ValueChanged;
                                MP5Form2.MP5_sensormin.ValueChanged -= MP5Form2.MP5_numericUpDown_ValueChanged;
                                MP5Form2.MP5_sensormax.ValueChanged -= MP5Form2.MP5_numericUpDown_ValueChanged;
                                MP5Form2.MP5_hallmax.ValueChanged -= MP5Form2.MP5_numericUpDown_ValueChanged;
                                MP5Form2.MP5_halfrange.ValueChanged -= MP5Form2.MP5_numericUpDown_ValueChanged;
                                MP5Form2.MP5_peakfilter.ValueChanged -= MP5Form2.MP5_numericUpDown_ValueChanged;
                                //
                                ActiveForm2 = MP5Form2;
                                HwName = "MP5";
                                MP5Form2.MP5_device.Text = HwName;
                                MP5Form2.MP5_serial.Text = SerialNumber;
                                MP5Form2.MP5_year.Text = "" + ProductionYear;
                                MP5Form2.MP5_address.Text = "" + BaseAddress;
                                MP5Form2.MP5_hw.Text = HwVersion;
                                MP5Form2.MP5_sw.Text = SwVersion;
                                MP5Form2.MP5_shots.Text = "" + TotalShots;
                                MP5Form2.MP5_powerons.Text = "" + Powerons;
                                MP5Form2.MP5_treshlow.Text = "" + TresholdLow;
                                MP5Form2.MP5_treshhigh.Text = "" + TresholdHigh;
                                MP5Form2.MP5_sensormin.Text = "" + SensorMin;
                                MP5Form2.MP5_sensormax.Text = "" + SensorMax;
                                MP5Form2.MP5_hallmax.Text = "" + HallMax;
                                MP5Form2.MP5_halfrange.Text = "" + HalfRange;
                                MP5Form2.MP5_peakfilter.Text = "" + PeakFilter;
                                //zapnutie eventu pri zmene numericupdown
                                MP5Form2.MP5_treshlow.ValueChanged += MP5Form2.MP5_numericUpDown_ValueChanged;
                                MP5Form2.MP5_treshhigh.ValueChanged += MP5Form2.MP5_numericUpDown_ValueChanged;
                                MP5Form2.MP5_sensormin.ValueChanged += MP5Form2.MP5_numericUpDown_ValueChanged;
                                MP5Form2.MP5_sensormax.ValueChanged += MP5Form2.MP5_numericUpDown_ValueChanged;
                                MP5Form2.MP5_hallmax.ValueChanged += MP5Form2.MP5_numericUpDown_ValueChanged;
                                MP5Form2.MP5_halfrange.ValueChanged += MP5Form2.MP5_numericUpDown_ValueChanged;
                                MP5Form2.MP5_peakfilter.ValueChanged += MP5Form2.MP5_numericUpDown_ValueChanged;
                                //
                                break;
                            case (137):
                                label1.Text = " G3 weapon found";
                                G3.G3Form G3Form2 = new G3.G3Form();
                                G3Form2.Show();
                                //vypnutie eventu pri zmene numericupdown
                                G3Form2.G3_treshlow.ValueChanged -= G3Form2.G3_numericUpDown_ValueChanged;
                                G3Form2.G3_treshhigh.ValueChanged -= G3Form2.G3_numericUpDown_ValueChanged;
                                G3Form2.G3_sensor1alow.ValueChanged -= G3Form2.G3_numericUpDown_ValueChanged;
                                G3Form2.G3_sensor1ahigh.ValueChanged -= G3Form2.G3_numericUpDown_ValueChanged;
                                G3Form2.G3_sensor1blow.ValueChanged -= G3Form2.G3_numericUpDown_ValueChanged;
                                G3Form2.G3_sensor1bhigh.ValueChanged -= G3Form2.G3_numericUpDown_ValueChanged;
                                //
                                ActiveForm2 = G3Form2;
                                HwName = "G3";
                                G3Form2.G3_device.Text = HwName;
                                G3Form2.G3_serial.Text = SerialNumber;
                                G3Form2.G3_year.Text = "" + ProductionYear;
                                G3Form2.G3_address.Text = "" + BaseAddress;
                                G3Form2.G3_hw.Text = HwVersion;
                                G3Form2.G3_sw.Text = SwVersion;
                                G3Form2.G3_shots.Text = "" + TotalShots;
                                G3Form2.G3_powerons.Text = "" + Powerons;
                                G3Form2.G3_treshlow.Text = "" + TresholdLow;
                                G3Form2.G3_treshhigh.Text = "" + TresholdHigh;
                                G3Form2.G3_sensor1alow.Text = "" + Sensor1aLow;
                                G3Form2.G3_sensor1ahigh.Text = "" + Sensor1aHigh;
                                G3Form2.G3_sensor1blow.Text = "" + Sensor1bLow;
                                G3Form2.G3_sensor1bhigh.Text = "" + Sensor1bHigh;
                                //zapnutie eventu pri zmene numericupdown
                                G3Form2.G3_treshlow.ValueChanged += G3Form2.G3_numericUpDown_ValueChanged;
                                G3Form2.G3_treshhigh.ValueChanged += G3Form2.G3_numericUpDown_ValueChanged;
                                G3Form2.G3_sensor1alow.ValueChanged += G3Form2.G3_numericUpDown_ValueChanged;
                                G3Form2.G3_sensor1ahigh.ValueChanged += G3Form2.G3_numericUpDown_ValueChanged;
                                G3Form2.G3_sensor1blow.ValueChanged += G3Form2.G3_numericUpDown_ValueChanged;
                                G3Form2.G3_sensor1bhigh.ValueChanged += G3Form2.G3_numericUpDown_ValueChanged;
                                //
                                break;
                            case (146):
                                label1.Text = " G36 weapon found";
                                G36.G36Form G36Form2 = new G36.G36Form();
                                G36Form2.Show();
                                //vypnutie eventu pri zmene numericupdown
                                G36Form2.G36_treshlow.ValueChanged -= G36Form2.G36_numericUpDown_ValueChanged;
                                G36Form2.G36_treshhigh.ValueChanged -= G36Form2.G36_numericUpDown_ValueChanged;
                                G36Form2.G36_sensor1alow.ValueChanged -= G36Form2.G36_numericUpDown_ValueChanged;
                                G36Form2.G36_sensor1ahigh.ValueChanged -= G36Form2.G36_numericUpDown_ValueChanged;
                                G36Form2.G36_sensor1blow.ValueChanged -= G36Form2.G36_numericUpDown_ValueChanged;
                                G36Form2.G36_sensor1bhigh.ValueChanged -= G36Form2.G36_numericUpDown_ValueChanged;
                                //
                                ActiveForm2 = G36Form2;
                                HwName = "G36";
                                G36Form2.G36_device.Text = HwName;
                                G36Form2.G36_serial.Text = SerialNumber;
                                G36Form2.G36_year.Text = "" + ProductionYear;
                                G36Form2.G36_address.Text = "" + BaseAddress;
                                G36Form2.G36_hw.Text = HwVersion;
                                G36Form2.G36_sw.Text = SwVersion;
                                G36Form2.G36_shots.Text = "" + TotalShots;
                                G36Form2.G36_powerons.Text = "" + Powerons;
                                G36Form2.G36_treshlow.Text = "" + TresholdLow;
                                G36Form2.G36_treshhigh.Text = "" + TresholdHigh;
                                G36Form2.G36_sensor1alow.Text = "" + Sensor1aLow;
                                G36Form2.G36_sensor1ahigh.Text = "" + Sensor1aHigh;
                                G36Form2.G36_sensor1blow.Text = "" + Sensor1bLow;
                                G36Form2.G36_sensor1bhigh.Text = "" + Sensor1bHigh;
                                //zapnutie eventu pri zmene numericupdown
                                G36Form2.G36_treshlow.ValueChanged += G36Form2.G36_numericUpDown_ValueChanged;
                                G36Form2.G36_treshhigh.ValueChanged += G36Form2.G36_numericUpDown_ValueChanged;
                                G36Form2.G36_sensor1alow.ValueChanged += G36Form2.G36_numericUpDown_ValueChanged;
                                G36Form2.G36_sensor1ahigh.ValueChanged += G36Form2.G36_numericUpDown_ValueChanged;
                                G36Form2.G36_sensor1blow.ValueChanged += G36Form2.G36_numericUpDown_ValueChanged;
                                G36Form2.G36_sensor1bhigh.ValueChanged += G36Form2.G36_numericUpDown_ValueChanged;
                                //
                                break;
                            case (139):
                                label1.Text = " AK103 weapon found";
                                AK103.AK103Form AK103Form2 = new AK103.AK103Form();
                                AK103Form2.Show();
                                //vypnutie eventu pri zmene numericupdown
                                AK103Form2.AK103_treshlow.ValueChanged -= AK103Form2.AK103_numericUpDown_ValueChanged;
                                AK103Form2.AK103_treshhigh.ValueChanged -= AK103Form2.AK103_numericUpDown_ValueChanged;
                                AK103Form2.AK103_voltoffset.ValueChanged -= AK103Form2.AK103_numericUpDown_ValueChanged;
                                AK103Form2.AK103_dagain.ValueChanged -= AK103Form2.AK103_numericUpDown_ValueChanged;
                                AK103Form2.AK103_rs100m.ValueChanged -= AK103Form2.AK103_numericUpDown_ValueChanged;
                                AK103Form2.AK103_rs200m.ValueChanged -= AK103Form2.AK103_numericUpDown_ValueChanged;
                                AK103Form2.AK103_rs300m.ValueChanged -= AK103Form2.AK103_numericUpDown_ValueChanged;
                                AK103Form2.AK103_rs400m.ValueChanged -= AK103Form2.AK103_numericUpDown_ValueChanged;
                                AK103Form2.AK103_rs500m.ValueChanged -= AK103Form2.AK103_numericUpDown_ValueChanged;
                                AK103Form2.AK103_rs600m.ValueChanged -= AK103Form2.AK103_numericUpDown_ValueChanged;
                                AK103Form2.AK103_rs700m.ValueChanged -= AK103Form2.AK103_numericUpDown_ValueChanged;
                                AK103Form2.AK103_rs800m.ValueChanged -= AK103Form2.AK103_numericUpDown_ValueChanged;
                                //
                                ActiveForm2 = AK103Form2;
                                HwName = "AK103";
                                AK103Form2.AK103_device.Text = HwName;
                                AK103Form2.AK103_serial.Text = SerialNumber;
                                AK103Form2.AK103_year.Text = "" + ProductionYear;
                                AK103Form2.AK103_address.Text = "" + BaseAddress;
                                AK103Form2.AK103_hw.Text = HwVersion;
                                AK103Form2.AK103_sw.Text = SwVersion;
                                AK103Form2.AK103_shots.Text = "" + TotalShots;
                                AK103Form2.AK103_powerons.Text = "" + Powerons;
                                AK103Form2.AK103_treshlow.Text = "" + TresholdLow;
                                AK103Form2.AK103_treshhigh.Text = "" + TresholdHigh;
                                AK103Form2.AK103_voltoffset.Text = "" + VoltOffset;
                                AK103Form2.AK103_dagain.Text = "" + DAGain;
                                AK103Form2.AK103_rs100m.Text = "" + RS100m;
                                AK103Form2.AK103_rs100m.Text = "" + RS200m;
                                AK103Form2.AK103_rs100m.Text = "" + RS300m;
                                AK103Form2.AK103_rs100m.Text = "" + RS400m;
                                AK103Form2.AK103_rs100m.Text = "" + RS500m;
                                AK103Form2.AK103_rs100m.Text = "" + RS600m;
                                AK103Form2.AK103_rs100m.Text = "" + RS700m;
                                AK103Form2.AK103_rs100m.Text = "" + RS800m;
                                //zapnutie eventu pri zmene numericupdown
                                AK103Form2.AK103_treshlow.ValueChanged += AK103Form2.AK103_numericUpDown_ValueChanged;
                                AK103Form2.AK103_treshhigh.ValueChanged += AK103Form2.AK103_numericUpDown_ValueChanged;
                                AK103Form2.AK103_voltoffset.ValueChanged += AK103Form2.AK103_numericUpDown_ValueChanged;
                                AK103Form2.AK103_dagain.ValueChanged += AK103Form2.AK103_numericUpDown_ValueChanged;
                                AK103Form2.AK103_rs100m.ValueChanged += AK103Form2.AK103_numericUpDown_ValueChanged;
                                AK103Form2.AK103_rs200m.ValueChanged += AK103Form2.AK103_numericUpDown_ValueChanged;
                                AK103Form2.AK103_rs300m.ValueChanged += AK103Form2.AK103_numericUpDown_ValueChanged;
                                AK103Form2.AK103_rs400m.ValueChanged += AK103Form2.AK103_numericUpDown_ValueChanged;
                                AK103Form2.AK103_rs500m.ValueChanged += AK103Form2.AK103_numericUpDown_ValueChanged;
                                AK103Form2.AK103_rs600m.ValueChanged += AK103Form2.AK103_numericUpDown_ValueChanged;
                                AK103Form2.AK103_rs700m.ValueChanged += AK103Form2.AK103_numericUpDown_ValueChanged;
                                AK103Form2.AK103_rs800m.ValueChanged += AK103Form2.AK103_numericUpDown_ValueChanged;
                                //
                                break;
                            case (136):
                                label1.Text = " MG3 weapon found";
                                MG3.MG3Form MG3Form2 = new MG3.MG3Form();
                                MG3Form2.Show();
                                //vypnutie eventu pri zmene numericupdown
                                MG3Form2.MG3_treshlow.ValueChanged -= MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_treshhigh.ValueChanged -= MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_hs3release.ValueChanged -= MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_hs3hold.ValueChanged -= MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_tempdown.ValueChanged -= MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_tempup.ValueChanged -= MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_maxledpwm.ValueChanged -= MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_downstep1.ValueChanged -= MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_downstep2.ValueChanged -= MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_downstep3.ValueChanged -= MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_upstep1.ValueChanged -= MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_upstep2.ValueChanged -= MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_upstep3.ValueChanged -= MG3Form2.MG3_numericUpDown_ValueChanged;
                                //
                                ActiveForm2 = MG3Form2;
                                HwName = "MG3";
                                MG3Form2.MG3_device.Text = HwName;
                                MG3Form2.MG3_serial.Text = SerialNumber;
                                MG3Form2.MG3_year.Text = "" + ProductionYear;
                                MG3Form2.MG3_address.Text = "" + BaseAddress;
                                MG3Form2.MG3_hw.Text = HwVersion;
                                MG3Form2.MG3_sw.Text = SwVersion;
                                MG3Form2.MG3_shots.Text = "" + TotalShots;
                                MG3Form2.MG3_powerons.Text = "" + Powerons;
                                MG3Form2.MG3_reloads.Text = "" + BeltReloads;
                                MG3Form2.MG3_treshlow.Text = "" + TresholdLow;
                                MG3Form2.MG3_treshhigh.Text = "" + TresholdHigh;
                                MG3Form2.MG3_hs3release.Text = "" + HS3Release;
                                MG3Form2.MG3_hs3hold.Text = "" + HS3Hold;
                                MG3Form2.MG3_tempdown.Text = "" + TempDown;
                                MG3Form2.MG3_tempup.Text = "" + TempUp;
                                MG3Form2.MG3_maxledpwm.Text = "" + MaxLedPWM;
                                MG3Form2.MG3_downstep1.Text = "" + DownStep1;
                                MG3Form2.MG3_downstep2.Text = "" + DownStep2;
                                MG3Form2.MG3_downstep3.Text = "" + DownStep3;
                                MG3Form2.MG3_upstep1.Text = "" + UpStep1;
                                MG3Form2.MG3_upstep2.Text = "" + UpStep2;
                                MG3Form2.MG3_upstep3.Text = "" + UpStep3;
                                //zapnutie eventu pri zmene numericupdown
                                MG3Form2.MG3_treshlow.ValueChanged += MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_treshhigh.ValueChanged += MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_hs3release.ValueChanged += MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_hs3hold.ValueChanged += MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_tempdown.ValueChanged += MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_tempup.ValueChanged += MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_maxledpwm.ValueChanged += MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_downstep1.ValueChanged += MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_downstep2.ValueChanged += MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_downstep3.ValueChanged += MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_upstep1.ValueChanged += MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_upstep2.ValueChanged += MG3Form2.MG3_numericUpDown_ValueChanged;
                                MG3Form2.MG3_upstep3.ValueChanged += MG3Form2.MG3_numericUpDown_ValueChanged;
                                //
                                break;
                            case (141):
                                label1.Text = " LRT3 weapon found";
                                LRT3.LRT3Form LRT3Form2 = new LRT3.LRT3Form();
                                LRT3Form2.Show();
                                //vypnutie eventu pri zmene numericupdown
                                LRT3Form2.LRT3_treshlow.ValueChanged -= LRT3Form2.LRT3_numericUpDown_ValueChanged;
                                LRT3Form2.LRT3_treshhigh.ValueChanged -= LRT3Form2.LRT3_numericUpDown_ValueChanged;
                                LRT3Form2.LRT3_triggerrelease.ValueChanged -= LRT3Form2.LRT3_numericUpDown_ValueChanged;
                                LRT3Form2.LRT3_triggerhold.ValueChanged -= LRT3Form2.LRT3_numericUpDown_ValueChanged;
                                LRT3Form2.LRT3_boltlocktresh.ValueChanged -= LRT3Form2.LRT3_numericUpDown_ValueChanged;
                                LRT3Form2.LRT3_boltunlocktresh.ValueChanged -= LRT3Form2.LRT3_numericUpDown_ValueChanged;
                                LRT3Form2.LRT3_firingpintresh.ValueChanged -= LRT3Form2.LRT3_numericUpDown_ValueChanged;
                                LRT3Form2.LRT3_firingpindaoffset.ValueChanged -= LRT3Form2.LRT3_numericUpDown_ValueChanged;
                                LRT3Form2.LRT3_safetresh.ValueChanged -= LRT3Form2.LRT3_numericUpDown_ValueChanged;
                                LRT3Form2.LRT3_safedaoffset.ValueChanged -= LRT3Form2.LRT3_numericUpDown_ValueChanged;
                                //
                                ActiveForm2 = LRT3Form2;
                                HwName = "LRT3";
                                LRT3Form2.LRT3_device.Text = HwName;
                                LRT3Form2.LRT3_serial.Text = SerialNumber;
                                LRT3Form2.LRT3_year.Text = "" + ProductionYear;
                                LRT3Form2.LRT3_address.Text = "" + BaseAddress;
                                LRT3Form2.LRT3_hw.Text = HwVersion;
                                LRT3Form2.LRT3_sw.Text = SwVersion;
                                LRT3Form2.LRT3_shots.Text = "" + TotalShots;
                                LRT3Form2.LRT3_powerons.Text = "" + Powerons;
                                LRT3Form2.LRT3_treshlow.Text = "" + TresholdLow;
                                LRT3Form2.LRT3_treshhigh.Text = "" + TresholdHigh;
                                LRT3Form2.LRT3_triggerrelease.Text = "" + TriggerRelease;
                                LRT3Form2.LRT3_triggerhold.Text = "" + TriggerHold;
                                LRT3Form2.LRT3_boltlocktresh.Text = "" + BoltLockTreshold;
                                LRT3Form2.LRT3_boltunlocktresh.Text = "" + BoltUnlockTreshold;
                                LRT3Form2.LRT3_firingpintresh.Text = "" + FiringPinTreshold;
                                LRT3Form2.LRT3_firingpindaoffset.Text = "" + FiringPinDAOffset;
                                LRT3Form2.LRT3_safetresh.Text = "" + SafeTreshold;
                                LRT3Form2.LRT3_safedaoffset.Text = "" + SafeDAOffset;
                                //zapnutie eventu pri zmene numericupdown
                                LRT3Form2.LRT3_treshlow.ValueChanged += LRT3Form2.LRT3_numericUpDown_ValueChanged;
                                LRT3Form2.LRT3_treshhigh.ValueChanged += LRT3Form2.LRT3_numericUpDown_ValueChanged;
                                LRT3Form2.LRT3_triggerrelease.ValueChanged += LRT3Form2.LRT3_numericUpDown_ValueChanged;
                                LRT3Form2.LRT3_triggerhold.ValueChanged += LRT3Form2.LRT3_numericUpDown_ValueChanged;
                                LRT3Form2.LRT3_boltlocktresh.ValueChanged += LRT3Form2.LRT3_numericUpDown_ValueChanged;
                                LRT3Form2.LRT3_boltunlocktresh.ValueChanged += LRT3Form2.LRT3_numericUpDown_ValueChanged;
                                LRT3Form2.LRT3_firingpintresh.ValueChanged += LRT3Form2.LRT3_numericUpDown_ValueChanged;
                                LRT3Form2.LRT3_firingpindaoffset.ValueChanged += LRT3Form2.LRT3_numericUpDown_ValueChanged;
                                LRT3Form2.LRT3_safetresh.ValueChanged += LRT3Form2.LRT3_numericUpDown_ValueChanged;
                                LRT3Form2.LRT3_safedaoffset.ValueChanged += LRT3Form2.LRT3_numericUpDown_ValueChanged;
                                //
                                break;
                            case (142):
                                label1.Text = " COYOTE weapon found";
                                COYOTE.COYOTEForm COYOTEForm2 = new COYOTE.COYOTEForm();
                                COYOTEForm2.Show();
                                //vypnutie eventu pri zmene numericupdown
                                COYOTEForm2.COYOTE_treshlow.ValueChanged -= COYOTEForm2.COYOTE_numericUpDown_ValueChanged;
                                COYOTEForm2.COYOTE_treshhigh.ValueChanged -= COYOTEForm2.COYOTE_numericUpDown_ValueChanged;
                                COYOTEForm2.COYOTE_triggerrelease.ValueChanged -= COYOTEForm2.COYOTE_numericUpDown_ValueChanged;
                                COYOTEForm2.COYOTE_triggerhold.ValueChanged -= COYOTEForm2.COYOTE_numericUpDown_ValueChanged;
                                COYOTEForm2.COYOTE_boltlocktresh.ValueChanged -= COYOTEForm2.COYOTE_numericUpDown_ValueChanged;
                                COYOTEForm2.COYOTE_boltunlocktresh.ValueChanged -= COYOTEForm2.COYOTE_numericUpDown_ValueChanged;
                                COYOTEForm2.COYOTE_firingpintresh.ValueChanged -= COYOTEForm2.COYOTE_numericUpDown_ValueChanged;
                                COYOTEForm2.COYOTE_firingpindaoffset.ValueChanged -= COYOTEForm2.COYOTE_numericUpDown_ValueChanged;
                                COYOTEForm2.COYOTE_safetresh.ValueChanged -= COYOTEForm2.COYOTE_numericUpDown_ValueChanged;
                                COYOTEForm2.COYOTE_safedaoffset.ValueChanged -= COYOTEForm2.COYOTE_numericUpDown_ValueChanged;
                                //
                                ActiveForm2 = COYOTEForm2;
                                HwName = "COYOTE";
                                COYOTEForm2.COYOTE_device.Text = HwName;
                                COYOTEForm2.COYOTE_serial.Text = SerialNumber;
                                COYOTEForm2.COYOTE_year.Text = "" + ProductionYear;
                                COYOTEForm2.COYOTE_address.Text = "" + BaseAddress;
                                COYOTEForm2.COYOTE_hw.Text = HwVersion;
                                COYOTEForm2.COYOTE_sw.Text = SwVersion;
                                COYOTEForm2.COYOTE_shots.Text = "" + TotalShots;
                                COYOTEForm2.COYOTE_powerons.Text = "" + Powerons;
                                COYOTEForm2.COYOTE_treshlow.Text = "" + TresholdLow;
                                COYOTEForm2.COYOTE_treshhigh.Text = "" + TresholdHigh;
                                COYOTEForm2.COYOTE_triggerrelease.Text = "" + TriggerRelease;
                                COYOTEForm2.COYOTE_triggerhold.Text = "" + TriggerHold;
                                COYOTEForm2.COYOTE_boltlocktresh.Text = "" + BoltLockTreshold;
                                COYOTEForm2.COYOTE_boltunlocktresh.Text = "" + BoltUnlockTreshold;
                                COYOTEForm2.COYOTE_firingpintresh.Text = "" + FiringPinTreshold;
                                COYOTEForm2.COYOTE_firingpindaoffset.Text = "" + FiringPinDAOffset;
                                COYOTEForm2.COYOTE_safetresh.Text = "" + SafeTreshold;
                                COYOTEForm2.COYOTE_safedaoffset.Text = "" + SafeDAOffset;
                                //zapnutie eventu pri zmene numericupdown
                                COYOTEForm2.COYOTE_treshlow.ValueChanged += COYOTEForm2.COYOTE_numericUpDown_ValueChanged;
                                COYOTEForm2.COYOTE_treshhigh.ValueChanged += COYOTEForm2.COYOTE_numericUpDown_ValueChanged;
                                COYOTEForm2.COYOTE_triggerrelease.ValueChanged += COYOTEForm2.COYOTE_numericUpDown_ValueChanged;
                                COYOTEForm2.COYOTE_triggerhold.ValueChanged += COYOTEForm2.COYOTE_numericUpDown_ValueChanged;
                                COYOTEForm2.COYOTE_boltlocktresh.ValueChanged += COYOTEForm2.COYOTE_numericUpDown_ValueChanged;
                                COYOTEForm2.COYOTE_boltunlocktresh.ValueChanged += COYOTEForm2.COYOTE_numericUpDown_ValueChanged;
                                COYOTEForm2.COYOTE_firingpintresh.ValueChanged += COYOTEForm2.COYOTE_numericUpDown_ValueChanged;
                                COYOTEForm2.COYOTE_firingpindaoffset.ValueChanged += COYOTEForm2.COYOTE_numericUpDown_ValueChanged;
                                COYOTEForm2.COYOTE_safetresh.ValueChanged += COYOTEForm2.COYOTE_numericUpDown_ValueChanged;
                                COYOTEForm2.COYOTE_safedaoffset.ValueChanged += COYOTEForm2.COYOTE_numericUpDown_ValueChanged;
                                //
                                break;
                            case (143):
                                label1.Text = " TIMBERWOLF weapon found";
                                TIMBER.TIMBERForm TIMBERForm2 = new TIMBER.TIMBERForm();
                                TIMBERForm2.Show();
                                //vypnutie eventu pri zmene numericupdown
                                TIMBERForm2.TIMBER_treshlow.ValueChanged -= TIMBERForm2.TIMBER_numericUpDown_ValueChanged;
                                TIMBERForm2.TIMBER_treshhigh.ValueChanged -= TIMBERForm2.TIMBER_numericUpDown_ValueChanged;
                                TIMBERForm2.TIMBER_triggerrelease.ValueChanged -= TIMBERForm2.TIMBER_numericUpDown_ValueChanged;
                                TIMBERForm2.TIMBER_triggerhold.ValueChanged -= TIMBERForm2.TIMBER_numericUpDown_ValueChanged;
                                TIMBERForm2.TIMBER_boltlocktresh.ValueChanged -= TIMBERForm2.TIMBER_numericUpDown_ValueChanged;
                                TIMBERForm2.TIMBER_boltunlocktresh.ValueChanged -= TIMBERForm2.TIMBER_numericUpDown_ValueChanged;
                                TIMBERForm2.TIMBER_firingpintresh.ValueChanged -= TIMBERForm2.TIMBER_numericUpDown_ValueChanged;
                                TIMBERForm2.TIMBER_firingpindaoffset.ValueChanged -= TIMBERForm2.TIMBER_numericUpDown_ValueChanged;
                                TIMBERForm2.TIMBER_safetresh.ValueChanged -= TIMBERForm2.TIMBER_numericUpDown_ValueChanged;
                                TIMBERForm2.TIMBER_safedaoffset.ValueChanged -= TIMBERForm2.TIMBER_numericUpDown_ValueChanged;
                                //
                                ActiveForm2 = TIMBERForm2;
                                HwName = "TIMBERWOLF";
                                TIMBERForm2.TIMBER_device.Text = HwName;
                                TIMBERForm2.TIMBER_serial.Text = SerialNumber;
                                TIMBERForm2.TIMBER_year.Text = "" + ProductionYear;
                                TIMBERForm2.TIMBER_address.Text = "" + BaseAddress;
                                TIMBERForm2.TIMBER_hw.Text = HwVersion;
                                TIMBERForm2.TIMBER_sw.Text = SwVersion;
                                TIMBERForm2.TIMBER_shots.Text = "" + TotalShots;
                                TIMBERForm2.TIMBER_powerons.Text = "" + Powerons;
                                TIMBERForm2.TIMBER_treshlow.Text = "" + TresholdLow;
                                TIMBERForm2.TIMBER_treshhigh.Text = "" + TresholdHigh;
                                TIMBERForm2.TIMBER_triggerrelease.Text = "" + TriggerRelease;
                                TIMBERForm2.TIMBER_triggerhold.Text = "" + TriggerHold;
                                TIMBERForm2.TIMBER_boltlocktresh.Text = "" + BoltLockTreshold;
                                TIMBERForm2.TIMBER_boltunlocktresh.Text = "" + BoltUnlockTreshold;
                                TIMBERForm2.TIMBER_firingpintresh.Text = "" + FiringPinTreshold;
                                TIMBERForm2.TIMBER_firingpindaoffset.Text = "" + FiringPinDAOffset;
                                TIMBERForm2.TIMBER_safetresh.Text = "" + SafeTreshold;
                                TIMBERForm2.TIMBER_safedaoffset.Text = "" + SafeDAOffset;
                                //zapnutie eventu pri zmene numericupdown
                                TIMBERForm2.TIMBER_treshlow.ValueChanged += TIMBERForm2.TIMBER_numericUpDown_ValueChanged;
                                TIMBERForm2.TIMBER_treshhigh.ValueChanged += TIMBERForm2.TIMBER_numericUpDown_ValueChanged;
                                TIMBERForm2.TIMBER_triggerrelease.ValueChanged += TIMBERForm2.TIMBER_numericUpDown_ValueChanged;
                                TIMBERForm2.TIMBER_triggerhold.ValueChanged += TIMBERForm2.TIMBER_numericUpDown_ValueChanged;
                                TIMBERForm2.TIMBER_boltlocktresh.ValueChanged += TIMBERForm2.TIMBER_numericUpDown_ValueChanged;
                                TIMBERForm2.TIMBER_boltunlocktresh.ValueChanged += TIMBERForm2.TIMBER_numericUpDown_ValueChanged;
                                TIMBERForm2.TIMBER_firingpintresh.ValueChanged += TIMBERForm2.TIMBER_numericUpDown_ValueChanged;
                                TIMBERForm2.TIMBER_firingpindaoffset.ValueChanged += TIMBERForm2.TIMBER_numericUpDown_ValueChanged;
                                TIMBERForm2.TIMBER_safetresh.ValueChanged += TIMBERForm2.TIMBER_numericUpDown_ValueChanged;
                                TIMBERForm2.TIMBER_safedaoffset.ValueChanged += TIMBERForm2.TIMBER_numericUpDown_ValueChanged;
                                //
                                break;
                            case (135):
                                label1.Text = " RPG7 weapon found";
                                RPG7.RPG7Form RPG7Form2 = new RPG7.RPG7Form();
                                RPG7Form2.Show();
                                //vypnutie eventu pri zmene numericupdown
                                RPG7Form2.RPG7_treshlow.ValueChanged -= RPG7Form2.RPG7_numericUpDown_ValueChanged;
                                RPG7Form2.RPG7_treshhigh.ValueChanged -= RPG7Form2.RPG7_numericUpDown_ValueChanged;
                                RPG7Form2.RPG7_voltoffset.ValueChanged -= RPG7Form2.RPG7_numericUpDown_ValueChanged;
                                RPG7Form2.RPG7_dagain.ValueChanged -= RPG7Form2.RPG7_numericUpDown_ValueChanged;
                                //
                                ActiveForm2 = RPG7Form2;
                                HwName = "RPG7";
                                RPG7Form2.RPG7_device.Text = HwName;
                                RPG7Form2.RPG7_serial.Text = SerialNumber;
                                RPG7Form2.RPG7_year.Text = "" + ProductionYear;
                                RPG7Form2.RPG7_address.Text = "" + BaseAddress;
                                RPG7Form2.RPG7_hw.Text = HwVersion;
                                RPG7Form2.RPG7_sw.Text = SwVersion;
                                RPG7Form2.RPG7_shots.Text = "" + TotalShots;
                                RPG7Form2.RPG7_powerons.Text = "" + Powerons;
                                RPG7Form2.RPG7_treshlow.Text = "" + TresholdLow;
                                RPG7Form2.RPG7_treshhigh.Text = "" + TresholdHigh;
                                RPG7Form2.RPG7_voltoffset.Text = "" + VoltOffset;
                                RPG7Form2.RPG7_dagain.Text = "" + DAGain;
                                //zapnutie eventu pri zmene numericupdown
                                RPG7Form2.RPG7_treshlow.ValueChanged += RPG7Form2.RPG7_numericUpDown_ValueChanged;
                                RPG7Form2.RPG7_treshhigh.ValueChanged += RPG7Form2.RPG7_numericUpDown_ValueChanged;
                                RPG7Form2.RPG7_voltoffset.ValueChanged += RPG7Form2.RPG7_numericUpDown_ValueChanged;
                                RPG7Form2.RPG7_dagain.ValueChanged += RPG7Form2.RPG7_numericUpDown_ValueChanged;
                                //
                                break;
                            case (2):
                                label1.Text = " GLOCK weapon found";
                                GLOCK.GLOCKForm GLOCKForm2 = new GLOCK.GLOCKForm();
                                GLOCKForm2.Show();
                                //vypnutie eventu pri zmene numericupdown
                                GLOCKForm2.GLOCK_treshlow.ValueChanged -= GLOCKForm2.GLOCK_numericUpDown_ValueChanged;
                                GLOCKForm2.GLOCK_treshhigh.ValueChanged -= GLOCKForm2.GLOCK_numericUpDown_ValueChanged;
                                GLOCKForm2.GLOCK_triggerrelease.ValueChanged -= GLOCKForm2.GLOCK_numericUpDown_ValueChanged;
                                GLOCKForm2.GLOCK_triggerhold.ValueChanged -= GLOCKForm2.GLOCK_numericUpDown_ValueChanged;
                                //
                                ActiveForm2 = GLOCKForm2;
                                HwName = "GLOCK";
                                GLOCKForm2.GLOCK_device.Text = HwName;
                                GLOCKForm2.GLOCK_serial.Text = SerialNumber;
                                GLOCKForm2.GLOCK_year.Text = "" + ProductionYear;
                                GLOCKForm2.GLOCK_address.Text = "" + BaseAddress;
                                GLOCKForm2.GLOCK_hw.Text = HwVersion;
                                GLOCKForm2.GLOCK_sw.Text = SwVersion;
                                GLOCKForm2.GLOCK_shots.Text = "" + TotalShots;
                                GLOCKForm2.GLOCK_powerons.Text = "" + Powerons;
                                GLOCKForm2.GLOCK_boltcatches.Text = "" + BoltCatches;
                                GLOCKForm2.GLOCK_treshlow.Text = "" + TresholdLow;
                                GLOCKForm2.GLOCK_treshhigh.Text = "" + TresholdHigh;
                                GLOCKForm2.GLOCK_triggerrelease.Text = "" + TriggerRelease;
                                GLOCKForm2.GLOCK_triggerhold.Text = "" + TriggerHold;
                                //zapnutie eventu pri zmene numericupdown
                                GLOCKForm2.GLOCK_treshlow.ValueChanged += GLOCKForm2.GLOCK_numericUpDown_ValueChanged;
                                GLOCKForm2.GLOCK_treshhigh.ValueChanged += GLOCKForm2.GLOCK_numericUpDown_ValueChanged;
                                GLOCKForm2.GLOCK_triggerrelease.ValueChanged += GLOCKForm2.GLOCK_numericUpDown_ValueChanged;
                                GLOCKForm2.GLOCK_triggerhold.ValueChanged += GLOCKForm2.GLOCK_numericUpDown_ValueChanged;
                                //134
                                break;
                            case (140):
                                label1.Text = " BROWNING weapon found";
                                BROWN.BROWNForm BROWNForm2 = new BROWN.BROWNForm();
                                BROWNForm2.Show();
                                //vypnutie eventu pri zmene numericupdown
                                BROWNForm2.BROWN_treshlow.ValueChanged -= BROWNForm2.BROWN_numericUpDown_ValueChanged;
                                BROWNForm2.BROWN_treshhigh.ValueChanged -= BROWNForm2.BROWN_numericUpDown_ValueChanged;
                                BROWNForm2.BROWN_triggerrelease.ValueChanged -= BROWNForm2.BROWN_numericUpDown_ValueChanged;
                                BROWNForm2.BROWN_triggerhold.ValueChanged -= BROWNForm2.BROWN_numericUpDown_ValueChanged;
                                //
                                ActiveForm2 = BROWNForm2;
                                HwName = "BROWNING";
                                BROWNForm2.BROWN_device.Text = HwName;
                                BROWNForm2.BROWN_serial.Text = SerialNumber;
                                BROWNForm2.BROWN_year.Text = "" + ProductionYear;
                                BROWNForm2.BROWN_address.Text = "" + BaseAddress;
                                BROWNForm2.BROWN_hw.Text = HwVersion;
                                BROWNForm2.BROWN_sw.Text = SwVersion;
                                BROWNForm2.BROWN_shots.Text = "" + TotalShots;
                                BROWNForm2.BROWN_powerons.Text = "" + Powerons;
                                BROWNForm2.BROWN_boltcatches.Text = "" + BoltCatches;
                                BROWNForm2.BROWN_treshlow.Text = "" + TresholdLow;
                                BROWNForm2.BROWN_treshhigh.Text = "" + TresholdHigh;
                                BROWNForm2.BROWN_triggerrelease.Text = "" + TriggerRelease;
                                BROWNForm2.BROWN_triggerhold.Text = "" + TriggerHold;
                                //zapnutie eventu pri zmene numericupdown
                                BROWNForm2.BROWN_treshlow.ValueChanged += BROWNForm2.BROWN_numericUpDown_ValueChanged;
                                BROWNForm2.BROWN_treshhigh.ValueChanged += BROWNForm2.BROWN_numericUpDown_ValueChanged;
                                BROWNForm2.BROWN_triggerrelease.ValueChanged += BROWNForm2.BROWN_numericUpDown_ValueChanged;
                                BROWNForm2.BROWN_triggerhold.ValueChanged += BROWNForm2.BROWN_numericUpDown_ValueChanged;
                                //
                                break;
                            case (150):
                                label1.Text = " GP34 weapon found";
                                AK103.GP34Form GP34Form2 = new AK103.GP34Form();
                                GP34Form2.Show();
                                //vypnutie eventu pri zmene numericupdown
                                GP34Form2.GP34_trigger1low.ValueChanged -= GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_trigger1high.ValueChanged -= GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_trigger2low.ValueChanged -= GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_trigger2high.ValueChanged -= GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rs0m.ValueChanged -= GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rs100m.ValueChanged -= GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rs150m.ValueChanged -= GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rs200m.ValueChanged -= GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rs250m.ValueChanged -= GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rs300m.ValueChanged -= GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rs350m.ValueChanged -= GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rs400m.ValueChanged -= GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rsx350m.ValueChanged -= GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rsx300m.ValueChanged -= GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rsx250m.ValueChanged -= GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rsx200m.ValueChanged -= GP34Form2.GP34_numericUpDown_ValueChanged;
                                //
                                ActiveForm2 = GP34Form2;
                                HwName = "GP34";
                                GP34Form2.GP34_device.Text = HwName;
                                GP34Form2.GP34_serial.Text = SerialNumber;
                                GP34Form2.GP34_year.Text = "" + ProductionYear;
                                GP34Form2.GP34_address.Text = "" + BaseAddress;
                                GP34Form2.GP34_hw.Text = HwVersion;
                                GP34Form2.GP34_sw.Text = SwVersion;
                                GP34Form2.GP34_shots.Text = "" + TotalShots;
                                GP34Form2.GP34_powerons.Text = "" + Powerons;
                                GP34Form2.GP34_trigger1low.Text = "" + Trigger1Low;
                                GP34Form2.GP34_trigger1high.Text = "" + Trigger1High;
                                GP34Form2.GP34_trigger2low.Text = "" + Trigger2Low;
                                GP34Form2.GP34_trigger2high.Text = "" + Trigger2High;
                                GP34Form2.GP34_rs0m.Text = "" + RS0m;
                                GP34Form2.GP34_rs100m.Text = "" + RS100m;
                                GP34Form2.GP34_rs150m.Text = "" + RS150m;
                                GP34Form2.GP34_rs200m.Text = "" + RS200m;
                                GP34Form2.GP34_rs250m.Text = "" + RS250m;
                                GP34Form2.GP34_rs300m.Text = "" + RS300m;
                                GP34Form2.GP34_rs350m.Text = "" + RS350m;
                                GP34Form2.GP34_rs400m.Text = "" + RS400m;
                                GP34Form2.GP34_rsx350m.Text = "" + RSx350m;
                                GP34Form2.GP34_rsx300m.Text = "" + RSx300m;
                                GP34Form2.GP34_rsx250m.Text = "" + RSx250m;
                                GP34Form2.GP34_rsx200m.Text = "" + RSx200m;
                                //zapnutie eventu pri zmene numericupdown
                                GP34Form2.GP34_trigger1low.ValueChanged += GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_trigger1high.ValueChanged += GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_trigger2low.ValueChanged += GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_trigger2high.ValueChanged += GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rs0m.ValueChanged += GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rs100m.ValueChanged += GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rs150m.ValueChanged += GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rs200m.ValueChanged += GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rs250m.ValueChanged += GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rs300m.ValueChanged += GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rs350m.ValueChanged += GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rs400m.ValueChanged += GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rsx350m.ValueChanged += GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rsx300m.ValueChanged += GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rsx250m.ValueChanged += GP34Form2.GP34_numericUpDown_ValueChanged;
                                GP34Form2.GP34_rsx200m.ValueChanged += GP34Form2.GP34_numericUpDown_ValueChanged;
                                //
                                break;
                            case (138):
                                label1.Text = " M60 weapon found";
                                M60.M60Form M60Form2 = new M60.M60Form();
                                M60Form2.Show();
                                //vypnutie eventu pri zmene numericupdown
                                M60Form2.M60_treshlow.ValueChanged -= M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_treshhigh.ValueChanged -= M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_hs3release.ValueChanged -= M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_hs3hold.ValueChanged -= M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_tempdown.ValueChanged -= M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_tempup.ValueChanged -= M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_maxledpwm.ValueChanged -= M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_downstep1.ValueChanged -= M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_downstep2.ValueChanged -= M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_downstep3.ValueChanged -= M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_upstep1.ValueChanged -= M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_upstep2.ValueChanged -= M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_upstep3.ValueChanged -= M60Form2.M60_numericUpDown_ValueChanged;
                                //
                                ActiveForm2 = M60Form2;
                                HwName = "M60";
                                M60Form2.M60_device.Text = HwName;
                                M60Form2.M60_serial.Text = SerialNumber;
                                M60Form2.M60_year.Text = "" + ProductionYear;
                                M60Form2.M60_address.Text = "" + BaseAddress;
                                M60Form2.M60_hw.Text = HwVersion;
                                M60Form2.M60_sw.Text = SwVersion;
                                M60Form2.M60_shots.Text = "" + TotalShots;
                                M60Form2.M60_powerons.Text = "" + Powerons;
                                M60Form2.M60_reloads.Text = "" + BeltReloads;
                                M60Form2.M60_treshlow.Text = "" + TresholdLow;
                                M60Form2.M60_treshhigh.Text = "" + TresholdHigh;
                                M60Form2.M60_hs3release.Text = "" + HS3Release;
                                M60Form2.M60_hs3hold.Text = "" + HS3Hold;
                                M60Form2.M60_tempdown.Text = "" + TempDown;
                                M60Form2.M60_tempup.Text = "" + TempUp;
                                M60Form2.M60_maxledpwm.Text = "" + MaxLedPWM;
                                M60Form2.M60_downstep1.Text = "" + DownStep1;
                                M60Form2.M60_downstep2.Text = "" + DownStep2;
                                M60Form2.M60_downstep3.Text = "" + DownStep3;
                                M60Form2.M60_upstep1.Text = "" + UpStep1;
                                M60Form2.M60_upstep2.Text = "" + UpStep2;
                                M60Form2.M60_upstep3.Text = "" + UpStep3;
                                //zapnutie eventu pri zmene numericupdown
                                M60Form2.M60_treshlow.ValueChanged += M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_treshhigh.ValueChanged += M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_hs3release.ValueChanged += M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_hs3hold.ValueChanged += M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_tempdown.ValueChanged += M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_tempup.ValueChanged += M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_maxledpwm.ValueChanged += M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_downstep1.ValueChanged += M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_downstep2.ValueChanged += M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_downstep3.ValueChanged += M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_upstep1.ValueChanged += M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_upstep2.ValueChanged += M60Form2.M60_numericUpDown_ValueChanged;
                                M60Form2.M60_upstep3.ValueChanged += M60Form2.M60_numericUpDown_ValueChanged;
                                //
                                break;
                            case (254):
                                label1.Text = " RezervaA weapon found";
                                RezervaA.RezervaAForm RezervaAForm2 = new RezervaA.RezervaAForm();
                                RezervaAForm2.Show();
                                //vypnutie eventu pri zmene numericupdown
                                RezervaAForm2.RezervaA_treshlow.ValueChanged -= RezervaAForm2.RezervaA_numericUpDown_ValueChanged;
                                RezervaAForm2.RezervaA_treshhigh.ValueChanged -= RezervaAForm2.RezervaA_numericUpDown_ValueChanged;
                                RezervaAForm2.RezervaA_triggerrelease.ValueChanged -= RezervaAForm2.RezervaA_numericUpDown_ValueChanged;
                                RezervaAForm2.RezervaA_triggerhold.ValueChanged -= RezervaAForm2.RezervaA_numericUpDown_ValueChanged;
                                //
                                ActiveForm2 = RezervaAForm2;
                                HwName = "RezervaA";
                                RezervaAForm2.RezervaA_device.Text = HwName;
                                RezervaAForm2.RezervaA_serial.Text = SerialNumber;
                                RezervaAForm2.RezervaA_year.Text = "" + ProductionYear;
                                RezervaAForm2.RezervaA_address.Text = "" + BaseAddress;
                                RezervaAForm2.RezervaA_hw.Text = HwVersion;
                                RezervaAForm2.RezervaA_sw.Text = SwVersion;
                                RezervaAForm2.RezervaA_shots.Text = "" + TotalShots;
                                RezervaAForm2.RezervaA_powerons.Text = "" + Powerons;
                                RezervaAForm2.RezervaA_boltcatches.Text = "" + BoltCatches;
                                RezervaAForm2.RezervaA_treshlow.Text = "" + TresholdLow;
                                RezervaAForm2.RezervaA_treshhigh.Text = "" + TresholdHigh;
                                RezervaAForm2.RezervaA_triggerrelease.Text = "" + TriggerRelease;
                                RezervaAForm2.RezervaA_triggerhold.Text = "" + TriggerHold;
                                //zapnutie eventu pri zmene numericupdown
                                RezervaAForm2.RezervaA_treshlow.ValueChanged += RezervaAForm2.RezervaA_numericUpDown_ValueChanged;
                                RezervaAForm2.RezervaA_treshhigh.ValueChanged += RezervaAForm2.RezervaA_numericUpDown_ValueChanged;
                                RezervaAForm2.RezervaA_triggerrelease.ValueChanged += RezervaAForm2.RezervaA_numericUpDown_ValueChanged;
                                RezervaAForm2.RezervaA_triggerhold.ValueChanged += RezervaAForm2.RezervaA_numericUpDown_ValueChanged;
                                //
                                break;
                            case (255):
                                label1.Text = " RezervaB weapon found";
                                RezervaB.RezervaBForm RezervaBForm2 = new RezervaB.RezervaBForm();
                                RezervaBForm2.Show();
                                //vypnutie eventu pri zmene numericupdown
                                RezervaBForm2.RezervaB_treshlow.ValueChanged -= RezervaBForm2.RezervaB_numericUpDown_ValueChanged;
                                RezervaBForm2.RezervaB_treshhigh.ValueChanged -= RezervaBForm2.RezervaB_numericUpDown_ValueChanged;
                                RezervaBForm2.RezervaB_triggerrelease.ValueChanged -= RezervaBForm2.RezervaB_numericUpDown_ValueChanged;
                                RezervaBForm2.RezervaB_triggerhold.ValueChanged -= RezervaBForm2.RezervaB_numericUpDown_ValueChanged;
                                //
                                ActiveForm2 = RezervaBForm2;
                                HwName = "RezervaB";
                                RezervaBForm2.RezervaB_device.Text = HwName;
                                RezervaBForm2.RezervaB_serial.Text = SerialNumber;
                                RezervaBForm2.RezervaB_year.Text = "" + ProductionYear;
                                RezervaBForm2.RezervaB_address.Text = "" + BaseAddress;
                                RezervaBForm2.RezervaB_hw.Text = HwVersion;
                                RezervaBForm2.RezervaB_sw.Text = SwVersion;
                                RezervaBForm2.RezervaB_shots.Text = "" + TotalShots;
                                RezervaBForm2.RezervaB_powerons.Text = "" + Powerons;
                                RezervaBForm2.RezervaB_boltcatches.Text = "" + BoltCatches;
                                RezervaBForm2.RezervaB_treshlow.Text = "" + TresholdLow;
                                RezervaBForm2.RezervaB_treshhigh.Text = "" + TresholdHigh;
                                RezervaBForm2.RezervaB_triggerrelease.Text = "" + TriggerRelease;
                                RezervaBForm2.RezervaB_triggerhold.Text = "" + TriggerHold;
                                //zapnutie eventu pri zmene numericupdown
                                RezervaBForm2.RezervaB_treshlow.ValueChanged += RezervaBForm2.RezervaB_numericUpDown_ValueChanged;
                                RezervaBForm2.RezervaB_treshhigh.ValueChanged += RezervaBForm2.RezervaB_numericUpDown_ValueChanged;
                                RezervaBForm2.RezervaB_triggerrelease.ValueChanged += RezervaBForm2.RezervaB_numericUpDown_ValueChanged;
                                RezervaBForm2.RezervaB_triggerhold.ValueChanged += RezervaBForm2.RezervaB_numericUpDown_ValueChanged;
                                //
                                break;
                            default:
                                label1.Text = "Unknown weapon found";
                                break;
                        }


                        
                        }
                        timer1.Enabled = true;
                        return;
                    }
                    if(ActiveForm2 != null)ActiveForm2.Close();
                    ActiveForm2 = null;
                    RxCounter = 0;
                    label1.Text = "Connect weapon to USB";
                    
                }

                toolStripStatusLabel2.Text = "RX: " + RxCounter;
            }
            catch (Exception ee1)
            {
                MessageBox.Show("CANaerospace server is offline.");
            }
            timer1.Enabled = true;
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            timer1.Enabled = false;
            try
            {
                System.Diagnostics.Process[] proc = System.Diagnostics.Process.GetProcessesByName("CanAerospaceServer");
	            proc[0].Kill();
            }
            catch (Exception e2)
            {
                //MessageBox.Show("Now you can exit the CANaerospace server.");
            }
            try
            {
                System.Diagnostics.Process[] proc = System.Diagnostics.Process.GetProcessesByName("FlashMagic");
                proc[0].Kill();
            }
            catch (Exception ee2)
            {
                //MessageBox.Show("Flash Magic closed.");
            }

        }

        private void backToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            try
            {
                System.Diagnostics.Process[] proc = System.Diagnostics.Process.GetProcessesByName("FlashMagic");
                proc[0].Kill();
            }
            catch (Exception ee4)
            {
                //MessageBox.Show("Flash Magic closed.");
            }
            string filePath = System.IO.Path.Combine(Environment.CurrentDirectory, "CanAerospace");
            filePath = System.IO.Path.Combine(filePath, "server_bin");
            filePath = System.IO.Path.Combine(filePath, "CanAerospaceServer.exe");
            System.Diagnostics.Process.Start(filePath);
            Thread.Sleep(7000);
            timer1.Enabled = true;
            backToolStripMenuItem1.Visible = false;
            flashFirmwareToolStripMenuItem.Visible = true;
            
        }
         
    }



public class MyCanAerospace : CanAerospace      // pre spracovanie cyklicky vysielanych udajov
{
    public override void OnCyclicValueReceived(CyclicValueKey key, CanData value, int messageCounter)
    {
      
        if (Application.OpenForms.OfType<Form1>().Any())
        {
            Form1 mainform = Application.OpenForms.OfType<Form1>().First();
            mainform.RxCounter = mainform.RxCounter + 1;
            mainform.toolStripStatusLabel2.Text = "RX: " + mainform.RxCounter;

            //mainform.idx1 = false;
            //mainform.idx2 = false;

            switch (key.nodeId)
            {
                case 2: // -------------------------------------------------------------------------------------- GLOCK
                    GLOCK.GLOCKForm activeformGLOCK = (GLOCK.GLOCKForm)mainform.ActiveForm2;
                    switch (key.canId)
                    {
                        case 1500:
                            byte[] accValueXY = value.GetRawData();
                            if (accValueXY != null) 
                            { 
                                mainform.axis_x_raw_data = (short)((accValueXY[0] << 8) + accValueXY[1]);
                                mainform.axis_y_raw_data = (short)((accValueXY[2] << 8) + accValueXY[3]);
                                if ((mainform.axis_x_raw_data != 0) && (mainform.axis_y_raw_data != 0)) mainform.idx1 = true;
                            }
                            break;

                        case 1501:
                            byte[] accValueZ = value.GetRawData();
                            if (accValueZ != null)
                            {
                                mainform.axis_z_raw_data = (short)((accValueZ[0] << 8) + accValueZ[1]);

                                if(mainform.axis_z_raw_data != 0)mainform.idx2 = true;
                            }
                            break;

                        case 1503:
                            byte[] triggerData = value.GetRawData();
                            if (triggerData != null)
                            {
                                //Trigger Position
                                activeformGLOCK.GLOCK_trigger.Width = (triggerData[0]) * 241 / 255;
                                //Flags0
                                if (((triggerData[2]) & 128) == '\0')
                                {
                                    activeformGLOCK.GLOCK_magazine.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformGLOCK.GLOCK_magazine.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 16) == '\0')
                                {
                                    activeformGLOCK.GLOCK_fasthall.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformGLOCK.GLOCK_fasthall.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 4) == '\0')
                                {
                                    activeformGLOCK.GLOCK_hscover.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformGLOCK.GLOCK_hscover.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 2) == '\0')
                                {
                                    activeformGLOCK.GLOCK_boltb.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformGLOCK.GLOCK_boltb.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 1) == '\0')
                                {
                                    activeformGLOCK.GLOCK_boltf.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformGLOCK.GLOCK_boltf.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                            }
                            break;

                        case 1506:
                            ulong CyclicTotalShots = 0;
                            CyclicTotalShots = value.GetAsUlong();
                            if (CyclicTotalShots != 0)
                            {
                                activeformGLOCK.GLOCK_shots.Text = "" + CyclicTotalShots;
                            }
                            break;
                    }

                    if ((mainform.idx1) && (mainform.idx2))
                    {
                        //angle
                        float temp1, temp2;
                        
                        if ((mainform.axis_x_raw_data & 0x800)==0)
                        {
                            mainform.axis_x_g_value = (float)mainform.axis_x_raw_data / 1024;
                        }
                        else
                        {
                            mainform.axis_x_g_value = (float)mainform.axis_x_raw_data / 1024;// -4;
                        }

                        if ((mainform.axis_y_raw_data & 0x800)==0)
                        {
                            mainform.axis_y_g_value = (float)mainform.axis_y_raw_data / 1024;
                        }
                        else
                        {
                            mainform.axis_y_g_value = (float)mainform.axis_y_raw_data / 1024;// -4;
                        }

                        if ((mainform.axis_z_raw_data & 0x800) == 0)
                        {
                            mainform.axis_z_g_value = (float)mainform.axis_z_raw_data / 1024;
                        }
                        else
                        {
                            mainform.axis_z_g_value = (float)mainform.axis_z_raw_data / 1024;// -4;
                        }

                        mainform.temp_x_g_value += mainform.axis_x_g_value;
                        mainform.temp_y_g_value += mainform.axis_y_g_value;
                        mainform.temp_z_g_value += mainform.axis_z_g_value;

                        mainform.idx++;

                        if (mainform.idx < (mainform.num_of_samples - 1)) return;

                        mainform.idx = 0;

                        mainform.axis_x_g_value = mainform.temp_x_g_value / mainform.num_of_samples;
                        mainform.axis_y_g_value = mainform.temp_y_g_value / mainform.num_of_samples;
                        mainform.axis_z_g_value = mainform.temp_z_g_value / mainform.num_of_samples;

                        mainform.temp_x_g_value = 0;
                        mainform.temp_y_g_value = 0;
                        mainform.temp_z_g_value = 0;

                        if (((mainform.axis_x_g_value == 0) && (mainform.axis_z_g_value == 0)) || ((mainform.axis_y_g_value == 0) && (mainform.axis_z_g_value == 0))) return;

                        temp1 = mainform.axis_x_g_value / (float)Math.Sqrt(mainform.axis_y_g_value * mainform.axis_y_g_value + mainform.axis_z_g_value * mainform.axis_z_g_value);
                        temp2 = mainform.axis_y_g_value / (float)Math.Sqrt(mainform.axis_x_g_value * mainform.axis_x_g_value + mainform.axis_z_g_value * mainform.axis_z_g_value);

                        mainform.actual_pitch_angle = (float)Math.Atan(temp1) * 180 / (float)Math.PI;
                        mainform.actual_roll_angle = (float)Math.Atan(temp2) * 180 / (float)Math.PI;
                        activeformGLOCK.GLOCK_accelerhor.Value = (int)mainform.actual_roll_angle;
                        activeformGLOCK.GLOCK_accelerver.Value = (int)mainform.actual_pitch_angle;

                        //
                        mainform.idx1 = false;
                        mainform.idx2 = false;
                    }

                    break;
                case 132: // -------------------------------------------------------------------------------------- MP5
                    MP5.MP5Form activeformMP5 = (MP5.MP5Form)mainform.ActiveForm2;
                    switch (key.canId)
                    {
                        case 1500:
                            byte[] accValueXY = value.GetRawData();
                            if (accValueXY != null)
                            {
                                mainform.axis_x_raw_data = (short)((accValueXY[0] << 8) + accValueXY[1]);
                                mainform.axis_y_raw_data = (short)((accValueXY[2] << 8) + accValueXY[3]);
                                if ((mainform.axis_x_raw_data != 0) && (mainform.axis_y_raw_data != 0)) mainform.idx1 = true;
                            }
                            break;

                        case 1501:
                            byte[] accValueZ = value.GetRawData();
                            if (accValueZ != null)
                            {
                                mainform.axis_z_raw_data = (short)((accValueZ[0] << 8) + accValueZ[1]);

                                if (mainform.axis_z_raw_data != 0) mainform.idx2 = true;
                            }
                            break;

                        case 1503:
                            byte[] triggerData = value.GetRawData();
                            if (triggerData != null)
                            {
                                //Trigger Position
                                activeformMP5.MP5_trigger.Width = (triggerData[0]) * 241 / 255;
                                //Joystick
                                if (triggerData[1] == 223)
                                {
                                    activeformMP5.MP5_navi_up.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                else
                                {
                                    activeformMP5.MP5_navi_up.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                if (triggerData[1] == 127)
                                {
                                    activeformMP5.MP5_navi_down.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                else
                                {
                                    activeformMP5.MP5_navi_down.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                if (triggerData[1] == 213)
                                {
                                    activeformMP5.MP5_navi_left.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                else
                                {
                                    activeformMP5.MP5_navi_left.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                if (triggerData[1] == 239)
                                {
                                    activeformMP5.MP5_navi_right.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                else
                                {
                                    activeformMP5.MP5_navi_right.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                if (triggerData[1] == 191)
                                {
                                    activeformMP5.MP5_navi_mid.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                else
                                {
                                    activeformMP5.MP5_navi_mid.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                //Flags0
                                if (((triggerData[2]) & 128) == '\0')
                                {
                                    activeformMP5.MP5_magazine.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformMP5.MP5_magazine.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 64) == '\0')
                                {
                                    activeformMP5.MP5_auto.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformMP5.MP5_auto.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 32) == '\0')
                                {
                                    activeformMP5.MP5_semi.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformMP5.MP5_semi.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 16) == '\0')
                                {
                                    activeformMP5.MP5_safe.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformMP5.MP5_safe.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 8) == '\0')
                                {
                                    activeformMP5.MP5_hammerf.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformMP5.MP5_hammerf.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 4) == '\0')
                                {
                                    activeformMP5.MP5_hammerb.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformMP5.MP5_hammerb.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 2) == '\0')
                                {
                                    activeformMP5.MP5_boltb.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformMP5.MP5_boltb.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 1) == '\0')
                                {
                                    activeformMP5.MP5_boltf.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformMP5.MP5_boltf.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                //fasthall
                                if (((triggerData[3]) & 1) == '\0')
                                {
                                    activeformMP5.MP5_boltfs.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformMP5.MP5_boltfs.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                            }
                            break;

                        case 1506:
                            ulong CyclicTotalShots = 0;
                            CyclicTotalShots = value.GetAsUlong();
                            if (CyclicTotalShots != 0)
                            {
                                activeformMP5.MP5_shots.Text = "" + CyclicTotalShots;
                            }
                            break;
                    }

                    if ((mainform.idx1) && (mainform.idx2))
                    {
                        //angle
                        float temp1, temp2;

                        if ((mainform.axis_x_raw_data & 0x800) == 0)
                        {
                            mainform.axis_x_g_value = (float)mainform.axis_x_raw_data / 1024;
                        }
                        else
                        {
                            mainform.axis_x_g_value = (float)mainform.axis_x_raw_data / 1024;// -4;
                        }

                        if ((mainform.axis_y_raw_data & 0x800) == 0)
                        {
                            mainform.axis_y_g_value = (float)mainform.axis_y_raw_data / 1024;
                        }
                        else
                        {
                            mainform.axis_y_g_value = (float)mainform.axis_y_raw_data / 1024;// -4;
                        }

                        if ((mainform.axis_z_raw_data & 0x800) == 0)
                        {
                            mainform.axis_z_g_value = (float)mainform.axis_z_raw_data / 1024;
                        }
                        else
                        {
                            mainform.axis_z_g_value = (float)mainform.axis_z_raw_data / 1024;// -4;
                        }

                        mainform.temp_x_g_value += mainform.axis_x_g_value;
                        mainform.temp_y_g_value += mainform.axis_y_g_value;
                        mainform.temp_z_g_value += mainform.axis_z_g_value;

                        mainform.idx++;

                        if (mainform.idx < (mainform.num_of_samples - 1)) return;

                        mainform.idx = 0;

                        mainform.axis_x_g_value = mainform.temp_x_g_value / mainform.num_of_samples;
                        mainform.axis_y_g_value = mainform.temp_y_g_value / mainform.num_of_samples;
                        mainform.axis_z_g_value = mainform.temp_z_g_value / mainform.num_of_samples;

                        mainform.temp_x_g_value = 0;
                        mainform.temp_y_g_value = 0;
                        mainform.temp_z_g_value = 0;

                        if (((mainform.axis_x_g_value == 0) && (mainform.axis_z_g_value == 0)) || ((mainform.axis_y_g_value == 0) && (mainform.axis_z_g_value == 0))) return;

                        temp1 = mainform.axis_x_g_value / (float)Math.Sqrt(mainform.axis_y_g_value * mainform.axis_y_g_value + mainform.axis_z_g_value * mainform.axis_z_g_value);
                        temp2 = mainform.axis_y_g_value / (float)Math.Sqrt(mainform.axis_x_g_value * mainform.axis_x_g_value + mainform.axis_z_g_value * mainform.axis_z_g_value);

                        mainform.actual_pitch_angle = (float)Math.Atan(temp1) * 180 / (float)Math.PI;
                        mainform.actual_roll_angle = (float)Math.Atan(temp2) * 180 / (float)Math.PI;
                        activeformMP5.MP5_accelerhor.Value = (int)mainform.actual_roll_angle;
                        activeformMP5.MP5_accelerver.Value = (int)mainform.actual_pitch_angle;

                        //
                        mainform.idx1 = false;
                        mainform.idx2 = false;
                    }

                    break;
                case 139: // -------------------------------------------------------------------------------------- AK103
                    AK103.AK103Form activeformAK103 = (AK103.AK103Form)mainform.ActiveForm2;
                    switch (key.canId)
                    {
                        case 1500:
                            byte[] accValueXY = value.GetRawData();
                            if (accValueXY != null)
                            {
                                mainform.axis_x_raw_data = (short)((accValueXY[0] << 8) + accValueXY[1]);
                                mainform.axis_y_raw_data = (short)((accValueXY[2] << 8) + accValueXY[3]);
                                if ((mainform.axis_x_raw_data != 0) && (mainform.axis_y_raw_data != 0)) mainform.idx1 = true;
                            }
                            break;

                        case 1501:
                            byte[] accValueZ = value.GetRawData();
                            if (accValueZ != null)
                            {
                                mainform.axis_z_raw_data = (short)((accValueZ[0] << 8) + accValueZ[1]);

                                if (mainform.axis_z_raw_data != 0) mainform.idx2 = true;
                            }
                            break;

                        case 1503:
                            byte[] triggerData = value.GetRawData();
                            if (triggerData != null)
                            {
                                //Trigger Position
                                activeformAK103.AK103_trigger.Width = (triggerData[0]) * 241 / 255;
                                //Joystick
                                if (triggerData[1] == 223)
                                {
                                    activeformAK103.AK103_navi_up.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                else
                                {
                                    activeformAK103.AK103_navi_up.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                if (triggerData[1] == 127)
                                {
                                    activeformAK103.AK103_navi_down.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                else
                                {
                                    activeformAK103.AK103_navi_down.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                if (triggerData[1] == 213)
                                {
                                    activeformAK103.AK103_navi_left.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                else
                                {
                                    activeformAK103.AK103_navi_left.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                if (triggerData[1] == 239)
                                {
                                    activeformAK103.AK103_navi_right.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                else
                                {
                                    activeformAK103.AK103_navi_right.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                if (triggerData[1] == 191)
                                {
                                    activeformAK103.AK103_navi_mid.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                else
                                {
                                    activeformAK103.AK103_navi_mid.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                //Flags0
                                if (((triggerData[2]) & 128) == '\0')
                                {
                                    activeformAK103.AK103_magazine.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformAK103.AK103_magazine.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 64) == '\0')
                                {
                                    activeformAK103.AK103_auto.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformAK103.AK103_auto.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 32) == '\0')
                                {
                                    activeformAK103.AK103_semi.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformAK103.AK103_semi.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 16) == '\0')
                                {
                                    activeformAK103.AK103_safe.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformAK103.AK103_safe.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 8) == '\0')
                                {
                                    activeformAK103.AK103_hammerb.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformAK103.AK103_hammerb.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 4) == '\0')
                                {
                                    activeformAK103.AK103_hammerf.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformAK103.AK103_hammerf.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 2) == '\0')
                                {
                                    activeformAK103.AK103_boltb.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformAK103.AK103_boltb.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 1) == '\0')
                                {
                                    activeformAK103.AK103_boltf.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformAK103.AK103_boltf.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                //fasthall
                                if (((triggerData[3]) & 1) == '\0')
                                {
                                    activeformAK103.AK103_boltfs.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformAK103.AK103_boltfs.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                            }
                            break;

                        case 1506:
                            ulong CyclicTotalShots = 0;
                            CyclicTotalShots = value.GetAsUlong();
                            if (CyclicTotalShots != 0)
                            {
                                activeformAK103.AK103_shots.Text = "" + CyclicTotalShots;
                            }
                            break;
                    }

                    if ((mainform.idx1) && (mainform.idx2))
                    {
                        //angle
                        float temp1, temp2;

                        if ((mainform.axis_x_raw_data & 0x800) == 0)
                        {
                            mainform.axis_x_g_value = (float)mainform.axis_x_raw_data / 1024;
                        }
                        else
                        {
                            mainform.axis_x_g_value = (float)mainform.axis_x_raw_data / 1024;// -4;
                        }

                        if ((mainform.axis_y_raw_data & 0x800) == 0)
                        {
                            mainform.axis_y_g_value = (float)mainform.axis_y_raw_data / 1024;
                        }
                        else
                        {
                            mainform.axis_y_g_value = (float)mainform.axis_y_raw_data / 1024;// -4;
                        }

                        if ((mainform.axis_z_raw_data & 0x800) == 0)
                        {
                            mainform.axis_z_g_value = (float)mainform.axis_z_raw_data / 1024;
                        }
                        else
                        {
                            mainform.axis_z_g_value = (float)mainform.axis_z_raw_data / 1024;// -4;
                        }

                        mainform.temp_x_g_value += mainform.axis_x_g_value;
                        mainform.temp_y_g_value += mainform.axis_y_g_value;
                        mainform.temp_z_g_value += mainform.axis_z_g_value;

                        mainform.idx++;

                        if (mainform.idx < (mainform.num_of_samples - 1)) return;

                        mainform.idx = 0;

                        mainform.axis_x_g_value = mainform.temp_x_g_value / mainform.num_of_samples;
                        mainform.axis_y_g_value = mainform.temp_y_g_value / mainform.num_of_samples;
                        mainform.axis_z_g_value = mainform.temp_z_g_value / mainform.num_of_samples;

                        mainform.temp_x_g_value = 0;
                        mainform.temp_y_g_value = 0;
                        mainform.temp_z_g_value = 0;

                        if (((mainform.axis_x_g_value == 0) && (mainform.axis_z_g_value == 0)) || ((mainform.axis_y_g_value == 0) && (mainform.axis_z_g_value == 0))) return;

                        temp1 = mainform.axis_x_g_value / (float)Math.Sqrt(mainform.axis_y_g_value * mainform.axis_y_g_value + mainform.axis_z_g_value * mainform.axis_z_g_value);
                        temp2 = mainform.axis_y_g_value / (float)Math.Sqrt(mainform.axis_x_g_value * mainform.axis_x_g_value + mainform.axis_z_g_value * mainform.axis_z_g_value);

                        mainform.actual_pitch_angle = (float)Math.Atan(temp1) * 180 / (float)Math.PI;
                        mainform.actual_roll_angle = (float)Math.Atan(temp2) * 180 / (float)Math.PI;
                        activeformAK103.AK103_accelerhor.Value = (int)mainform.actual_roll_angle;
                        activeformAK103.AK103_accelerver.Value = (int)mainform.actual_pitch_angle;

                        //
                        mainform.idx1 = false;
                        mainform.idx2 = false;
                    }

                    break;
                case 150: // -------------------------------------------------------------------------------------- GP34
                    AK103.GP34Form activeformGP34 = (AK103.GP34Form)mainform.ActiveForm2;
                    switch (key.canId)
                    {
                        case 1501:
                            ushort[] triggerData1 = value.GetAsUshort2();
                            if (triggerData1 != null)
                            {
                                //Trigger Position
                                activeformGP34.GP34_trigger.Width = (triggerData1[0]) * 241 / 255;
                                //TriggerFlags
                                if (((byte)(triggerData1[1]) & 4) == '\0')
                                {
                                    activeformGP34.GP34_trigger33.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformGP34.GP34_trigger33.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((byte)(triggerData1[1]) & 2) == '\0')
                                {
                                    activeformGP34.GP34_trigger23.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformGP34.GP34_trigger23.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((byte)(triggerData1[1]) & 1) == '\0')
                                {
                                    activeformGP34.GP34_trigger13.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformGP34.GP34_trigger13.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                            }
                            break;

                        case 1502:
                            byte[] triggerData = value.GetRawData();
                            if (triggerData != null)
                            {
                                //Flags0
                                if (((triggerData[0]) & 32) == '\0')
                                {
                                    activeformGP34.GP34_ready.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformGP34.GP34_ready.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[0]) & 16) == '\0')
                                {
                                    activeformGP34.GP34_loaded.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformGP34.GP34_loaded.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[0]) & 8) == '\0')
                                {
                                    activeformGP34.GP34_safe.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                    activeformGP34.GP34_unsafe.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                else
                                {
                                    activeformGP34.GP34_safe.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                    activeformGP34.GP34_unsafe.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                if (((triggerData[0]) & 4) == '\0')
                                {
                                    activeformGP34.GP34_he.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformGP34.GP34_he.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[0]) & 2) == '\0')
                                {
                                    activeformGP34.GP34_heap.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformGP34.GP34_heap.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[0]) & 1) == '\0')
                                {
                                    activeformGP34.GP34_smk.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformGP34.GP34_smk.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                            }
                            break;

                        case 1506:
                            ulong CyclicTotalShots = 0;
                            CyclicTotalShots = value.GetAsUlong();
                            if (CyclicTotalShots != 0)
                            {
                                activeformGP34.GP34_shots.Text = "" + CyclicTotalShots;
                            }
                            break;
                    }
                    break;
                case 140: // -------------------------------------------------------------------------------------- BROWN
                    BROWN.BROWNForm activeformBROWN = (BROWN.BROWNForm)mainform.ActiveForm2;
                    switch (key.canId)
                    {
                        case 1500:
                            byte[] accValueXY = value.GetRawData();
                            if (accValueXY != null)
                            {
                                mainform.axis_x_raw_data = (short)((accValueXY[0] << 8) + accValueXY[1]);
                                mainform.axis_y_raw_data = (short)((accValueXY[2] << 8) + accValueXY[3]);
                                if ((mainform.axis_x_raw_data != 0) && (mainform.axis_y_raw_data != 0)) mainform.idx1 = true;
                            }
                            break;

                        case 1501:
                            byte[] accValueZ = value.GetRawData();
                            if (accValueZ != null)
                            {
                                mainform.axis_z_raw_data = (short)((accValueZ[0] << 8) + accValueZ[1]);

                                if (mainform.axis_z_raw_data != 0) mainform.idx2 = true;
                            }
                            break;

                        case 1503:
                            byte[] triggerData = value.GetRawData();
                            if (triggerData != null)
                            {
                                //Trigger Position
                                activeformBROWN.BROWN_trigger.Width = (triggerData[0]) * 241 / 255;
                                //Flags0
                                if (((triggerData[2]) & 128) == '\0')
                                {
                                    activeformBROWN.BROWN_magazine.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformBROWN.BROWN_magazine.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 64) == '\0')
                                {
                                    activeformBROWN.BROWN_safety.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformBROWN.BROWN_safety.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 32) == '\0')
                                {
                                    activeformBROWN.BROWN_hammer.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformBROWN.BROWN_hammer.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 16) == '\0')
                                {
                                    activeformBROWN.BROWN_fasthall.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformBROWN.BROWN_fasthall.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 4) == '\0')
                                {
                                    activeformBROWN.BROWN_hscover.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformBROWN.BROWN_hscover.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 2) == '\0')
                                {
                                    activeformBROWN.BROWN_boltb.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformBROWN.BROWN_boltb.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 1) == '\0')
                                {
                                    activeformBROWN.BROWN_boltf.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformBROWN.BROWN_boltf.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                            }
                            break;

                        case 1506:
                            ulong CyclicTotalShots = 0;
                            CyclicTotalShots = value.GetAsUlong();
                            if (CyclicTotalShots != 0)
                            {
                                activeformBROWN.BROWN_shots.Text = "" + CyclicTotalShots;
                            }
                            break;
                    }

                    if ((mainform.idx1) && (mainform.idx2))
                    {
                        //angle
                        float temp1, temp2;

                        if ((mainform.axis_x_raw_data & 0x800) == 0)
                        {
                            mainform.axis_x_g_value = (float)mainform.axis_x_raw_data / 1024;
                        }
                        else
                        {
                            mainform.axis_x_g_value = (float)mainform.axis_x_raw_data / 1024;// -4;
                        }

                        if ((mainform.axis_y_raw_data & 0x800) == 0)
                        {
                            mainform.axis_y_g_value = (float)mainform.axis_y_raw_data / 1024;
                        }
                        else
                        {
                            mainform.axis_y_g_value = (float)mainform.axis_y_raw_data / 1024;// -4;
                        }

                        if ((mainform.axis_z_raw_data & 0x800) == 0)
                        {
                            mainform.axis_z_g_value = (float)mainform.axis_z_raw_data / 1024;
                        }
                        else
                        {
                            mainform.axis_z_g_value = (float)mainform.axis_z_raw_data / 1024;// -4;
                        }

                        mainform.temp_x_g_value += mainform.axis_x_g_value;
                        mainform.temp_y_g_value += mainform.axis_y_g_value;
                        mainform.temp_z_g_value += mainform.axis_z_g_value;

                        mainform.idx++;

                        if (mainform.idx < (mainform.num_of_samples - 1)) return;

                        mainform.idx = 0;

                        mainform.axis_x_g_value = mainform.temp_x_g_value / mainform.num_of_samples;
                        mainform.axis_y_g_value = mainform.temp_y_g_value / mainform.num_of_samples;
                        mainform.axis_z_g_value = mainform.temp_z_g_value / mainform.num_of_samples;

                        mainform.temp_x_g_value = 0;
                        mainform.temp_y_g_value = 0;
                        mainform.temp_z_g_value = 0;

                        if (((mainform.axis_x_g_value == 0) && (mainform.axis_z_g_value == 0)) || ((mainform.axis_y_g_value == 0) && (mainform.axis_z_g_value == 0))) return;

                        temp1 = mainform.axis_x_g_value / (float)Math.Sqrt(mainform.axis_y_g_value * mainform.axis_y_g_value + mainform.axis_z_g_value * mainform.axis_z_g_value);
                        temp2 = mainform.axis_y_g_value / (float)Math.Sqrt(mainform.axis_x_g_value * mainform.axis_x_g_value + mainform.axis_z_g_value * mainform.axis_z_g_value);

                        mainform.actual_pitch_angle = (float)Math.Atan(temp1) * 180 / (float)Math.PI;
                        mainform.actual_roll_angle = (float)Math.Atan(temp2) * 180 / (float)Math.PI;
                        activeformBROWN.BROWN_accelerhor.Value = (int)mainform.actual_roll_angle;
                        activeformBROWN.BROWN_accelerver.Value = (int)mainform.actual_pitch_angle;

                        //
                        mainform.idx1 = false;
                        mainform.idx2 = false;
                    }
                    break;
                case 142: // -------------------------------------------------------------------------------------- COYOTE
                    COYOTE.COYOTEForm activeformCOYOTE = (COYOTE.COYOTEForm)mainform.ActiveForm2;
                    switch (key.canId)
                    {
                        case 1500:
                            byte[] accValueXY = value.GetRawData();
                            if (accValueXY != null)
                            {
                                mainform.axis_x_raw_data = (short)((accValueXY[0] << 8) + accValueXY[1]);
                                mainform.axis_y_raw_data = (short)((accValueXY[2] << 8) + accValueXY[3]);
                                if ((mainform.axis_x_raw_data != 0) && (mainform.axis_y_raw_data != 0)) mainform.idx1 = true;
                            }
                            break;

                        case 1501:
                            byte[] accValueZ = value.GetRawData();
                            if (accValueZ != null)
                            {
                                mainform.axis_z_raw_data = (short)((accValueZ[0] << 8) + accValueZ[1]);

                                if (mainform.axis_z_raw_data != 0) mainform.idx2 = true;
                            }
                            break;

                        case 1503:
                            byte[] triggerData = value.GetRawData();
                            if (triggerData != null)
                            {
                                //Trigger Position
                                activeformCOYOTE.COYOTE_trigger.Width = (triggerData[0]) * 241 / 255;
                                //Joystick
                                if (triggerData[1] == 223)
                                {
                                    activeformCOYOTE.COYOTE_navi_up.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                else
                                {
                                    activeformCOYOTE.COYOTE_navi_up.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                if (triggerData[1] == 127)
                                {
                                    activeformCOYOTE.COYOTE_navi_down.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                else
                                {
                                    activeformCOYOTE.COYOTE_navi_down.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                if (triggerData[1] == 213)
                                {
                                    activeformCOYOTE.COYOTE_navi_left.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                else
                                {
                                    activeformCOYOTE.COYOTE_navi_left.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                if (triggerData[1] == 239)
                                {
                                    activeformCOYOTE.COYOTE_navi_right.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                else
                                {
                                    activeformCOYOTE.COYOTE_navi_right.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                if (triggerData[1] == 191)
                                {
                                    activeformCOYOTE.COYOTE_navi_mid.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                else
                                {
                                    activeformCOYOTE.COYOTE_navi_mid.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                //Flags0
                                if (((triggerData[2]) & 128) == '\0')
                                {
                                    activeformCOYOTE.COYOTE_magazine.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformCOYOTE.COYOTE_magazine.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 64) == '\0')
                                {
                                    activeformCOYOTE.COYOTE_boltunlock.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformCOYOTE.COYOTE_boltunlock.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 32) == '\0')
                                {
                                    activeformCOYOTE.COYOTE_boltlock.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformCOYOTE.COYOTE_boltlock.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 16) == '\0')
                                {
                                    activeformCOYOTE.COYOTE_safe.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformCOYOTE.COYOTE_safe.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 8) == '\0')
                                {
                                    activeformCOYOTE.COYOTE_fire.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformCOYOTE.COYOTE_fire.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 4) == '\0')
                                {
                                    activeformCOYOTE.COYOTE_firingpin.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformCOYOTE.COYOTE_firingpin.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 2) == '\0')
                                {
                                    activeformCOYOTE.COYOTE_boltb.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformCOYOTE.COYOTE_boltb.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 1) == '\0')
                                {
                                    activeformCOYOTE.COYOTE_boltf.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformCOYOTE.COYOTE_boltf.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                            }
                            break;

                        case 1506:
                            ulong CyclicTotalShots = 0;
                            CyclicTotalShots = value.GetAsUlong();
                            if (CyclicTotalShots != 0)
                            {
                                activeformCOYOTE.COYOTE_shots.Text = "" + CyclicTotalShots;
                            }
                            break;
                    }

                    if ((mainform.idx1) && (mainform.idx2))
                    {
                        //angle
                        float temp1, temp2;

                        if ((mainform.axis_x_raw_data & 0x800) == 0)
                        {
                            mainform.axis_x_g_value = (float)mainform.axis_x_raw_data / 1024;
                        }
                        else
                        {
                            mainform.axis_x_g_value = (float)mainform.axis_x_raw_data / 1024;// -4;
                        }

                        if ((mainform.axis_y_raw_data & 0x800) == 0)
                        {
                            mainform.axis_y_g_value = (float)mainform.axis_y_raw_data / 1024;
                        }
                        else
                        {
                            mainform.axis_y_g_value = (float)mainform.axis_y_raw_data / 1024;// -4;
                        }

                        if ((mainform.axis_z_raw_data & 0x800) == 0)
                        {
                            mainform.axis_z_g_value = (float)mainform.axis_z_raw_data / 1024;
                        }
                        else
                        {
                            mainform.axis_z_g_value = (float)mainform.axis_z_raw_data / 1024;// -4;
                        }

                        mainform.temp_x_g_value += mainform.axis_x_g_value;
                        mainform.temp_y_g_value += mainform.axis_y_g_value;
                        mainform.temp_z_g_value += mainform.axis_z_g_value;

                        mainform.idx++;

                        if (mainform.idx < (mainform.num_of_samples - 1)) return;

                        mainform.idx = 0;

                        mainform.axis_x_g_value = mainform.temp_x_g_value / mainform.num_of_samples;
                        mainform.axis_y_g_value = mainform.temp_y_g_value / mainform.num_of_samples;
                        mainform.axis_z_g_value = mainform.temp_z_g_value / mainform.num_of_samples;

                        mainform.temp_x_g_value = 0;
                        mainform.temp_y_g_value = 0;
                        mainform.temp_z_g_value = 0;

                        if (((mainform.axis_x_g_value == 0) && (mainform.axis_z_g_value == 0)) || ((mainform.axis_y_g_value == 0) && (mainform.axis_z_g_value == 0))) return;

                        temp1 = mainform.axis_x_g_value / (float)Math.Sqrt(mainform.axis_y_g_value * mainform.axis_y_g_value + mainform.axis_z_g_value * mainform.axis_z_g_value);
                        temp2 = mainform.axis_y_g_value / (float)Math.Sqrt(mainform.axis_x_g_value * mainform.axis_x_g_value + mainform.axis_z_g_value * mainform.axis_z_g_value);

                        mainform.actual_pitch_angle = (float)Math.Atan(temp1) * 180 / (float)Math.PI;
                        mainform.actual_roll_angle = (float)Math.Atan(temp2) * 180 / (float)Math.PI;
                        activeformCOYOTE.COYOTE_accelerhor.Value = (int)mainform.actual_roll_angle;
                        activeformCOYOTE.COYOTE_accelerver.Value = (int)mainform.actual_pitch_angle;

                        //
                        mainform.idx1 = false;
                        mainform.idx2 = false;
                    }
                    break;
                case 137: // -------------------------------------------------------------------------------------- G3
                    G3.G3Form activeformG3 = (G3.G3Form)mainform.ActiveForm2;
                    switch (key.canId)
                    {
                        case 1500:
                            byte[] accValueXY = value.GetRawData();
                            if (accValueXY != null)
                            {
                                mainform.axis_x_raw_data = (short)((accValueXY[0] << 8) + accValueXY[1]);
                                mainform.axis_y_raw_data = (short)((accValueXY[2] << 8) + accValueXY[3]);
                                if ((mainform.axis_x_raw_data != 0) && (mainform.axis_y_raw_data != 0)) mainform.idx1 = true;
                            }
                            break;

                        case 1502:
                            byte[] accValueZ = value.GetRawData();
                            if (accValueZ != null)
                            {
                                mainform.axis_z_raw_data = (short)((accValueZ[0] << 8) + accValueZ[1]);

                                if (mainform.axis_z_raw_data != 0) mainform.idx2 = true;
                            }
                            break;

                        case 1503:
                            byte[] triggerData = value.GetRawData();
                            if (triggerData != null)
                            {
                                //Trigger Position
                                activeformG3.G3_trigger.Width = (triggerData[0]) * 241 / 255;
                                //Joystick
                                if (triggerData[1] == 223)
                                {
                                    activeformG3.G3_navi_up.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                else
                                {
                                    activeformG3.G3_navi_up.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                if (triggerData[1] == 127)
                                {
                                    activeformG3.G3_navi_down.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                else
                                {
                                    activeformG3.G3_navi_down.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                if (triggerData[1] == 213)
                                {
                                    activeformG3.G3_navi_left.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                else
                                {
                                    activeformG3.G3_navi_left.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                if (triggerData[1] == 239)
                                {
                                    activeformG3.G3_navi_right.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                else
                                {
                                    activeformG3.G3_navi_right.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                if (triggerData[1] == 191)
                                {
                                    activeformG3.G3_navi_mid.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                else
                                {
                                    activeformG3.G3_navi_mid.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                //Flags0
                                if (((triggerData[2]) & 128) == '\0')
                                {
                                    activeformG3.G3_magazine.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformG3.G3_magazine.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 64) == '\0')
                                {
                                    activeformG3.G3_auto.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformG3.G3_auto.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 32) == '\0')
                                {
                                    activeformG3.G3_semi.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformG3.G3_semi.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 16) == '\0')
                                {
                                    activeformG3.G3_safe.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformG3.G3_safe.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 8) == '\0')
                                {
                                    activeformG3.G3_hammerf.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformG3.G3_hammerf.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 4) == '\0')
                                {
                                    activeformG3.G3_hammerb.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformG3.G3_hammerb.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 2) == '\0')
                                {
                                    activeformG3.G3_boltb.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformG3.G3_boltb.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 1) == '\0')
                                {
                                    activeformG3.G3_boltf.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformG3.G3_boltf.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                //fasthall
                                if (((triggerData[3]) & 1) == '\0')
                                {
                                    activeformG3.G3_boltfs.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformG3.G3_boltfs.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                            }
                            break;

                        case 1506:
                            ulong CyclicTotalShots = 0;
                            CyclicTotalShots = value.GetAsUlong();
                            if (CyclicTotalShots != 0)
                            {
                                activeformG3.G3_shots.Text = "" + CyclicTotalShots;
                            }
                            break;
                    }

                    if ((mainform.idx1) && (mainform.idx2))
                    {
                        //angle
                        float temp1, temp2;

                        if ((mainform.axis_x_raw_data & 0x800) == 0)
                        {
                            mainform.axis_x_g_value = (float)mainform.axis_x_raw_data / 1024;
                        }
                        else
                        {
                            mainform.axis_x_g_value = (float)mainform.axis_x_raw_data / 1024;// -4;
                        }

                        if ((mainform.axis_y_raw_data & 0x800) == 0)
                        {
                            mainform.axis_y_g_value = (float)mainform.axis_y_raw_data / 1024;
                        }
                        else
                        {
                            mainform.axis_y_g_value = (float)mainform.axis_y_raw_data / 1024;// -4;
                        }

                        if ((mainform.axis_z_raw_data & 0x800) == 0)
                        {
                            mainform.axis_z_g_value = (float)mainform.axis_z_raw_data / 1024;
                        }
                        else
                        {
                            mainform.axis_z_g_value = (float)mainform.axis_z_raw_data / 1024;// -4;
                        }

                        mainform.temp_x_g_value += mainform.axis_x_g_value;
                        mainform.temp_y_g_value += mainform.axis_y_g_value;
                        mainform.temp_z_g_value += mainform.axis_z_g_value;

                        mainform.idx++;

                        if (mainform.idx < (mainform.num_of_samples - 1)) return;

                        mainform.idx = 0;

                        mainform.axis_x_g_value = mainform.temp_x_g_value / mainform.num_of_samples;
                        mainform.axis_y_g_value = mainform.temp_y_g_value / mainform.num_of_samples;
                        mainform.axis_z_g_value = mainform.temp_z_g_value / mainform.num_of_samples;

                        mainform.temp_x_g_value = 0;
                        mainform.temp_y_g_value = 0;
                        mainform.temp_z_g_value = 0;

                        if (((mainform.axis_x_g_value == 0) && (mainform.axis_z_g_value == 0)) || ((mainform.axis_y_g_value == 0) && (mainform.axis_z_g_value == 0))) return;

                        temp1 = mainform.axis_x_g_value / (float)Math.Sqrt(mainform.axis_y_g_value * mainform.axis_y_g_value + mainform.axis_z_g_value * mainform.axis_z_g_value);
                        temp2 = mainform.axis_y_g_value / (float)Math.Sqrt(mainform.axis_x_g_value * mainform.axis_x_g_value + mainform.axis_z_g_value * mainform.axis_z_g_value);

                        mainform.actual_pitch_angle = (float)Math.Atan(temp1) * 180 / (float)Math.PI;
                        mainform.actual_roll_angle = (float)Math.Atan(temp2) * 180 / (float)Math.PI;
                        activeformG3.G3_accelerhor.Value = (int)mainform.actual_roll_angle;
                        activeformG3.G3_accelerver.Value = (int)mainform.actual_pitch_angle;

                        //
                        mainform.idx1 = false;
                        mainform.idx2 = false;
                    }
                    break;
                case 146: // -------------------------------------------------------------------------------------- G36
                    G36.G36Form activeformG36 = (G36.G36Form)mainform.ActiveForm2;
                    switch (key.canId)
                    {
                        case 1500:
                            byte[] accValueXY = value.GetRawData();
                            if (accValueXY != null)
                            {
                                mainform.axis_x_raw_data = (short)((accValueXY[0] << 8) + accValueXY[1]);
                                mainform.axis_y_raw_data = (short)((accValueXY[2] << 8) + accValueXY[3]);
                                if ((mainform.axis_x_raw_data != 0) && (mainform.axis_y_raw_data != 0)) mainform.idx1 = true;
                            }
                            break;

                        case 1502:
                            byte[] accValueZ = value.GetRawData();
                            if (accValueZ != null)
                            {
                                mainform.axis_z_raw_data = (short)((accValueZ[0] << 8) + accValueZ[1]);

                                if (mainform.axis_z_raw_data != 0) mainform.idx2 = true;
                            }
                            break;

                        case 1503:
                            byte[] triggerData = value.GetRawData();
                            if (triggerData != null)
                            {
                                //Trigger Position
                                activeformG36.G36_trigger.Width = (triggerData[0]) * 241 / 255;
                                //Joystick
                                if (triggerData[1] == 223)
                                {
                                    activeformG36.G36_navi_up.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                else
                                {
                                    activeformG36.G36_navi_up.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                if (triggerData[1] == 127)
                                {
                                    activeformG36.G36_navi_down.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                else
                                {
                                    activeformG36.G36_navi_down.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                if (triggerData[1] == 213)
                                {
                                    activeformG36.G36_navi_left.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                else
                                {
                                    activeformG36.G36_navi_left.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                if (triggerData[1] == 239)
                                {
                                    activeformG36.G36_navi_right.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                else
                                {
                                    activeformG36.G36_navi_right.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                if (triggerData[1] == 191)
                                {
                                    activeformG36.G36_navi_mid.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                else
                                {
                                    activeformG36.G36_navi_mid.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                //Flags0
                                if (((triggerData[2]) & 128) == '\0')
                                {
                                    activeformG36.G36_magazine.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformG36.G36_magazine.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 64) == '\0')
                                {
                                    activeformG36.G36_auto.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformG36.G36_auto.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 32) == '\0')
                                {
                                    activeformG36.G36_semi.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformG36.G36_semi.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 16) == '\0')
                                {
                                    activeformG36.G36_safe.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformG36.G36_safe.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 8) == '\0')
                                {
                                    activeformG36.G36_hammerf.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformG36.G36_hammerf.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 4) == '\0')
                                {
                                    activeformG36.G36_hammerb.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformG36.G36_hammerb.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 2) == '\0')
                                {
                                    activeformG36.G36_boltb.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformG36.G36_boltb.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 1) == '\0')
                                {
                                    activeformG36.G36_boltf.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformG36.G36_boltf.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                //fasthall
                                if (((triggerData[3]) & 1) == '\0')
                                {
                                    activeformG36.G36_boltfs.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformG36.G36_boltfs.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                            }
                            break;

                        case 1506:
                            ulong CyclicTotalShots = 0;
                            CyclicTotalShots = value.GetAsUlong();
                            if (CyclicTotalShots != 0)
                            {
                                activeformG36.G36_shots.Text = "" + CyclicTotalShots;
                            }
                            break;
                    }

                    if ((mainform.idx1) && (mainform.idx2))
                    {
                        //angle
                        float temp1, temp2;

                        if ((mainform.axis_x_raw_data & 0x800) == 0)
                        {
                            mainform.axis_x_g_value = (float)mainform.axis_x_raw_data / 1024;
                        }
                        else
                        {
                            mainform.axis_x_g_value = (float)mainform.axis_x_raw_data / 1024;// -4;
                        }

                        if ((mainform.axis_y_raw_data & 0x800) == 0)
                        {
                            mainform.axis_y_g_value = (float)mainform.axis_y_raw_data / 1024;
                        }
                        else
                        {
                            mainform.axis_y_g_value = (float)mainform.axis_y_raw_data / 1024;// -4;
                        }

                        if ((mainform.axis_z_raw_data & 0x800) == 0)
                        {
                            mainform.axis_z_g_value = (float)mainform.axis_z_raw_data / 1024;
                        }
                        else
                        {
                            mainform.axis_z_g_value = (float)mainform.axis_z_raw_data / 1024;// -4;
                        }

                        mainform.temp_x_g_value += mainform.axis_x_g_value;
                        mainform.temp_y_g_value += mainform.axis_y_g_value;
                        mainform.temp_z_g_value += mainform.axis_z_g_value;

                        mainform.idx++;

                        if (mainform.idx < (mainform.num_of_samples - 1)) return;

                        mainform.idx = 0;

                        mainform.axis_x_g_value = mainform.temp_x_g_value / mainform.num_of_samples;
                        mainform.axis_y_g_value = mainform.temp_y_g_value / mainform.num_of_samples;
                        mainform.axis_z_g_value = mainform.temp_z_g_value / mainform.num_of_samples;

                        mainform.temp_x_g_value = 0;
                        mainform.temp_y_g_value = 0;
                        mainform.temp_z_g_value = 0;

                        if (((mainform.axis_x_g_value == 0) && (mainform.axis_z_g_value == 0)) || ((mainform.axis_y_g_value == 0) && (mainform.axis_z_g_value == 0))) return;

                        temp1 = mainform.axis_x_g_value / (float)Math.Sqrt(mainform.axis_y_g_value * mainform.axis_y_g_value + mainform.axis_z_g_value * mainform.axis_z_g_value);
                        temp2 = mainform.axis_y_g_value / (float)Math.Sqrt(mainform.axis_x_g_value * mainform.axis_x_g_value + mainform.axis_z_g_value * mainform.axis_z_g_value);

                        mainform.actual_pitch_angle = (float)Math.Atan(temp1) * 180 / (float)Math.PI;
                        mainform.actual_roll_angle = (float)Math.Atan(temp2) * 180 / (float)Math.PI;
                        activeformG36.G36_accelerhor.Value = (int)mainform.actual_roll_angle;
                        activeformG36.G36_accelerver.Value = (int)mainform.actual_pitch_angle;

                        //
                        mainform.idx1 = false;
                        mainform.idx2 = false;
                    }
                    break;
                case 141: // -------------------------------------------------------------------------------------- LRT3
                    LRT3.LRT3Form activeformLRT3 = (LRT3.LRT3Form)mainform.ActiveForm2;
                    switch (key.canId)
                    {
                        case 1500:
                            byte[] accValueXY = value.GetRawData();
                            if (accValueXY != null)
                            {
                                mainform.axis_x_raw_data = (short)((accValueXY[0] << 8) + accValueXY[1]);
                                mainform.axis_y_raw_data = (short)((accValueXY[2] << 8) + accValueXY[3]);
                                if ((mainform.axis_x_raw_data != 0) && (mainform.axis_y_raw_data != 0)) mainform.idx1 = true;
                            }
                            break;

                        case 1501:
                            byte[] accValueZ = value.GetRawData();
                            if (accValueZ != null)
                            {
                                mainform.axis_z_raw_data = (short)((accValueZ[0] << 8) + accValueZ[1]);

                                if (mainform.axis_z_raw_data != 0) mainform.idx2 = true;
                            }
                            break;

                        case 1503:
                            byte[] triggerData = value.GetRawData();
                            if (triggerData != null)
                            {
                                //Trigger Position
                                activeformLRT3.LRT3_trigger.Width = (triggerData[0]) * 241 / 255;
                                //Joystick
                                if (triggerData[1] == 223)
                                {
                                    activeformLRT3.LRT3_navi_up.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                else
                                {
                                    activeformLRT3.LRT3_navi_up.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                if (triggerData[1] == 127)
                                {
                                    activeformLRT3.LRT3_navi_down.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                else
                                {
                                    activeformLRT3.LRT3_navi_down.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                if (triggerData[1] == 213)
                                {
                                    activeformLRT3.LRT3_navi_left.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                else
                                {
                                    activeformLRT3.LRT3_navi_left.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                if (triggerData[1] == 239)
                                {
                                    activeformLRT3.LRT3_navi_right.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                else
                                {
                                    activeformLRT3.LRT3_navi_right.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                if (triggerData[1] == 191)
                                {
                                    activeformLRT3.LRT3_navi_mid.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                else
                                {
                                    activeformLRT3.LRT3_navi_mid.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                //Flags0
                                if (((triggerData[2]) & 128) == '\0')
                                {
                                    activeformLRT3.LRT3_magazine.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformLRT3.LRT3_magazine.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 64) == '\0')
                                {
                                    activeformLRT3.LRT3_boltunlock.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformLRT3.LRT3_boltunlock.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 32) == '\0')
                                {
                                    activeformLRT3.LRT3_boltlock.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformLRT3.LRT3_boltlock.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 16) == '\0')
                                {
                                    activeformLRT3.LRT3_safe.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformLRT3.LRT3_safe.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 8) == '\0')
                                {
                                    activeformLRT3.LRT3_fire.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformLRT3.LRT3_fire.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 4) == '\0')
                                {
                                    activeformLRT3.LRT3_firingpin.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformLRT3.LRT3_firingpin.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 2) == '\0')
                                {
                                    activeformLRT3.LRT3_boltb.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformLRT3.LRT3_boltb.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 1) == '\0')
                                {
                                    activeformLRT3.LRT3_boltf.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformLRT3.LRT3_boltf.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                            }
                            break;

                        case 1506:
                            ulong CyclicTotalShots = 0;
                            CyclicTotalShots = value.GetAsUlong();
                            if (CyclicTotalShots != 0)
                            {
                                activeformLRT3.LRT3_shots.Text = "" + CyclicTotalShots;
                            }
                            break;
                    }

                    if ((mainform.idx1) && (mainform.idx2))
                    {
                        //angle
                        float temp1, temp2;

                        if ((mainform.axis_x_raw_data & 0x800) == 0)
                        {
                            mainform.axis_x_g_value = (float)mainform.axis_x_raw_data / 1024;
                        }
                        else
                        {
                            mainform.axis_x_g_value = (float)mainform.axis_x_raw_data / 1024;// -4;
                        }

                        if ((mainform.axis_y_raw_data & 0x800) == 0)
                        {
                            mainform.axis_y_g_value = (float)mainform.axis_y_raw_data / 1024;
                        }
                        else
                        {
                            mainform.axis_y_g_value = (float)mainform.axis_y_raw_data / 1024;// -4;
                        }

                        if ((mainform.axis_z_raw_data & 0x800) == 0)
                        {
                            mainform.axis_z_g_value = (float)mainform.axis_z_raw_data / 1024;
                        }
                        else
                        {
                            mainform.axis_z_g_value = (float)mainform.axis_z_raw_data / 1024;// -4;
                        }

                        mainform.temp_x_g_value += mainform.axis_x_g_value;
                        mainform.temp_y_g_value += mainform.axis_y_g_value;
                        mainform.temp_z_g_value += mainform.axis_z_g_value;

                        mainform.idx++;

                        if (mainform.idx < (mainform.num_of_samples - 1)) return;

                        mainform.idx = 0;

                        mainform.axis_x_g_value = mainform.temp_x_g_value / mainform.num_of_samples;
                        mainform.axis_y_g_value = mainform.temp_y_g_value / mainform.num_of_samples;
                        mainform.axis_z_g_value = mainform.temp_z_g_value / mainform.num_of_samples;

                        mainform.temp_x_g_value = 0;
                        mainform.temp_y_g_value = 0;
                        mainform.temp_z_g_value = 0;

                        if (((mainform.axis_x_g_value == 0) && (mainform.axis_z_g_value == 0)) || ((mainform.axis_y_g_value == 0) && (mainform.axis_z_g_value == 0))) return;

                        temp1 = mainform.axis_x_g_value / (float)Math.Sqrt(mainform.axis_y_g_value * mainform.axis_y_g_value + mainform.axis_z_g_value * mainform.axis_z_g_value);
                        temp2 = mainform.axis_y_g_value / (float)Math.Sqrt(mainform.axis_x_g_value * mainform.axis_x_g_value + mainform.axis_z_g_value * mainform.axis_z_g_value);

                        mainform.actual_pitch_angle = (float)Math.Atan(temp1) * 180 / (float)Math.PI;
                        mainform.actual_roll_angle = (float)Math.Atan(temp2) * 180 / (float)Math.PI;
                        activeformLRT3.LRT3_accelerhor.Value = (int)mainform.actual_roll_angle;
                        activeformLRT3.LRT3_accelerver.Value = (int)mainform.actual_pitch_angle;

                        //
                        mainform.idx1 = false;
                        mainform.idx2 = false;
                    }
                    break;
                case 138: // -------------------------------------------------------------------------------------- M60
                    M60.M60Form activeformM60 = (M60.M60Form)mainform.ActiveForm2;
                    switch (key.canId)
                    {
                        case 1500:
                            byte[] accValueXY = value.GetRawData();
                            if (accValueXY != null)
                            {
                                mainform.axis_x_raw_data = (short)((accValueXY[0] << 8) + accValueXY[1]);
                                mainform.axis_y_raw_data = (short)((accValueXY[2] << 8) + accValueXY[3]);
                                if ((mainform.axis_x_raw_data != 0) && (mainform.axis_y_raw_data != 0)) mainform.idx1 = true;
                            }
                            break;

                        case 1501:
                            byte[] accValueZ = value.GetRawData();
                            if (accValueZ != null)
                            {
                                mainform.axis_z_raw_data = (short)((accValueZ[0] << 8) + accValueZ[1]);

                                if (mainform.axis_z_raw_data != 0) mainform.idx2 = true;
                            }
                            break;

                        case 1503:
                            byte[] triggerData = value.GetRawData();
                            if (triggerData != null)
                            {
                                //Trigger Position
                                activeformM60.M60_trigger.Width = (triggerData[0]) * 241 / 255;
                                //Joystick
                                if (triggerData[1] == 223)
                                {
                                    activeformM60.M60_navi_up.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                else
                                {
                                    activeformM60.M60_navi_up.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                if (triggerData[1] == 127)
                                {
                                    activeformM60.M60_navi_down.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                else
                                {
                                    activeformM60.M60_navi_down.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                if (triggerData[1] == 213)
                                {
                                    activeformM60.M60_navi_left.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                else
                                {
                                    activeformM60.M60_navi_left.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                if (triggerData[1] == 239)
                                {
                                    activeformM60.M60_navi_right.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                else
                                {
                                    activeformM60.M60_navi_right.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                if (triggerData[1] == 191)
                                {
                                    activeformM60.M60_navi_mid.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                else
                                {
                                    activeformM60.M60_navi_mid.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                //Flags0
                                if (((triggerData[2]) & 128) == '\0')
                                {
                                    activeformM60.M60_loaded.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformM60.M60_loaded.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 64) == '\0')
                                {
                                    activeformM60.M60_fire.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformM60.M60_fire.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 16) == '\0')
                                {
                                    activeformM60.M60_safe.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformM60.M60_safe.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 8) == '\0')
                                {
                                    activeformM60.M60_barrel.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformM60.M60_barrel.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 2) == '\0')
                                {
                                    activeformM60.M60_boltb.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformM60.M60_boltb.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 1) == '\0')
                                {
                                    activeformM60.M60_boltf.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformM60.M60_boltf.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                //fasthall
                                if (((triggerData[3]) & 128) == '\0')
                                {
                                    activeformM60.M60_handleb.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformM60.M60_handleb.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[3]) & 64) == '\0')
                                {
                                    activeformM60.M60_handlef.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformM60.M60_handlef.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[3]) & 4) == '\0')
                                {
                                    activeformM60.M60_coversensor.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformM60.M60_coversensor.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[3]) & 2) == '\0')
                                {
                                    activeformM60.M60_belt1.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformM60.M60_belt1.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[3]) & 1) == '\0')
                                {
                                    activeformM60.M60_belt0.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformM60.M60_belt0.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                            }
                            break;

                        case 1506:
                            ulong CyclicTotalShots = 0;
                            CyclicTotalShots = value.GetAsUlong();
                            if (CyclicTotalShots != 0)
                            {
                                activeformM60.M60_shots.Text = "" + CyclicTotalShots;
                            }
                            break;
                    }

                    if ((mainform.idx1) && (mainform.idx2))
                    {
                        //angle
                        float temp1, temp2;

                        if ((mainform.axis_x_raw_data & 0x800) == 0)
                        {
                            mainform.axis_x_g_value = (float)mainform.axis_x_raw_data / 1024;
                        }
                        else
                        {
                            mainform.axis_x_g_value = (float)mainform.axis_x_raw_data / 1024;// -4;
                        }

                        if ((mainform.axis_y_raw_data & 0x800) == 0)
                        {
                            mainform.axis_y_g_value = (float)mainform.axis_y_raw_data / 1024;
                        }
                        else
                        {
                            mainform.axis_y_g_value = (float)mainform.axis_y_raw_data / 1024;// -4;
                        }

                        if ((mainform.axis_z_raw_data & 0x800) == 0)
                        {
                            mainform.axis_z_g_value = (float)mainform.axis_z_raw_data / 1024;
                        }
                        else
                        {
                            mainform.axis_z_g_value = (float)mainform.axis_z_raw_data / 1024;// -4;
                        }

                        mainform.temp_x_g_value += mainform.axis_x_g_value;
                        mainform.temp_y_g_value += mainform.axis_y_g_value;
                        mainform.temp_z_g_value += mainform.axis_z_g_value;

                        mainform.idx++;

                        if (mainform.idx < (mainform.num_of_samples - 1)) return;

                        mainform.idx = 0;

                        mainform.axis_x_g_value = mainform.temp_x_g_value / mainform.num_of_samples;
                        mainform.axis_y_g_value = mainform.temp_y_g_value / mainform.num_of_samples;
                        mainform.axis_z_g_value = mainform.temp_z_g_value / mainform.num_of_samples;

                        mainform.temp_x_g_value = 0;
                        mainform.temp_y_g_value = 0;
                        mainform.temp_z_g_value = 0;

                        if (((mainform.axis_x_g_value == 0) && (mainform.axis_z_g_value == 0)) || ((mainform.axis_y_g_value == 0) && (mainform.axis_z_g_value == 0))) return;

                        temp1 = mainform.axis_x_g_value / (float)Math.Sqrt(mainform.axis_y_g_value * mainform.axis_y_g_value + mainform.axis_z_g_value * mainform.axis_z_g_value);
                        temp2 = mainform.axis_y_g_value / (float)Math.Sqrt(mainform.axis_x_g_value * mainform.axis_x_g_value + mainform.axis_z_g_value * mainform.axis_z_g_value);

                        mainform.actual_pitch_angle = (float)Math.Atan(temp1) * 180 / (float)Math.PI;
                        mainform.actual_roll_angle = (float)Math.Atan(temp2) * 180 / (float)Math.PI;
                        activeformM60.M60_accelerhor.Value = (int)mainform.actual_roll_angle;
                        activeformM60.M60_accelerver.Value = (int)mainform.actual_pitch_angle;

                        //
                        mainform.idx1 = false;
                        mainform.idx2 = false;
                    }
                    break;
                case 136: // -------------------------------------------------------------------------------------- MG3
                    MG3.MG3Form activeformMG3 = (MG3.MG3Form)mainform.ActiveForm2;
                    switch (key.canId)
                    {
                        case 1500:
                            byte[] accValueXY = value.GetRawData();
                            if (accValueXY != null)
                            {
                                mainform.axis_x_raw_data = (short)((accValueXY[0] << 8) + accValueXY[1]);
                                mainform.axis_y_raw_data = (short)((accValueXY[2] << 8) + accValueXY[3]);
                                if ((mainform.axis_x_raw_data != 0) && (mainform.axis_y_raw_data != 0)) mainform.idx1 = true;
                            }
                            break;

                        case 1501:
                            byte[] accValueZ = value.GetRawData();
                            if (accValueZ != null)
                            {
                                mainform.axis_z_raw_data = (short)((accValueZ[0] << 8) + accValueZ[1]);

                                if (mainform.axis_z_raw_data != 0) mainform.idx2 = true;
                            }
                            break;

                        case 1503:
                            byte[] triggerData = value.GetRawData();
                            if (triggerData != null)
                            {
                                //Trigger Position
                                activeformMG3.MG3_trigger.Width = (triggerData[0]) * 241 / 255;
                                //Joystick
                                if (triggerData[1] == 223)
                                {
                                    activeformMG3.MG3_navi_up.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                else
                                {
                                    activeformMG3.MG3_navi_up.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                if (triggerData[1] == 127)
                                {
                                    activeformMG3.MG3_navi_down.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                else
                                {
                                    activeformMG3.MG3_navi_down.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                if (triggerData[1] == 213)
                                {
                                    activeformMG3.MG3_navi_left.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                else
                                {
                                    activeformMG3.MG3_navi_left.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                if (triggerData[1] == 239)
                                {
                                    activeformMG3.MG3_navi_right.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                else
                                {
                                    activeformMG3.MG3_navi_right.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                if (triggerData[1] == 191)
                                {
                                    activeformMG3.MG3_navi_mid.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                else
                                {
                                    activeformMG3.MG3_navi_mid.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                //Flags0
                                if (((triggerData[2]) & 128) == '\0')
                                {
                                    activeformMG3.MG3_loaded.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformMG3.MG3_loaded.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 64) == '\0')
                                {
                                    activeformMG3.MG3_fire.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformMG3.MG3_fire.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 16) == '\0')
                                {
                                    activeformMG3.MG3_safe.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformMG3.MG3_safe.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 8) == '\0')
                                {
                                    activeformMG3.MG3_barrel.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformMG3.MG3_barrel.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 2) == '\0')
                                {
                                    activeformMG3.MG3_boltb.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformMG3.MG3_boltb.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 1) == '\0')
                                {
                                    activeformMG3.MG3_boltf.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformMG3.MG3_boltf.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                //fasthall
                                if (((triggerData[3]) & 128) == '\0')
                                {
                                    activeformMG3.MG3_handleb.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformMG3.MG3_handleb.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[3]) & 64) == '\0')
                                {
                                    activeformMG3.MG3_handlef.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformMG3.MG3_handlef.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[3]) & 32) == '\0')
                                {
                                    activeformMG3.MG3_antiaircraft.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformMG3.MG3_antiaircraft.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[3]) & 16) == '\0')
                                {
                                    activeformMG3.MG3_barrelcover.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformMG3.MG3_barrelcover.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[3]) & 4) == '\0')
                                {
                                    activeformMG3.MG3_coversensor.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformMG3.MG3_coversensor.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[3]) & 2) == '\0')
                                {
                                    activeformMG3.MG3_belt1.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformMG3.MG3_belt1.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[3]) & 1) == '\0')
                                {
                                    activeformMG3.MG3_belt0.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformMG3.MG3_belt0.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                            }
                            break;

                        case 1506:
                            ulong CyclicTotalShots = 0;
                            CyclicTotalShots = value.GetAsUlong();
                            if (CyclicTotalShots != 0)
                            {
                                activeformMG3.MG3_shots.Text = "" + CyclicTotalShots;
                            }
                            break;
                    }

                    if ((mainform.idx1) && (mainform.idx2))
                    {
                        //angle
                        float temp1, temp2;

                        if ((mainform.axis_x_raw_data & 0x800) == 0)
                        {
                            mainform.axis_x_g_value = (float)mainform.axis_x_raw_data / 1024;
                        }
                        else
                        {
                            mainform.axis_x_g_value = (float)mainform.axis_x_raw_data / 1024;// -4;
                        }

                        if ((mainform.axis_y_raw_data & 0x800) == 0)
                        {
                            mainform.axis_y_g_value = (float)mainform.axis_y_raw_data / 1024;
                        }
                        else
                        {
                            mainform.axis_y_g_value = (float)mainform.axis_y_raw_data / 1024;// -4;
                        }

                        if ((mainform.axis_z_raw_data & 0x800) == 0)
                        {
                            mainform.axis_z_g_value = (float)mainform.axis_z_raw_data / 1024;
                        }
                        else
                        {
                            mainform.axis_z_g_value = (float)mainform.axis_z_raw_data / 1024;// -4;
                        }

                        mainform.temp_x_g_value += mainform.axis_x_g_value;
                        mainform.temp_y_g_value += mainform.axis_y_g_value;
                        mainform.temp_z_g_value += mainform.axis_z_g_value;

                        mainform.idx++;

                        if (mainform.idx < (mainform.num_of_samples - 1)) return;

                        mainform.idx = 0;

                        mainform.axis_x_g_value = mainform.temp_x_g_value / mainform.num_of_samples;
                        mainform.axis_y_g_value = mainform.temp_y_g_value / mainform.num_of_samples;
                        mainform.axis_z_g_value = mainform.temp_z_g_value / mainform.num_of_samples;

                        mainform.temp_x_g_value = 0;
                        mainform.temp_y_g_value = 0;
                        mainform.temp_z_g_value = 0;

                        if (((mainform.axis_x_g_value == 0) && (mainform.axis_z_g_value == 0)) || ((mainform.axis_y_g_value == 0) && (mainform.axis_z_g_value == 0))) return;

                        temp1 = mainform.axis_x_g_value / (float)Math.Sqrt(mainform.axis_y_g_value * mainform.axis_y_g_value + mainform.axis_z_g_value * mainform.axis_z_g_value);
                        temp2 = mainform.axis_y_g_value / (float)Math.Sqrt(mainform.axis_x_g_value * mainform.axis_x_g_value + mainform.axis_z_g_value * mainform.axis_z_g_value);

                        mainform.actual_pitch_angle = (float)Math.Atan(temp1) * 180 / (float)Math.PI;
                        mainform.actual_roll_angle = (float)Math.Atan(temp2) * 180 / (float)Math.PI;
                        activeformMG3.MG3_accelerhor.Value = (int)mainform.actual_roll_angle;
                        activeformMG3.MG3_accelerver.Value = (int)mainform.actual_pitch_angle;

                        //
                        mainform.idx1 = false;
                        mainform.idx2 = false;
                    }
                    break;
                case 135: // -------------------------------------------------------------------------------------- RPG7
                    RPG7.RPG7Form activeformRPG7 = (RPG7.RPG7Form)mainform.ActiveForm2;
                    switch (key.canId)
                    {
                        case 1500:
                            byte[] accValueXY = value.GetRawData();
                            if (accValueXY != null)
                            {
                                mainform.axis_x_raw_data = (short)((accValueXY[0] << 8) + accValueXY[1]);
                                mainform.axis_y_raw_data = (short)((accValueXY[2] << 8) + accValueXY[3]);
                                if ((mainform.axis_x_raw_data != 0) && (mainform.axis_y_raw_data != 0)) mainform.idx1 = true;
                            }
                            break;

                        case 1501:
                            byte[] accValueZ = value.GetRawData();
                            if (accValueZ != null)
                            {
                                mainform.axis_z_raw_data = (short)((accValueZ[0] << 8) + accValueZ[1]);

                                if (mainform.axis_z_raw_data != 0) mainform.idx2 = true;
                            }
                            break;

                        case 1503:
                            ushort[] triggerData1 = value.GetAsUshort2();
                            if (triggerData1 != null)
                            {
                                //Trigger Position
                                activeformRPG7.RPG7_trigger.Width = (triggerData1[0]) * 241 / 255;
                            }
                            break;
                            
                        case 1505:
                            byte[] triggerData = value.GetRawData();
                            if (triggerData != null)
                            {
                                //Flags0
                                if (((triggerData[0]) & 128) == '\0')
                                {
                                    activeformRPG7.RPG7_magazine.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformRPG7.RPG7_magazine.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[0]) & 64) == '\0')
                                {
                                    activeformRPG7.RPG7_loaded.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformRPG7.RPG7_loaded.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[0]) & 32) == '\0')
                                {
                                    activeformRPG7.RPG7_single.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformRPG7.RPG7_single.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[0]) & 16) == '\0')
                                {
                                    activeformRPG7.RPG7_safe.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformRPG7.RPG7_safe.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[0]) & 8) == '\0')
                                {
                                    activeformRPG7.RPG7_boltb.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformRPG7.RPG7_boltb.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[0]) & 4) == '\0')
                                {
                                    activeformRPG7.RPG7_boltf.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformRPG7.RPG7_boltf.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[0]) & 1) == '\0')
                                {
                                    activeformRPG7.RPG7_frontsight.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformRPG7.RPG7_frontsight.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                            }
                            break;

                        case 1506:
                            ulong CyclicTotalShots = 0;
                            CyclicTotalShots = value.GetAsUlong();
                            if (CyclicTotalShots != 0)
                            {
                                activeformRPG7.RPG7_shots.Text = "" + CyclicTotalShots;
                            }
                            break;
                    }

                    if ((mainform.idx1) && (mainform.idx2))
                    {
                        //angle
                        float temp1, temp2;

                        if ((mainform.axis_x_raw_data & 0x800) == 0)
                        {
                            mainform.axis_x_g_value = (float)mainform.axis_x_raw_data / 1024;
                        }
                        else
                        {
                            mainform.axis_x_g_value = (float)mainform.axis_x_raw_data / 1024;// -4;
                        }

                        if ((mainform.axis_y_raw_data & 0x800) == 0)
                        {
                            mainform.axis_y_g_value = (float)mainform.axis_y_raw_data / 1024;
                        }
                        else
                        {
                            mainform.axis_y_g_value = (float)mainform.axis_y_raw_data / 1024;// -4;
                        }

                        if ((mainform.axis_z_raw_data & 0x800) == 0)
                        {
                            mainform.axis_z_g_value = (float)mainform.axis_z_raw_data / 1024;
                        }
                        else
                        {
                            mainform.axis_z_g_value = (float)mainform.axis_z_raw_data / 1024;// -4;
                        }

                        mainform.temp_x_g_value += mainform.axis_x_g_value;
                        mainform.temp_y_g_value += mainform.axis_y_g_value;
                        mainform.temp_z_g_value += mainform.axis_z_g_value;

                        mainform.idx++;

                        if (mainform.idx < (mainform.num_of_samples - 1)) return;

                        mainform.idx = 0;

                        mainform.axis_x_g_value = mainform.temp_x_g_value / mainform.num_of_samples;
                        mainform.axis_y_g_value = mainform.temp_y_g_value / mainform.num_of_samples;
                        mainform.axis_z_g_value = mainform.temp_z_g_value / mainform.num_of_samples;

                        mainform.temp_x_g_value = 0;
                        mainform.temp_y_g_value = 0;
                        mainform.temp_z_g_value = 0;

                        if (((mainform.axis_x_g_value == 0) && (mainform.axis_z_g_value == 0)) || ((mainform.axis_y_g_value == 0) && (mainform.axis_z_g_value == 0))) return;

                        temp1 = mainform.axis_x_g_value / (float)Math.Sqrt(mainform.axis_y_g_value * mainform.axis_y_g_value + mainform.axis_z_g_value * mainform.axis_z_g_value);
                        temp2 = mainform.axis_y_g_value / (float)Math.Sqrt(mainform.axis_x_g_value * mainform.axis_x_g_value + mainform.axis_z_g_value * mainform.axis_z_g_value);

                        mainform.actual_pitch_angle = (float)Math.Atan(temp1) * 180 / (float)Math.PI;
                        mainform.actual_roll_angle = (float)Math.Atan(temp2) * 180 / (float)Math.PI;
                        activeformRPG7.RPG7_accelerhor.Value = (int)mainform.actual_roll_angle;
                        activeformRPG7.RPG7_accelerver.Value = (int)mainform.actual_pitch_angle;

                        //
                        mainform.idx1 = false;
                        mainform.idx2 = false;
                    }
                    break;
                case 143: // -------------------------------------------------------------------------------------- TIMBER
                    TIMBER.TIMBERForm activeformTIMBER = (TIMBER.TIMBERForm)mainform.ActiveForm2;
                    switch (key.canId)
                    {
                        case 1500:
                            byte[] accValueXY = value.GetRawData();
                            if (accValueXY != null)
                            {
                                mainform.axis_x_raw_data = (short)((accValueXY[0] << 8) + accValueXY[1]);
                                mainform.axis_y_raw_data = (short)((accValueXY[2] << 8) + accValueXY[3]);
                                if ((mainform.axis_x_raw_data != 0) && (mainform.axis_y_raw_data != 0)) mainform.idx1 = true;
                            }
                            break;

                        case 1501:
                            byte[] accValueZ = value.GetRawData();
                            if (accValueZ != null)
                            {
                                mainform.axis_z_raw_data = (short)((accValueZ[0] << 8) + accValueZ[1]);

                                if (mainform.axis_z_raw_data != 0) mainform.idx2 = true;
                            }
                            break;

                        case 1503:
                            byte[] triggerData = value.GetRawData();
                            if (triggerData != null)
                            {
                                //Trigger Position
                                activeformTIMBER.TIMBER_trigger.Width = (triggerData[0]) * 241 / 255;
                                //Joystick
                                if (triggerData[1] == 223)
                                {
                                    activeformTIMBER.TIMBER_navi_up.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                else
                                {
                                    activeformTIMBER.TIMBER_navi_up.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                if (triggerData[1] == 127)
                                {
                                    activeformTIMBER.TIMBER_navi_down.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                else
                                {
                                    activeformTIMBER.TIMBER_navi_down.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                if (triggerData[1] == 213)
                                {
                                    activeformTIMBER.TIMBER_navi_left.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                else
                                {
                                    activeformTIMBER.TIMBER_navi_left.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                if (triggerData[1] == 239)
                                {
                                    activeformTIMBER.TIMBER_navi_right.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                else
                                {
                                    activeformTIMBER.TIMBER_navi_right.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                if (triggerData[1] == 191)
                                {
                                    activeformTIMBER.TIMBER_navi_mid.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                else
                                {
                                    activeformTIMBER.TIMBER_navi_mid.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                //Flags0
                                if (((triggerData[2]) & 128) == '\0')
                                {
                                    activeformTIMBER.TIMBER_magazine.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformTIMBER.TIMBER_magazine.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 64) == '\0')
                                {
                                    activeformTIMBER.TIMBER_boltunlock.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformTIMBER.TIMBER_boltunlock.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 32) == '\0')
                                {
                                    activeformTIMBER.TIMBER_boltlock.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformTIMBER.TIMBER_boltlock.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 16) == '\0')
                                {
                                    activeformTIMBER.TIMBER_safe.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformTIMBER.TIMBER_safe.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 8) == '\0')
                                {
                                    activeformTIMBER.TIMBER_fire.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformTIMBER.TIMBER_fire.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 4) == '\0')
                                {
                                    activeformTIMBER.TIMBER_firingpin.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformTIMBER.TIMBER_firingpin.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 2) == '\0')
                                {
                                    activeformTIMBER.TIMBER_boltb.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformTIMBER.TIMBER_boltb.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 1) == '\0')
                                {
                                    activeformTIMBER.TIMBER_boltf.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformTIMBER.TIMBER_boltf.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                            }
                            break;

                        case 1506:
                            ulong CyclicTotalShots = 0;
                            CyclicTotalShots = value.GetAsUlong();
                            if (CyclicTotalShots != 0)
                            {
                                activeformTIMBER.TIMBER_shots.Text = "" + CyclicTotalShots;
                            }
                            break;
                    }

                    if ((mainform.idx1) && (mainform.idx2))
                    {
                        //angle
                        float temp1, temp2;

                        if ((mainform.axis_x_raw_data & 0x800) == 0)
                        {
                            mainform.axis_x_g_value = (float)mainform.axis_x_raw_data / 1024;
                        }
                        else
                        {
                            mainform.axis_x_g_value = (float)mainform.axis_x_raw_data / 1024;// -4;
                        }

                        if ((mainform.axis_y_raw_data & 0x800) == 0)
                        {
                            mainform.axis_y_g_value = (float)mainform.axis_y_raw_data / 1024;
                        }
                        else
                        {
                            mainform.axis_y_g_value = (float)mainform.axis_y_raw_data / 1024;// -4;
                        }

                        if ((mainform.axis_z_raw_data & 0x800) == 0)
                        {
                            mainform.axis_z_g_value = (float)mainform.axis_z_raw_data / 1024;
                        }
                        else
                        {
                            mainform.axis_z_g_value = (float)mainform.axis_z_raw_data / 1024;// -4;
                        }

                        mainform.temp_x_g_value += mainform.axis_x_g_value;
                        mainform.temp_y_g_value += mainform.axis_y_g_value;
                        mainform.temp_z_g_value += mainform.axis_z_g_value;

                        mainform.idx++;

                        if (mainform.idx < (mainform.num_of_samples - 1)) return;

                        mainform.idx = 0;

                        mainform.axis_x_g_value = mainform.temp_x_g_value / mainform.num_of_samples;
                        mainform.axis_y_g_value = mainform.temp_y_g_value / mainform.num_of_samples;
                        mainform.axis_z_g_value = mainform.temp_z_g_value / mainform.num_of_samples;

                        mainform.temp_x_g_value = 0;
                        mainform.temp_y_g_value = 0;
                        mainform.temp_z_g_value = 0;

                        if (((mainform.axis_x_g_value == 0) && (mainform.axis_z_g_value == 0)) || ((mainform.axis_y_g_value == 0) && (mainform.axis_z_g_value == 0))) return;

                        temp1 = mainform.axis_x_g_value / (float)Math.Sqrt(mainform.axis_y_g_value * mainform.axis_y_g_value + mainform.axis_z_g_value * mainform.axis_z_g_value);
                        temp2 = mainform.axis_y_g_value / (float)Math.Sqrt(mainform.axis_x_g_value * mainform.axis_x_g_value + mainform.axis_z_g_value * mainform.axis_z_g_value);

                        mainform.actual_pitch_angle = (float)Math.Atan(temp1) * 180 / (float)Math.PI;
                        mainform.actual_roll_angle = (float)Math.Atan(temp2) * 180 / (float)Math.PI;
                        activeformTIMBER.TIMBER_accelerhor.Value = (int)mainform.actual_roll_angle;
                        activeformTIMBER.TIMBER_accelerver.Value = (int)mainform.actual_pitch_angle;

                        //
                        mainform.idx1 = false;
                        mainform.idx2 = false;
                    }
                    break;
                case 254: // -------------------------------------------------------------------------------------- RezervaA
                    RezervaA.RezervaAForm activeformRezervaA = (RezervaA.RezervaAForm)mainform.ActiveForm2;
                    switch (key.canId)
                    {
                        case 1500:
                            byte[] accValueXY = value.GetRawData();
                            if (accValueXY != null)
                            {
                                mainform.axis_x_raw_data = (short)((accValueXY[0] << 8) + accValueXY[1]);
                                mainform.axis_y_raw_data = (short)((accValueXY[2] << 8) + accValueXY[3]);
                                if ((mainform.axis_x_raw_data != 0) && (mainform.axis_y_raw_data != 0)) mainform.idx1 = true;
                            }
                            break;

                        case 1501:
                            byte[] accValueZ = value.GetRawData();
                            if (accValueZ != null)
                            {
                                mainform.axis_z_raw_data = (short)((accValueZ[0] << 8) + accValueZ[1]);

                                if (mainform.axis_z_raw_data != 0) mainform.idx2 = true;
                            }
                            break;

                        case 1503:
                            byte[] triggerData = value.GetRawData();
                            if (triggerData != null)
                            {
                                //Trigger Position
                                activeformRezervaA.RezervaA_trigger.Width = (triggerData[0]) * 241 / 255;
                                //Flags0
                                if (((triggerData[2]) & 128) == '\0')
                                {
                                    activeformRezervaA.RezervaA_magazine.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformRezervaA.RezervaA_magazine.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 16) == '\0')
                                {
                                    activeformRezervaA.RezervaA_fasthall.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformRezervaA.RezervaA_fasthall.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 4) == '\0')
                                {
                                    activeformRezervaA.RezervaA_hscover.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformRezervaA.RezervaA_hscover.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 2) == '\0')
                                {
                                    activeformRezervaA.RezervaA_boltb.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformRezervaA.RezervaA_boltb.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 1) == '\0')
                                {
                                    activeformRezervaA.RezervaA_boltf.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformRezervaA.RezervaA_boltf.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                            }
                            break;

                        case 1506:
                            ulong CyclicTotalShots = 0;
                            CyclicTotalShots = value.GetAsUlong();
                            if (CyclicTotalShots != 0)
                            {
                                activeformRezervaA.RezervaA_shots.Text = "" + CyclicTotalShots;
                            }
                            break;
                    }

                    if ((mainform.idx1) && (mainform.idx2))
                    {
                        //angle
                        float temp1, temp2;

                        if ((mainform.axis_x_raw_data & 0x800) == 0)
                        {
                            mainform.axis_x_g_value = (float)mainform.axis_x_raw_data / 1024;
                        }
                        else
                        {
                            mainform.axis_x_g_value = (float)mainform.axis_x_raw_data / 1024;// -4;
                        }

                        if ((mainform.axis_y_raw_data & 0x800) == 0)
                        {
                            mainform.axis_y_g_value = (float)mainform.axis_y_raw_data / 1024;
                        }
                        else
                        {
                            mainform.axis_y_g_value = (float)mainform.axis_y_raw_data / 1024;// -4;
                        }

                        if ((mainform.axis_z_raw_data & 0x800) == 0)
                        {
                            mainform.axis_z_g_value = (float)mainform.axis_z_raw_data / 1024;
                        }
                        else
                        {
                            mainform.axis_z_g_value = (float)mainform.axis_z_raw_data / 1024;// -4;
                        }

                        mainform.temp_x_g_value += mainform.axis_x_g_value;
                        mainform.temp_y_g_value += mainform.axis_y_g_value;
                        mainform.temp_z_g_value += mainform.axis_z_g_value;

                        mainform.idx++;

                        if (mainform.idx < (mainform.num_of_samples - 1)) return;

                        mainform.idx = 0;

                        mainform.axis_x_g_value = mainform.temp_x_g_value / mainform.num_of_samples;
                        mainform.axis_y_g_value = mainform.temp_y_g_value / mainform.num_of_samples;
                        mainform.axis_z_g_value = mainform.temp_z_g_value / mainform.num_of_samples;

                        mainform.temp_x_g_value = 0;
                        mainform.temp_y_g_value = 0;
                        mainform.temp_z_g_value = 0;

                        if (((mainform.axis_x_g_value == 0) && (mainform.axis_z_g_value == 0)) || ((mainform.axis_y_g_value == 0) && (mainform.axis_z_g_value == 0))) return;

                        temp1 = mainform.axis_x_g_value / (float)Math.Sqrt(mainform.axis_y_g_value * mainform.axis_y_g_value + mainform.axis_z_g_value * mainform.axis_z_g_value);
                        temp2 = mainform.axis_y_g_value / (float)Math.Sqrt(mainform.axis_x_g_value * mainform.axis_x_g_value + mainform.axis_z_g_value * mainform.axis_z_g_value);

                        mainform.actual_pitch_angle = (float)Math.Atan(temp1) * 180 / (float)Math.PI;
                        mainform.actual_roll_angle = (float)Math.Atan(temp2) * 180 / (float)Math.PI;
                        activeformRezervaA.RezervaA_accelerhor.Value = (int)mainform.actual_roll_angle;
                        activeformRezervaA.RezervaA_accelerver.Value = (int)mainform.actual_pitch_angle;

                        //
                        mainform.idx1 = false;
                        mainform.idx2 = false;
                    }

                    break;
                case 255: // -------------------------------------------------------------------------------------- RezervaB
                    RezervaB.RezervaBForm activeformRezervaB = (RezervaB.RezervaBForm)mainform.ActiveForm2;
                    switch (key.canId)
                    {
                        case 1500:
                            byte[] accValueXY = value.GetRawData();
                            if (accValueXY != null)
                            {
                                mainform.axis_x_raw_data = (short)((accValueXY[0] << 8) + accValueXY[1]);
                                mainform.axis_y_raw_data = (short)((accValueXY[2] << 8) + accValueXY[3]);
                                if ((mainform.axis_x_raw_data != 0) && (mainform.axis_y_raw_data != 0)) mainform.idx1 = true;
                            }
                            break;

                        case 1501:
                            byte[] accValueZ = value.GetRawData();
                            if (accValueZ != null)
                            {
                                mainform.axis_z_raw_data = (short)((accValueZ[0] << 8) + accValueZ[1]);

                                if (mainform.axis_z_raw_data != 0) mainform.idx2 = true;
                            }
                            break;

                        case 1503:
                            byte[] triggerData = value.GetRawData();
                            if (triggerData != null)
                            {
                                //Trigger Position
                                activeformRezervaB.RezervaB_trigger.Width = (triggerData[0]) * 241 / 255;
                                //Flags0
                                if (((triggerData[2]) & 128) == '\0')
                                {
                                    activeformRezervaB.RezervaB_magazine.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformRezervaB.RezervaB_magazine.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 16) == '\0')
                                {
                                    activeformRezervaB.RezervaB_fasthall.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformRezervaB.RezervaB_fasthall.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 4) == '\0')
                                {
                                    activeformRezervaB.RezervaB_hscover.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformRezervaB.RezervaB_hscover.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 2) == '\0')
                                {
                                    activeformRezervaB.RezervaB_boltb.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformRezervaB.RezervaB_boltb.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                                if (((triggerData[2]) & 1) == '\0')
                                {
                                    activeformRezervaB.RezervaB_boltf.ForeColor = Color.FromKnownColor(KnownColor.Silver);
                                }
                                else
                                {
                                    activeformRezervaB.RezervaB_boltf.ForeColor = Color.FromKnownColor(KnownColor.Lime);
                                }
                            }
                            break;

                        case 1506:
                            ulong CyclicTotalShots = 0;
                            CyclicTotalShots = value.GetAsUlong();
                            if (CyclicTotalShots != 0)
                            {
                                activeformRezervaB.RezervaB_shots.Text = "" + CyclicTotalShots;
                            }
                            break;
                    }

                    if ((mainform.idx1) && (mainform.idx2))
                    {
                        //angle
                        float temp1, temp2;

                        if ((mainform.axis_x_raw_data & 0x800) == 0)
                        {
                            mainform.axis_x_g_value = (float)mainform.axis_x_raw_data / 1024;
                        }
                        else
                        {
                            mainform.axis_x_g_value = (float)mainform.axis_x_raw_data / 1024;// -4;
                        }

                        if ((mainform.axis_y_raw_data & 0x800) == 0)
                        {
                            mainform.axis_y_g_value = (float)mainform.axis_y_raw_data / 1024;
                        }
                        else
                        {
                            mainform.axis_y_g_value = (float)mainform.axis_y_raw_data / 1024;// -4;
                        }

                        if ((mainform.axis_z_raw_data & 0x800) == 0)
                        {
                            mainform.axis_z_g_value = (float)mainform.axis_z_raw_data / 1024;
                        }
                        else
                        {
                            mainform.axis_z_g_value = (float)mainform.axis_z_raw_data / 1024;// -4;
                        }

                        mainform.temp_x_g_value += mainform.axis_x_g_value;
                        mainform.temp_y_g_value += mainform.axis_y_g_value;
                        mainform.temp_z_g_value += mainform.axis_z_g_value;

                        mainform.idx++;

                        if (mainform.idx < (mainform.num_of_samples - 1)) return;

                        mainform.idx = 0;

                        mainform.axis_x_g_value = mainform.temp_x_g_value / mainform.num_of_samples;
                        mainform.axis_y_g_value = mainform.temp_y_g_value / mainform.num_of_samples;
                        mainform.axis_z_g_value = mainform.temp_z_g_value / mainform.num_of_samples;

                        mainform.temp_x_g_value = 0;
                        mainform.temp_y_g_value = 0;
                        mainform.temp_z_g_value = 0;

                        if (((mainform.axis_x_g_value == 0) && (mainform.axis_z_g_value == 0)) || ((mainform.axis_y_g_value == 0) && (mainform.axis_z_g_value == 0))) return;

                        temp1 = mainform.axis_x_g_value / (float)Math.Sqrt(mainform.axis_y_g_value * mainform.axis_y_g_value + mainform.axis_z_g_value * mainform.axis_z_g_value);
                        temp2 = mainform.axis_y_g_value / (float)Math.Sqrt(mainform.axis_x_g_value * mainform.axis_x_g_value + mainform.axis_z_g_value * mainform.axis_z_g_value);

                        mainform.actual_pitch_angle = (float)Math.Atan(temp1) * 180 / (float)Math.PI;
                        mainform.actual_roll_angle = (float)Math.Atan(temp2) * 180 / (float)Math.PI;
                        activeformRezervaB.RezervaB_accelerhor.Value = (int)mainform.actual_roll_angle;
                        activeformRezervaB.RezervaB_accelerver.Value = (int)mainform.actual_pitch_angle;

                        //
                        mainform.idx1 = false;
                        mainform.idx2 = false;
                    }
                    break;

                default:
                    break;
            }
        }




    }
}


}