Example #1
0
        static void Main(string[] args)
        {
            try
            {
                //set up new textLCD object and event handlers
                TextLCD tLCD = new TextLCD();

                tLCD.Attach += new AttachEventHandler(tLCD_attach);
                tLCD.Detach += new DetachEventHandler(tLCD_detach);
                tLCD.Error += new ErrorEventHandler(tLCD_error);

                tLCD.open();

                if (!tLCD.Attached)
                {
                    Console.WriteLine("Waiting for TextLCD to be attached....");
                    tLCD.waitForAttachment();
                }

                writeLCD(0, tLCD);
                writeLCD(1, tLCD);

                Console.ReadLine();

                tLCD.close();
            }
            catch (PhidgetException e)
            {
                Console.WriteLine(e.ToString());

            }
        }
Example #2
0
        //When the application is terminating, close the Phidget.
        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            lcd.rows[0].DisplayString = "";
            lcd.rows[1].DisplayString = "";

            lcd.Attach -= new AttachEventHandler(lcd_Attach);
            lcd.Detach -= new DetachEventHandler(lcd_Detach);
            lcd.Error  -= new ErrorEventHandler(lcd_Error);

            ifk.Attach -= new AttachEventHandler(ifk_Attach);
            ifk.Detach -= new DetachEventHandler(ifk_Detach);
            ifk.Error  -= new ErrorEventHandler(ifk_Error);

            ifk.InputChange  -= new InputChangeEventHandler(ifk_InputChange);
            ifk.OutputChange -= new OutputChangeEventHandler(ifk_OutputChange);
            ifk.SensorChange -= new SensorChangeEventHandler(ifk_SensorChange);

            //run any events in the message queue - otherwise close will hang if there are any outstanding events
            Application.DoEvents();

            lcd.close();
            ifk.close();

            lcd = null;
            ifk = null;
        }
Example #3
0
        //When the application is terminating, close the Phidget.
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            lcd.Attach -= new AttachEventHandler(lcd_Attach);
            lcd.Detach -= new DetachEventHandler(lcd_Detach);
            lcd.Error  -= new ErrorEventHandler(lcd_Error);

            //run any events in the message queue - otherwise close will hang if there are any outstanding events
            Application.DoEvents();

            lcd.close();
        }
Example #4
0
        static void Main(string[] args)
        {
            try
            {
                //set up our Phidget TextLCD and hook the event handlers
                TextLCD tLCD = new TextLCD();

                tLCD.Attach += new AttachEventHandler(tLCD_Attach);
                tLCD.Detach += new DetachEventHandler(tLCD_Detach);
                tLCD.Error  += new ErrorEventHandler(tLCD_Error);

                tLCD.open();

                //We have to wait to make sure that a TextLCD is plugged in before
                //trying to communicate with it
                if (!tLCD.Attached)
                {
                    Console.WriteLine("Waiting for TextLCD to be attached....");
                    tLCD.waitForAttachment();
                }

                //prompt for the first line of input, Phidget TextLCD have two display
                //lines
                Console.WriteLine("Enter text to display on line 1:");
                string line1 = Console.ReadLine();

                //make sure a TextLCd is still attached before trying to communicate
                //with it...this is for if the TextLCd has been detached while waiting
                //for user input
                if (tLCD.Attached)
                {
                    if (line1.Length > tLCD.rows[0].MaximumLength)
                    {
                        while (line1.Length > tLCD.rows[0].MaximumLength)
                        {
                            Console.WriteLine("Entered text is too long, try again...");
                            line1 = Console.ReadLine();
                        }
                    }
                    else
                    {
                        if (tLCD.Attached)
                        {
                            tLCD.rows[0].DisplayString = line1;
                        }
                    }
                }

                //prompt for the second line of input
                Console.WriteLine("Enter text to display on line 2:");
                string line2 = Console.ReadLine();

                //make sure a TextLCd is still attached before trying to communicate
                //with it...this is for if the TextLCd has been detached while waiting
                //for user input
                if (tLCD.Attached)
                {
                    if (line2.Length > tLCD.rows[1].MaximumLength)
                    {
                        while (line2.Length > tLCD.rows[1].MaximumLength)
                        {
                            Console.WriteLine("Entered text is too long, try again...");
                            line2 = Console.ReadLine();
                        }
                    }
                    else
                    {
                        if (tLCD.Attached)
                        {
                            tLCD.rows[1].DisplayString = line2;
                        }
                    }
                }

                //Close the phidget
                tLCD.close();
                Console.WriteLine("ok");
            }
            catch (PhidgetException ex)
            {
                //output any exception data to the console
                Console.WriteLine(ex.ToString());
            }
        }
        static void Main(string[] args)
        {
            try
            {
                //set up our Phidget TextLCD and hook the event handlers
                TextLCD tLCD = new TextLCD();

                tLCD.Attach += new AttachEventHandler(tLCD_Attach);
                tLCD.Detach += new DetachEventHandler(tLCD_Detach);
                tLCD.Error += new ErrorEventHandler(tLCD_Error);

                tLCD.open();

                //We have to wait to make sure that a TextLCD is plugged in before
                //trying to communicate with it
                if(!tLCD.Attached)
                {
                    Console.WriteLine("Waiting for TextLCD to be attached....");
                    tLCD.waitForAttachment();
                }

                //prompt for the first line of input, Phidget TextLCD have two display
                //lines
                Console.WriteLine("Enter text to display on line 1:");
                string line1 = Console.ReadLine();

                //make sure a TextLCd is still attached before trying to communicate
                //with it...this is for if the TextLCd has been detached while waiting
                //for user input
                if (tLCD.Attached)
                {
                    if (line1.Length > tLCD.rows[0].MaximumLength)
                    {
                        while (line1.Length > tLCD.rows[0].MaximumLength)
                        {
                            Console.WriteLine("Entered text is too long, try again...");
                            line1 = Console.ReadLine();
                        }
                    }
                    else
                    {
                        if (tLCD.Attached)
                        {
                            tLCD.rows[0].DisplayString = line1;
                        }
                    }
                }

                //prompt for the second line of input
                Console.WriteLine("Enter text to display on line 2:");
                string line2 = Console.ReadLine();

                //make sure a TextLCd is still attached before trying to communicate
                //with it...this is for if the TextLCd has been detached while waiting
                //for user input
                if (tLCD.Attached)
                {
                    if (line2.Length > tLCD.rows[1].MaximumLength)
                    {
                        while (line2.Length > tLCD.rows[1].MaximumLength)
                        {
                            Console.WriteLine("Entered text is too long, try again...");
                            line2 = Console.ReadLine();
                        }
                    }
                    else
                    {
                        if (tLCD.Attached)
                        {
                            tLCD.rows[1].DisplayString = line2;
                        }
                    }
                }

                //Close the phidget
                tLCD.close();
                Console.WriteLine("ok");
            }
            catch (PhidgetException ex)
            {
                //output any exception data to the console
                Console.WriteLine(ex.ToString());
            }
        }