Example #1
0
        // This example takes a single SPI capable IOWarrior to control an MCP4922, an external 12bit DAC with 2 channels.
        public MainForm()
        {
            InitializeComponent();
            FormClosing += OnFormClosingEvent;

            FastIOW.OpenConnection();
            iow = (SPIDevice)FastIOW.GetIOWarriors().Where(entry => entry is SPIDevice).FirstOrDefault();

            if (iow == null)
            {
                FastIOW.CloseConnection();
                MessageBox.Show("No SPI capable IOWarrior detected!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Environment.Exit(1);
                return;
            }

            iow.SPI.Enable();

            m_TrackBar1.Maximum       = 4095;
            m_TrackBar1.ValueChanged += OnScrollEvent1;
            m_Label1.Text             = (0.0).ToString("#0.00") + " V";

            m_TrackBar2.Maximum       = 4095;
            m_TrackBar2.ValueChanged += OnScrollEvent2;
            m_Label2.Text             = (0.0).ToString("#0.00") + " V";
        }
Example #2
0
        // This programm requires an IOWarrior24. Connect a push button to pin P0.0 and press for short period of time.
        // Pulse duration will show up on console. For more accurate results is neccessary to debounce the push button.
        static void Main(string[] args)
        {
            FastIOW.OpenConnection();

            IOWarrior24 iow = (IOWarrior24)FastIOW.GetIOWarriors().Where(entry => entry is IOWarrior24).FirstOrDefault();

            if (iow == null)
            {
                FastIOW.CloseConnection();
                Console.WriteLine("No IOWarrior24 detected! Press any key to exit.");
                Console.ReadKey();
                return;
            }

            Console.WriteLine("Found an IOWarrior24!");
            Console.WriteLine("Press a push button connected to Timer_1 or press any key on keyboard to exit.");

            while (!Console.KeyAvailable)
            {
                // Read duration of button press using Timer_1 on pin P0.0, set timeout to 2 seconds.
                int time_us = iow.Timer.PulseIn(IOWarrior24.Timer_1, false, TimeSpan.FromSeconds(2));

                if (time_us != -1)
                {
                    Console.WriteLine("Pulsewidth = " + time_us + " μs");
                }
            }

            FastIOW.CloseConnection();
        }
Example #3
0
        private static void PrintInfos()
        {
            Console.WriteLine(string.Format("|{0,20}|{1,20}|{2,20}|", "Name", "Unique Identifier", "Serial Number"));

            foreach (var iow in FastIOW.GetIOWarriors())
            {
                Console.WriteLine(string.Format("|{0,20}|{1,20}|{2,20}|", iow.Name, string.Format("0x{0:X8}", iow.Id), iow.SerialNumber));
            }
        }
Example #4
0
        private void OnFormClosingEvent(Object sender, FormClosingEventArgs e)
        {
            if (iow != null)
            {
                iow.PWM.Disable();
            }

            FastIOW.CloseConnection();
        }
Example #5
0
        private void OnFormClosingEvent(Object sender, FormClosingEventArgs e)
        {
            PollingTimer?.Stop();

            foreach (IOWarrior iow in FastIOW.GetIOWarriors().Where(entry => entry is ADCDevice))
            {
                // Disable all ADC channels.
                (iow as ADCDevice).ADC.Disable();
            }

            FastIOW.CloseConnection();
        }
Example #6
0
        private void OnFormClosingEvent(Object sender, FormClosingEventArgs e)
        {
            PollingTimer?.Stop();

            if (Iow != null)
            {
                Iow.I2C.WriteBytes(BH1750_ADDRESS, BH1750_RESET);
                Iow.I2C.WriteBytes(BH1750_ADDRESS, BH1750_POWER_DOWN);
                Iow.I2C.Disable();
            }

            FastIOW.CloseConnection();
        }
Example #7
0
        // This example takes the first I2C capable IOWarrior to read out an BH1750, an external brightness sensor.
        public MainForm()
        {
            InitializeComponent();
            FormClosing += OnFormClosingEvent;

            FastIOW.OpenConnection();
            Iow = (I2CDevice)FastIOW.GetIOWarriors().Where(entry => entry is I2CDevice).FirstOrDefault();

            if (Iow == null)
            {
                FastIOW.CloseConnection();
                MessageBox.Show("No I2C capable IOWarriors detected!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Environment.Exit(1);
                return;
            }

            Iow.I2C.Enable();
            Iow.I2C.WriteBytes(BH1750_ADDRESS, BH1750_POWER_ON);
            Iow.I2C.WriteBytes(BH1750_ADDRESS, Continuously_H_ResolutionMode2);


            m_Chart.Dock = DockStyle.Fill;

            m_Chart.Series = new SeriesCollection();

            m_Chart.AxisY.Add(new Axis
            {
                Foreground = System.Windows.Media.Brushes.DodgerBlue,
                Title      = "Brightness (lx)"
            });

            m_Chart.AxisX.Add(new Axis
            {
                Foreground = System.Windows.Media.Brushes.DodgerBlue,
                Title      = "Time (sec)"
            });

            DataLine = new LineSeries()
            {
                PointGeometrySize = 15,
                Values            = new ChartValues <ObservablePoint>()
            };

            m_Chart.Series.Add(DataLine);

            PollingTimer          = new Timer();
            PollingTimer.Tick    += new EventHandler(OnTick);
            PollingTimer.Interval = 500;
            PollingTimer.Start();
        }
Example #8
0
        // This example scans I2C interface of all connected IOWarriors
        // for I2C slave devices, printing their address to console.
        static void Main(string[] args)
        {
            FastIOW.OpenConnection();

            if (!FastIOW.Connected)
            {
                FastIOW.CloseConnection();
                Console.WriteLine("No IOWarrior detected!");
                Console.ReadKey();
                return;
            }


            Console.WriteLine(string.Format("|{0,20}|{1,20}|{2,20}|{3,20}|", "Name", "Unique Identifier", "Serial Number", "I2C Address"));

            foreach (IOWarrior iow in FastIOW.GetIOWarriors().Where(entry => entry is I2CDevice))
            {
                I2CInterface i2c = (iow as I2CDevice).I2C;

                i2c.Enable();

                foreach (byte address in Enumerable.Range(0, 127))
                {
                    try
                    {
                        // Throws IOException when I2C device is not responding.
                        i2c.WriteBytes(address);

                        // This is only called when I2C device send a response.
                        Console.WriteLine(string.Format("|{0,20}|{1,20}|{2,20}|{3,20}|", iow.Name, string.Format("0x{0:X8}", iow.Id), iow.SerialNumber, string.Format("0x{0:X2}", address)));
                    }
                    catch (IOException) { }
                }

                i2c.Disable();
            }

            FastIOW.CloseConnection();

            Console.WriteLine("\nPress any key to exit.");
            Console.ReadKey();
        }
Example #9
0
        // This example will blink up LEDs with a fix frequency of 1 Hz. See above for pin definitions.
        static void Main(string[] args)
        {
            FastIOW.OpenConnection();

            if (!FastIOW.Connected)
            {
                FastIOW.CloseConnection();
                Console.WriteLine("No IOWarrior detected!");
                Console.ReadKey();
                return;
            }

            PrintInfos();

            Console.WriteLine("\nPress any key to exit.");

            IOWarrior[] iows = FastIOW.GetIOWarriors();

            // Set delay to zero to get maximum frequency
            // (e.g. 250 Hz on Win10 x64 with AMD Ryzen 5 2400G and one IOWarrior 28)
            int delay = 500; // 0;

            while (!Console.KeyAvailable)
            {
                foreach (var iow in iows)
                {
                    iow.DigitalWrite(LedDefinitions[iow.Type], iow.LOW);
                }

                Thread.Sleep(delay);

                foreach (var iow in iows)
                {
                    iow.DigitalWrite(LedDefinitions[iow.Type], iow.HIGH);
                }

                Thread.Sleep(delay);
            }

            FastIOW.CloseConnection();
        }
Example #10
0
        // This example takes a single IOWarrior56 to dimm a LED on port P6.7 alias P7.7 using a TrackBar.
        public MainForm()
        {
            InitializeComponent();
            FormClosing += OnFormClosingEvent;

            FastIOW.OpenConnection();
            iow = (IOWarrior56)FastIOW.GetIOWarriors().Where(entry => entry is IOWarrior56).FirstOrDefault();

            if (iow == null)
            {
                FastIOW.CloseConnection();
                MessageBox.Show("No IOWarrior56 detected!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Environment.Exit(1);
                return;
            }

            iow.PWM.Enable(PWMConfig.PWM_1);

            m_TrackBar.Maximum       = UInt16.MaxValue;
            m_TrackBar.ValueChanged += OnScrollEvent;
        }
Example #11
0
        private void OnTick(object sender, EventArgs e)
        {
            adcListView.Items.Clear();

            foreach (IOWarrior iow in FastIOW.GetIOWarriors().Where(entry => entry is ADCDevice))
            {
                ADCInterface adc = (iow as ADCDevice).ADC;

                for (int counter = 0; counter < adc.AnalogPins.Length; counter++)
                {
                    double ratio = (adc.AnalogRead(adc.AnalogPins[counter]) / 65535.0);
                    double vcc   = 5.0;

                    if (iow is IOWarrior28)
                    {
                        vcc = 3.3;
                    }

                    adcListView.Items.Add(new ListViewItem(new[] { iow.Name, iow.SerialNumber, "ADC_" + counter, (ratio * vcc).ToString("#0.00") + "V" }));
                }
            }
        }
Example #12
0
        // This example takes the first I2C capable IOWarrior to write chars to a liquid crystal display connected via I2C adapter (pcf8574).
        public MainForm()
        {
            InitializeComponent();
            FormClosing += OnFormClosingEvent;

            FastIOW.OpenConnection();
            iow = (I2CDevice)FastIOW.GetIOWarriors().Where(entry => entry is I2CDevice).FirstOrDefault();

            if (iow == null)
            {
                FastIOW.CloseConnection();
                MessageBox.Show("No I2C capable IOWarrior detected!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Environment.Exit(1);
                return;
            }

            iow.I2C.Enable();

            display = new LiquidCrystalI2C(iow.I2C, DisplayAddress, DisplayColumns, DisplayRows);
            display.Begin();
            display.Backlight();
            display.Clear();
        }
Example #13
0
        // This example takes all ADC capable IOWarriors and reads in all analog inputs.
        public MainForm()
        {
            InitializeComponent();
            FormClosing += OnFormClosingEvent;

            adcListView.View          = View.Details;
            adcListView.GridLines     = true;
            adcListView.FullRowSelect = true;

            adcListView.Columns.Add("Model", 140);
            adcListView.Columns.Add("Serial No", 140);
            adcListView.Columns.Add("ADC Channel", 140);
            adcListView.Columns.Add("ADC Voltage", 140);


            FastIOW.OpenConnection();

            if (FastIOW.GetIOWarriors().Where(entry => entry is ADCDevice).Count() == 0)
            {
                FastIOW.CloseConnection();
                MessageBox.Show("No ADC capable IOWarrior detected!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Environment.Exit(1);
                return;
            }

            foreach (IOWarrior iow in FastIOW.GetIOWarriors().Where(entry => entry is ADCDevice))
            {
                // Enable all ADC channels.
                (iow as ADCDevice).ADC.Enable(ADCConfig.Channel_0To7);
            }

            PollingTimer          = new Timer();
            PollingTimer.Tick    += new EventHandler(OnTick);
            PollingTimer.Interval = 300;
            PollingTimer.Start();
        }
Example #14
0
        // This example lights up buildin LED as long a pushbutton is pressed. See above for pin definitions.
        static void Main(string[] args)
        {
            FastIOW.OpenConnection();

            if (!FastIOW.Connected)
            {
                FastIOW.CloseConnection();
                Console.WriteLine("No IOWarrior detected!");
                Console.ReadKey();
                return;
            }

            PrintInfos();

            foreach (var iow in FastIOW.GetIOWarriors())
            {
                iow.PinStateChange += OnPinStateChange;
            }

            Console.WriteLine("\nPress any key to exit.");
            Console.ReadKey();

            FastIOW.CloseConnection();
        }