Results 1 to 2 of 2

Thread: C# and 0/0/4 Kit

  1. C# and 0/0/4 Kit

    I am having problems with creating the simplist of programs to control the 0/0/4. Here is my code.

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using Phidgets;
    using Phidgets.Events;
    
    namespace MyPhidgets
    {
        public partial class Form1 : Form
        {
            Manager phidgetManager = null;
            
            public Form1()
            {
                InitializeComponent();
            }
    
            private void getPhidgetList()
            {
                phidgetManager = new Manager();
                phidgetManager.Attach += new AttachEventHandler(phidgetManager_Attach);
                phidgetManager.Detach += new DetachEventHandler(phidgetManager_Detach);
                phidgetManager.Error += new ErrorEventHandler(phidgetManager_Error);
                phidgetManager.open();
                int phidgetCount = phidgetManager.Devices.Count;
               
            }
    
            void phidgetManager_Error(object sender, Phidgets.Events.ErrorEventArgs e)
            {
                MessageBox.Show("Error: " + e.Description);
            }
    
            void phidgetManager_Detach(object sender, Phidgets.Events.DetachEventArgs e)
            {
                throw new Exception("The method or operation is not implemented.");
            }
    
            void phidgetManager_Attach(object sender, Phidgets.Events.AttachEventArgs e)
            {
                
                if (e.Device.Type.ToLower() == "phidgetinterfacekit")
                {
                    //MessageBox.Show(e.Device.Name + " ");
                    int serial = e.Device.SerialNumber;
                }
                
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                getPhidgetList();
            }
        }
    }
    The problem is that if I try to use the e.Device.SerialNumber or the e.Device.Version the phidgetManager_Attach method never fires. I really don't understand why or how that could be happening. It seems to work just fine in the MSDN Christmas Light Sequencer program.

    Thanks

  2. #2
    Join Date
    Sep 2006
    Location
    Carol Stream, Illinois
    Posts
    1,695
    Images
    118
    Rep Power
    105

    Re: C# and 0/0/4 Kit

    Hi Gothar,

    Sorry to take so long to reply. I was out of town for a bit, but am back now

    It is possible that you have a defective 0/0/4, but let's troubleshoot a bit first.

    Have you set a breakpoint in your Attach event to confidently say that it (the Attach event) never fires? I got your code to work just fine... All I did was copied and pasted your code into a new C# project, and inside the Attach event, I commented out the Integer declaration line, and uncommented your MessageBox line and everything worked just fine.

    Keep in mind that if you have more than one Phidget plugged into your machine, then you will need pass the particular Phidget device's Serial Number into the .open() method.

    Also, the phidgetManager object only interacts with a Phidget at the base class level, which only has the very basic Phidget interaction tools. If you want to interact with a specific Phidget (like the 0/0/4), then you will need to instantiate an object of that particular type:


    Code:
            InterfaceKit phidgetIFK = null;
    
            public Form1()
            {
                InitializeComponent();
            }
    
            private void getPhidgetList()
            {
                phidgetIFK = new InterfaceKit();
                phidgetIFK.Attach += new AttachEventHandler(phidgetIFK_Attach);
                phidgetIFK.Detach += new DetachEventHandler(phidgetIFK_Detach);
                phidgetIFK.Error += new ErrorEventHandler(phidgetIFK_Error);
                phidgetIFK.open();
                //int phidgetCount = phidgetI.Devices.Count;
    
            }
    
            void phidgetIFK_Error(object sender, Phidgets.Events.ErrorEventArgs e)
            {
                MessageBox.Show("Error: " + e.Description);
            }
    
            void phidgetIFK_Detach(object sender, Phidgets.Events.DetachEventArgs e)
            {
                throw new Exception("The method or operation is not implemented.");
            }
    
            void phidgetIFK_Attach(object sender, Phidgets.Events.AttachEventArgs e)
            {
    
                if (e.Device.Type.ToLower() == "phidgetinterfacekit")
                {
                    MessageBox.Show(e.Device.Name + " ");
                    //int serial = e.Device.SerialNumber;
                }
    
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                getPhidgetList();
            }
    Let me know how everything goes

    �In the long history of humankind (and animal kind, too) those who learned to collaborate and improvise most effectively have prevailed�
    - Charles Darwin

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •