C# Interfacing Program Using Wireless rather then USB

Supporting Visual Studio on Windows
Rasco
Phidgetsian
Posts: 7
Joined: Thu Oct 11, 2012 12:19 pm
Location: California, New Mexico
Contact:

C# Interfacing Program Using Wireless rather then USB

Postby Rasco » Thu Oct 11, 2012 12:53 pm

I am unable to interface my Phidget 1072 with my C program Wirelessly. I am able use my Phidget 1072 and my motor controller with the code when I use the USB Cable. Everything seems to work fine until I unplug the USB cable to go wireless.

My Phidget in the control panel runs wireless just fine. So my major problem is making my C program recognize my 8/8/8 and 1064.

I am a bit new the C language. I have interfaced my 1072 and Motor controller with the Flow stone programming, but I really want to use C. So this is the wall of destruction that is infront of my hours of enjoyment.

My C program has the Phidget.Net reference and the Phidget Com reference.

I am using the C example "Simple Motor Controller"

O yeah by the way I am using Visual Studio 2010 Express and my .NET is updated to 4.0.

Preemptive thanks to any responses.

Your friend,

Rasco

User avatar
burley
Human-Cyborg Relations
Posts: 441
Joined: Tue Sep 27, 2011 2:37 pm
Location: Calgary
Contact:

Re: C# Interfacing Program Using Wireless rather then USB

Postby burley » Thu Oct 11, 2012 1:22 pm

C, or C#? Those are to very different things.

Can you explain what exactly is happening? What kind of error message are you getting?
Brian Burley
403-282-7335 ext. 6003
support@phidgets.com

Rasco
Phidgetsian
Posts: 7
Joined: Thu Oct 11, 2012 12:19 pm
Location: California, New Mexico
Contact:

Re: C# Interfacing Program Using Wireless rather then USB

Postby Rasco » Thu Oct 11, 2012 1:28 pm

C#. Well I am trying to control my 8/8/8 board without a USB cable from my program.

I am unable to interface my 8/8/8 or motor controller without the USB cable connected to my computer.

Here is the program i am using. I am not what i am missing.

Code: Select all

using System;
using System.Collections.Generic;
using System.Text;
//Needed for the MotorControl class, Phidget base classes, and the PhidgetException class
using Phidgets;
//Needed for the Phidget event handling classes
using Phidgets.Events;
using System.Threading;
using Phidget21COM;
using System.Data;

namespace MotorControl_simple
{
    class Program
    {
        //Declare a MotorControl object
        static MotorControl motoControl;

        static void Main(string[] args)
        {
            try
            {
                //Initiallize the MotorControl object
                motoControl = new MotorControl();

                //Hook the basic event handlers
                motoControl.Attach += new AttachEventHandler(motoControl_Attach);
                motoControl.Detach += new DetachEventHandler(motoControl_Detach);
                motoControl.Error += new ErrorEventHandler(motoControl_Error);

                //Hook the phidget specific event handlers
                motoControl.CurrentChange += new CurrentChangeEventHandler
                                                    (motoControl_CurrentChange);
                motoControl.InputChange += new InputChangeEventHandler
                                                    (motoControl_InputChange);
                motoControl.VelocityChange += new VelocityChangeEventHandler
                                                    (motoControl_VelocityChange);

                //open the object for MotorControl device connections
                motoControl.open();

                //Wait for a MotorControl device to be attached
                Console.WriteLine("Waiting for MotorControl to be attached....");
                motoControl.waitForAttachment();

                //Set the acceleration to 100 for this example and intialize the velocity
                //to 0.00 (stopped)
                motoControl.motors[0].Acceleration = 100.00;
                motoControl.motors[0].Velocity = 0.00;

                //Prompt for user inpu to continue
                Console.WriteLine("Press any button to continue...");
                Console.Read();

                //Slowly speed the motor to full speed going one direction
                double i;
                for (i = 0.00; i < 100; i++)
                {
                    Thread.Sleep(100);
                    motoControl.motors[0].Velocity = i;
                }

                //Slowly speed down and start accelerating in the other direction
                for (i = 100; i > -100; i--)
                {
                    Thread.Sleep(100);
                    motoControl.motors[0].Velocity = i;
                }

                //Stop the motor
                motoControl.motors[0].Velocity = 0.00;

                //Prompt the user for input to terminate
                Console.WriteLine("Press any key to end...");
                Console.Read();

                //User input was read so we can terminate, close the MotorControl object
                motoControl.close();

                //Set the MotorControl object to null to get it out of memory
                motoControl = null;

                //If no exceptions were thrown by this point it is ok to terminate
                Console.WriteLine("ok");
            }
            catch (PhidgetException ex)
            {
                Console.WriteLine(ex.Description);
            }
        }

        //Attach event hanlder. Display serial number of attached MotorControl phidget
        static void motoControl_Attach(object sender, AttachEventArgs e)
        {
            Console.WriteLine("MotorControl {0} attached!",
                                    e.Device.SerialNumber.ToString());
        }

        //Detach event handler. Display serial number of detached MotorControl phidget
        static void motoControl_Detach(object sender, DetachEventArgs e)
        {
            Console.WriteLine("MotorControl {0} detached!",
                                    e.Device.SerialNumber.ToString());
        }

        //Error event handler...Display the error description to the console
        static void motoControl_Error(object sender, ErrorEventArgs e)
        {
            Console.WriteLine(e.Description);
        }

        //Current change event handler. Display the index and the new current value to
        //the console
        static void motoControl_CurrentChange(object sender, CurrentChangeEventArgs e)
        {
            Console.WriteLine("Current Index {0} Current {1}", e.Index, e.Current);
        }

        //Input change event handler. Dislay the index and new input value to console
        static void motoControl_InputChange(object sender, InputChangeEventArgs e)
        {
            Console.WriteLine("Input Index {0} Value {1}", e.Index, e.Value);
        }

        //Velocity change event handler. Display the motor index and the current
        //velocity value to the console.
        static void motoControl_VelocityChange(object sender, VelocityChangeEventArgs e)
        {
            Console.WriteLine("Index {0} Velocity {1}", e.Index, e.Velocity);
        }
    }
}



This is what i am using. I am missing something to interface my board wirelessly.

Thanks for response.
Last edited by Rasco on Thu Oct 11, 2012 2:03 pm, edited 3 times in total.

Rasco
Phidgetsian
Posts: 7
Joined: Thu Oct 11, 2012 12:19 pm
Location: California, New Mexico
Contact:

Re: C# Interfacing Program Using Wireless rather then USB

Postby Rasco » Thu Oct 11, 2012 1:29 pm

O yeah i am not getting an error code. I just do not get any communications.

I was unable to find a solution over the net. Or any kind of wireless interface example program.

Rasco
Phidgetsian
Posts: 7
Joined: Thu Oct 11, 2012 12:19 pm
Location: California, New Mexico
Contact:

Re: C# Interfacing Program Using Wireless rather then USB

Postby Rasco » Thu Oct 11, 2012 2:00 pm

This is the robot we did last year with phidget hardware. But we used Flowstone programming. This year i want to use C#.

http://www.youtube.com/watch?v=-ehcA_up ... ure=relmfu

User avatar
burley
Human-Cyborg Relations
Posts: 441
Joined: Tue Sep 27, 2011 2:37 pm
Location: Calgary
Contact:

Re: C# Interfacing Program Using Wireless rather then USB

Postby burley » Thu Oct 11, 2012 2:33 pm

The open call you are using does not use the WebService. It does not know where to look for the devices. You need to be using the version of open which requires an IP address and port number. You can then give it the IP address of the SBC that you have all of your devices connected to. Without this the program is looking for devices which are connected directly to your computer (and obviously there are none so it doesn't work).
Brian Burley
403-282-7335 ext. 6003
support@phidgets.com

Rasco
Phidgetsian
Posts: 7
Joined: Thu Oct 11, 2012 12:19 pm
Location: California, New Mexico
Contact:

Re: C# Interfacing Program Using Wireless rather then USB

Postby Rasco » Thu Oct 11, 2012 3:08 pm

motoControl.open();

That command is to open without serial number. What syntax do I have to include to be able to use IP address and Serial number of a specific piece of hardware.

Thank you sir for you response.

User avatar
burley
Human-Cyborg Relations
Posts: 441
Joined: Tue Sep 27, 2011 2:37 pm
Location: Calgary
Contact:

Re: C# Interfacing Program Using Wireless rather then USB

Postby burley » Fri Oct 12, 2012 7:33 am

Have a look at the .NET API:

http://www.phidgets.com/documentation/w ... Index.html

Specifically, the Phidget Class module. Under methods you will find open which has been overloaded and has the variant:

public void open(
int serialNumber,
string IPAddress,
int port
)
Brian Burley
403-282-7335 ext. 6003
support@phidgets.com

Rasco
Phidgetsian
Posts: 7
Joined: Thu Oct 11, 2012 12:19 pm
Location: California, New Mexico
Contact:

Re: C# Interfacing Program Using Wireless rather then USB

Postby Rasco » Mon Oct 15, 2012 8:52 am

Thank you sir,

I will try that again.

Rasco
Phidgetsian
Posts: 7
Joined: Thu Oct 11, 2012 12:19 pm
Location: California, New Mexico
Contact:

Re: C# Interfacing Program Using Wireless rather then USB

Postby Rasco » Mon Oct 15, 2012 11:56 am

WOOT,

Its alive.

Thank you for sending me that reference. I do not know how I overlooked it.


Return to “C#.NET”

Who is online

Users browsing this forum: No registered users and 6 guests