Exemple #1
0
        private void ReadSwitched()
        {
            if (!_switcheReady)
            {
                return;
            }
            if (!_switch.Connected)
            {
                return;
            }

            // Channel 1
            labelChannel1.Text = _switch.GetSwitchName((short)enumSwitch.PowerCh1);
            labelDesc1.Text    = _switch.GetSwitchDescription((short)enumSwitch.PowerCh1);
            if (_switch.GetSwitch((short)enumSwitch.OnOffCh1))
            {
                buttonCh1OnOff.Image = global::EnvironmentPlot.Properties.Resources.On;
            }
            else
            {
                buttonCh1OnOff.Image = global::EnvironmentPlot.Properties.Resources.Off;
            }

            if (_switch.GetSwitch((short)enumSwitch.AutoCh1))
            {
                buttonAuto1.Image = global::EnvironmentPlot.Properties.Resources.On;
            }
            else
            {
                buttonAuto1.Image = global::EnvironmentPlot.Properties.Resources.Off;
            }

            numericUpDownChannel1.Value = (int)_switch.GetSwitchValue((short)enumSwitch.PowerCh1);
            _switch.SetSwitchValue((short)enumSwitch.PowerCh1, (double)numericUpDownChannel1.Value);

            // Channel 2
            labelChannel2.Text = _switch.GetSwitchName((short)enumSwitch.PowerCh2);
            labelDesc2.Text    = _switch.GetSwitchDescription((short)enumSwitch.PowerCh2);
            if (_switch.GetSwitch((short)enumSwitch.OnOffCh2))
            {
                buttonCh2OnOff.Image = global::EnvironmentPlot.Properties.Resources.On;
            }
            else
            {
                buttonCh2OnOff.Image = global::EnvironmentPlot.Properties.Resources.Off;
            }

            if (_switch.GetSwitch((short)enumSwitch.AutoCh2))
            {
                buttonAuto2.Image = global::EnvironmentPlot.Properties.Resources.On;
            }
            else
            {
                buttonAuto2.Image = global::EnvironmentPlot.Properties.Resources.Off;
            }

            numericUpDownChannel2.Value = (int)_switch.GetSwitchValue((short)enumSwitch.PowerCh2);
            _switch.SetSwitchValue((short)enumSwitch.PowerCh2, (double)numericUpDownChannel2.Value);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            // Uncomment the code that's required
#if UseChooser
            // choose the device
            string id = Switch.Choose("");
            if (string.IsNullOrEmpty(id))
            {
                return;
            }
            // create this device
            Switch device = new Switch(id);
#else
            // this can be replaced by this code, it avoids the chooser and creates the driver class directly.
            ASCOM.DriverAccess.Switch device = new ASCOM.DriverAccess.Switch("ASCOM.Simulator.Switch");
#endif
            // now run some tests, adding code to your driver so that the tests will pass.
            // these first tests are common to all drivers.
            Console.WriteLine("name " + device.Name);
            Console.WriteLine("description " + device.Description);
            Console.WriteLine("DriverInfo " + device.DriverInfo);
            Console.WriteLine("driverVersion " + device.DriverVersion);

            device.SetupDialog();

            // TODO add more code to test the driver.
            device.Connected = true;

            Console.WriteLine("Number " + device.MaxSwitch);
            for (short i = 0; i < device.MaxSwitch; i++)
            {
                Console.Write("Id {0}, Name {1}, Min {2}, max {3}, step {4}",
                              i, device.GetSwitchName(i),
                              device.MinSwitchValue(i), device.MaxSwitchValue(i),
                              device.SwitchStep(i));
                try
                {
                    if (isBoolean(device, i))
                    {
                        Console.Write(", Value {0}", device.GetSwitch(i));
                    }
                    else
                    {
                        Console.Write(", Value {0}", device.GetSwitchValue(i));
                    }
                }
                catch (ASCOM.MethodNotImplementedException)
                {
                    Console.Write(", Value unknown");
                }
                Console.WriteLine(", CanWrite {0}", device.CanWrite(i));
            }

            device.Connected = false;
            Console.WriteLine("Press Enter to finish");
            Console.ReadLine();
        }