Exemple #1
0
        static void Main(string[] args)
        {
            RelayManager.Init();
            Console.WriteLine("Total devices : " + RelayManager.DevicesCount().ToString());
            for (int i = 0; i < RelayManager.DevicesCount(); ++i)
            {
                RelayManager.OpenDevice(i);
                Console.WriteLine("Device number   : {0}", RelayManager.CurrentDeviceIndex());
                Console.WriteLine("Device serial   : {0}", RelayManager.RelaySerial());
                Console.WriteLine("Device channels : {0}", RelayManager.ChannelsCount());
                Console.WriteLine("--------------------------------");
            }

            Console.WriteLine("Enter 'q' for quit");

            while (true)
            {
                string s = Console.ReadLine();
                if (s == "1")
                {
                    Console.WriteLine("Opening...");
                    RelayManager.Open(0, 1);
                    Console.WriteLine("Channel 1 opened status : " + RelayManager.ChannelOpened(1));
                }
                if (s == "2")
                {
                    Console.WriteLine("Closing...");
                    RelayManager.Close(0, 1);
                    Console.WriteLine("Channel 1 opened status : " + RelayManager.ChannelOpened(1));
                }
                if (s == "3")
                {
                    Console.WriteLine("Opening...");
                    RelayManager.Open(1, 1);
                    Console.WriteLine("Channel 1 opened status : " + RelayManager.ChannelOpened(1));
                }
                if (s == "4")
                {
                    Console.WriteLine("Closing...");
                    RelayManager.Close(1, 1);
                    Console.WriteLine("Channel 1 opened status : " + RelayManager.ChannelOpened(1));
                }
                if (s == "5")
                {
                    Console.WriteLine("Inverting channel 1 on relay 0...");
                    RelayManager.Invert(0, 1);
                    Console.WriteLine("Channel 1 opened status : " + RelayManager.ChannelOpened(1));
                }
                if (s == "6")
                {
                    Console.WriteLine("Inverting channel 1 on relay 1 ...");
                    RelayManager.Invert(1, 1);
                    Console.WriteLine("Channel 1 opened status : " + RelayManager.ChannelOpened(1));
                }
                if (s == "q")
                {
                    break;
                }
            }
            RelayManager.Close();
        }
        public SetDistancePerRev()
        {
            ////////////////////////////////////
            ///Hotkeys
            ///
            ////////////////////////////////////
            //Hilfsform erschaffen um die Hotkeys zu behandeln. nicht sichtbar
            Form HKHandlerForm = new Form()
            {
                Visible = false
            };

            HK.OwnerForm      = HKHandlerForm;
            HK.HotKeyPressed += new HotKey.HotKeyPressedEventHandler(HK_HotKeyPressed);

            /*HK.AddHotKey(Keys.F1, HotKey.MODKEY.MOD_CONTROL, "Relay1Key");
            *  HK.AddHotKey(Keys.F2, HotKey.MODKEY.MOD_CONTROL, "Relay2Key");
            *  HK.AddHotKey(Keys.F3, HotKey.MODKEY.MOD_CONTROL, "Relay3Key");
            *  HK.AddHotKey(Keys.F4, HotKey.MODKEY.MOD_CONTROL, "Relay4Key");
            *  HK.AddHotKey(Keys.F5, HotKey.MODKEY.MOD_CONTROL, "Relay5Key");*/
            HK.AddHotKey(Keys.F6, HotKey.MODKEY.MOD_NONE, "Relay6Key");
            HK.AddHotKey(Keys.F7, HotKey.MODKEY.MOD_NONE, "Relay7Key");
            HK.AddHotKey(Keys.F8, HotKey.MODKEY.MOD_NONE, "Relay8Key");
            HK.AddHotKey(Keys.F9, HotKey.MODKEY.MOD_NONE, "ResetDistance");

            //////////////////////////////
            ///Relay Status
            ///
            Rectangle screensize = Screen.PrimaryScreen.WorkingArea;
            int       width      = 600;
            int       xpos       = screensize.Width - width;

            int ypos = 25;

            statusOverlay.Location = new System.Drawing.Point(xpos, ypos);
            statusOverlay.Size     = new Size(width, 38);

            InitializeComponent();

            statusOverlay.Show();


            R6.Text = Properties.Settings.Default.R_6Name;
            R7.Text = Properties.Settings.Default.R_7Name;
            R8.Text = Properties.Settings.Default.R_8Name;

            //Starts the driver
            RelayManager.Init();
            startButton.Enabled = true;
            R1.Enabled          = false; R1.BackColor = SystemColors.Control;
            R2.Enabled          = false; R2.BackColor = SystemColors.Control;
            R3.Enabled          = false; R3.BackColor = SystemColors.Control;
            R4.Enabled          = false; R4.BackColor = SystemColors.Control;
            R5.Enabled          = false; R5.BackColor = SystemColors.Control;
            R6.Enabled          = true;
            R7.Enabled          = true;
            R8.Enabled          = true;

            //Checks to see if there is a connected USB Relay board.
            if (RelayManager.DevicesCount() == 0)
            {
                Properties.Status.Default.NoRelayBrd = true;
                //MessageBox.Show("USBRelay (No Connected Devices)");
            }
            else
            {
                //Opens first USB Relay board found
                RelayManager.OpenDevice(0);

                //Reads serial number
                RSerial.Text = "USB Relay Serial: " + (RelayManager.RelaySerial().ToString());

                //Reads info on how many channels and enables the correct number of buttons.
                switch (RelayManager.ChannelsCount())
                {
                case 1:
                    R1.Enabled = true;
                    //Checks state of relay and sets colour accordingly.
                    if (RelayManager.ChannelOpened(1).ToString() == "False")
                    {
                        R1.BackColor = SystemColors.Control;
                    }
                    else
                    {
                        R1.BackColor = Color.ForestGreen;
                    }

                    break;

                case 2:
                    R1.Enabled = true;
                    R2.Enabled = true;
                    if (RelayManager.ChannelOpened(1).ToString() == "False")
                    {
                        R1.BackColor = SystemColors.Control;
                    }
                    else
                    {
                        R1.BackColor = Color.ForestGreen;
                    }
                    if (RelayManager.ChannelOpened(2).ToString() == "False")
                    {
                        R2.BackColor = SystemColors.Control;
                    }
                    else
                    {
                        R2.BackColor = Color.ForestGreen;
                    }

                    break;

                case 4:
                    R1.Enabled = true;
                    R2.Enabled = true;
                    R3.Enabled = true;
                    R4.Enabled = true;
                    if (RelayManager.ChannelOpened(1).ToString() == "False")
                    {
                        R1.BackColor = SystemColors.Control;
                    }
                    else
                    {
                        R1.BackColor = Color.ForestGreen;
                    }
                    if (RelayManager.ChannelOpened(2).ToString() == "False")
                    {
                        R2.BackColor = SystemColors.Control;
                    }
                    else
                    {
                        R2.BackColor = Color.ForestGreen;
                    }
                    if (RelayManager.ChannelOpened(3).ToString() == "False")
                    {
                        R3.BackColor = SystemColors.Control;
                    }
                    else
                    {
                        R3.BackColor = Color.ForestGreen;
                    }
                    if (RelayManager.ChannelOpened(4).ToString() == "False")
                    {
                        R4.BackColor = SystemColors.Control;
                    }
                    else
                    {
                        R4.BackColor = Color.ForestGreen;
                    }
                    break;

                case 8:
                    R1.Enabled = true;
                    R2.Enabled = true;
                    R3.Enabled = true;
                    R4.Enabled = true;
                    R5.Enabled = true;
                    R6.Enabled = true;
                    R7.Enabled = true;
                    R8.Enabled = true;
                    if (RelayManager.ChannelOpened(1).ToString() == "False")
                    {
                        R1.BackColor = SystemColors.Control;
                    }
                    else
                    {
                        R1.BackColor = Color.ForestGreen;
                    }
                    if (RelayManager.ChannelOpened(2).ToString() == "False")
                    {
                        R2.BackColor = SystemColors.Control;
                    }
                    else
                    {
                        R2.BackColor = Color.ForestGreen;
                    }
                    if (RelayManager.ChannelOpened(3).ToString() == "False")
                    {
                        R3.BackColor = SystemColors.Control;
                    }
                    else
                    {
                        R3.BackColor = Color.ForestGreen;
                    }
                    if (RelayManager.ChannelOpened(4).ToString() == "False")
                    {
                        R4.BackColor = SystemColors.Control;
                    }
                    else
                    {
                        R4.BackColor = Color.ForestGreen;
                    }
                    if (RelayManager.ChannelOpened(5).ToString() == "False")
                    {
                        R5.BackColor = SystemColors.Control;
                    }
                    else
                    {
                        R5.BackColor = Color.ForestGreen;
                    }
                    if (RelayManager.ChannelOpened(6).ToString() == "False")
                    {
                        R6.BackColor = SystemColors.Control;
                    }
                    else
                    {
                        R6.BackColor = Color.ForestGreen;
                    }
                    if (RelayManager.ChannelOpened(7).ToString() == "False")
                    {
                        R7.BackColor = SystemColors.Control;
                    }
                    else
                    {
                        R7.BackColor = Color.ForestGreen;
                    }
                    if (RelayManager.ChannelOpened(8).ToString() == "False")
                    {
                        R8.BackColor = SystemColors.Control;
                    }
                    else
                    {
                        R8.BackColor = Color.ForestGreen;
                    }
                    break;

                default:
                    MessageBox.Show("Something went wrong with detecting number of relays.");
                    break;
                }
            }

            //Fill Text Boxes and other control elements with Settings
            textBoxBrakeCirc.Value = (decimal)Properties.Settings.Default.brakeCirc;
            textBoxCdA.Text        = Properties.Settings.Default.CdA.ToString();
            textBoxStageTime.Text  = Properties.Settings.Default.preStageTime_ms.ToString();
            textBoxWeight.Text     = Properties.Settings.Default.VehicleWeight.ToString();
            if (Properties.Settings.Default.start_mode)
            {
                radioButtonModeStd.Checked = true;
            }
            else
            {
                radioButtonModeNHRA.Checked = true;
            }
            switch (Properties.Settings.Default.race_mode)
            {
            case 0:
                radioButtonRaceMode1.Checked = true;
                break;

            case 1:
                radioButtonRaceMode2.Checked = true;
                break;

            case 2:
                radioButtonRaceMode3.Checked = true;
                break;

            case 3:
                radioButtonRaceMode4.Checked = true;
                break;

            case 4:
                radioButtonRaceMode5.Checked = true;
                break;
            }
        }