Ejemplo n.º 1
0
        public static void Main()
        {
            byte Nb = 4; // Channels under test in single mode

            MCP342x can  = new MCP342x();
            PCF8574 leds = new PCF8574();

#if LCD
            ELCD162 lcd = new ELCD162("COM1");
            lcd.Init(); lcd.ClearScreen(); lcd.CursorOff();
#endif

            // One Shot Conversion
#if LCD
            lcd.PutString("One Shot Conv.");
            Thread.Sleep(2000);
#endif
            can.Mode       = MCP342x.ConversionMode.OneShot;
            can.Resolution = MCP342x.SampleRate.TwelveBits;
            can.Gain       = MCP342x.PGA_Gain.x1;
            double resolution = Resolution(can.Resolution);
            double gain       = System.Math.Pow(2, (byte)can.Gain);

            for (int i = 0; i < Nb; i++)
            {
                try
                {
                    Debug.Print("Single on channel " + (can.CHannel + 1) + " => Tension= " + can.ReadVolts().ToString("F2") +
                                "   " + "Resol: " + resolution + "-bit " + "Gain: " + gain);
                    can.CHannel = (MCP342x.Channel)(i + 1);
                }
                catch (System.IO.IOException ex)
                {
#if LCD
                    lcd.ClearScreen(); lcd.SetCursor(0, 0); lcd.PutString(ex.Message);
#else
                    Debug.Print(ex.Message);
#endif
                }
                finally
                {
                    Thread.Sleep(500);
                }
            }

            // Continuous Conversion mode
#if LCD
            lcd.ClearScreen();
            lcd.PutString("Continuous Conv.");
            Thread.Sleep(2000);
#endif
            can.Mode = MCP342x.ConversionMode.Continuous;
            byte j = 1; bool commut = true;

            while (true)
            {
                if (commut)
                {
                    try
                    {
                        leds.Write(0xF0);
                    }
                    catch (System.IO.IOException ex)
                    {
#if LCD
                        lcd.ClearScreen(); lcd.SetCursor(0, 1); lcd.PutString(ex.Message); Thread.Sleep(1000);
#else
                        Debug.Print(ex.Message);
#endif
                    }
                    finally
                    {
                        commut      = false;
                        can.CHannel = (MCP342x.Channel)(j - 1); j = 2;
                    }
                }
                else
                {
                    try
                    {
                        leds.Write(0x0F);
                    }
                    catch (System.IO.IOException ex)
                    {
#if LCD
                        lcd.ClearScreen(); lcd.SetCursor(0, 1); lcd.PutString(ex.Message); Thread.Sleep(1000);
#else
                        Debug.Print(ex.Message);
#endif
                    }
                    finally
                    {
                        commut      = true;
                        can.CHannel = (MCP342x.Channel)(j - 1); j = 1;
                    }
                }


                try
                {
#if LCD
                    lcd.ClearScreen();
                    lcd.SetCursor(0, 0); lcd.PutString("Ch" + (can.CHannel + 1) + " U=" + can.ReadVolts().ToString("F2") + "V");
#else
                    Debug.Print("Continuous on channel " + (can.CHannel + 1) + " =>Tension= " + can.ReadVolts().ToString("F2") + "   " +
                                "Resol: " + resolution + "-bit " + "Gain: " + gain);
#endif
                }
                catch (System.IO.IOException ex)
                {
#if LCD
                    lcd.ClearScreen(); lcd.SetCursor(0, 0); lcd.PutString(ex.Message);
#else
                    Debug.Print(ex.Message);
#endif
                }
                finally
                {
                    Thread.Sleep(1000);
                }
            }
        }
Ejemplo n.º 2
0
        public static void Main()
        {
            MLX90614 tempIR = new MLX90614();

#if Debug
            while (true)
            {
                try
                {
                    Debug.Print("Température Air = " + tempIR.Read_TA_AsCelcius().ToString("F1") + " °C");
                    Debug.Print("Température IR = " + tempIR.Read_Tobj_AsCelcius().ToString("F1") + " °C");
                    Debug.Print("---------------------");
                }
                catch (IOException ioEx)
                {
                    Debug.Print(ioEx.Message);
                }
                finally
                {
                    Thread.Sleep(500);
                }
            }
#else
            // Test with PCF8574 and ELCD162
            PCF8574 Leds = new PCF8574(0x38, 100);
            ELCD162 lcd  = new ELCD162("COM1"); //issue on COM2
            lcd.Init(); lcd.ClearScreen();

            while (true)
            {
                try
                {
                    Leds.Write(0xf0);
                    Thread.Sleep(200);
                    Leds.Write(0x0f);
                }
                catch (System.Exception ioEx)
                {
                    lcd.ClearScreen();
                    lcd.PutString(ioEx.Message);
                    Thread.Sleep(1000);
                }
                try
                {
                    double TA = tempIR.Read_TA_AsCelcius();
                    double TO = tempIR.Read_Tobj_AsCelcius();
                    lcd.ClearScreen();
                    lcd.PutString("TA=" + TA.ToString("F1") + "C");
                    lcd.SetCursor(0, 1);
                    lcd.PutString("TO=" + TO.ToString("F1") + "C");
                }
                catch (IOException ioEx)
                {
                    lcd.ClearScreen();
                    lcd.PutString(ioEx.Message);
                }
                finally
                {
                    Thread.Sleep(200);
                }
            }
#endif
        }