Page 1 of 3 123 LastLast
Results 1 to 10 of 23

Thread: One problem after another!

  1. #1

    One problem after another!

    I've been trying to get a simple program going to control a servo motor I have, but have had issues with the first 2 steps. Granted the first one was due to ignorance, and this 2nd one is probably the same thing. Anyway, I've written this code:
    Code:
    #include <stdio.h>
    #include <phidget21.h>
    
    int main (int argc, char* argv[])
    {
      int result;
      int numServos;
      CPhidgetServoHandle Servo = 0;
    
      // Open any PhidgetServo non-exclisively
      if ( CPhidgetServo_create (&Servo) )
        {
          printf ("Unable to find a PhidgetServo.\n");
          return 1;
        }
    
      // Verify the number of servos
      CPhidgetServo_getNumMotors (Servo, &numServos);
      printf ("%i Servos.\n", numServos);
    
      // Set position of servo 0 to 90 degrees
      if ( CPhidgetServo_setMotorPosition (Servo, 0, 90.0) )
        {
          printf ("Unable to set motor position.\n");
          return 1;
        }
    
      CPhidget_close (Servo);
      CPhidget_delete (Servo);
      return 0;
    }
    And get this output:
    Code:
    0 Servos.
    Unable to set motor position.
    This is on a 1001 PhidgetServo version 3.0 controller with the libphidget21 library. Whenever I plug the controller into the USB port it's recognized and loads the appropriate driver, "phidgetservo".

    If you didn't catch my first post this is on a Linux computer with GCC 4.1.2 and kernel version 2.6.18.

    Thanks

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

    Re: One problem after another!

    Forgive my ignorance, but is this C or C++?

    I am not all that familiar with whatever version of C you are using, but the first thing that comes to mind given my experience using Phidgets in other languages is that it doesn't look like you are calling the open method on the servo. Have you looked through the C API Manual?

    http://www.phidgets.com/documentatio..._Phidget21.pdf

    Your printf call,

    printf ("%i Servos.\n", numServos);
    is returning "0 Servos", so that tells me that the servo controller was never opened and recognized within the programming environment.

    This is from page 4 on the C API Manual:

    CPhidget_open (CPhidgetHandle, int SerialNumber);
    Attempts to locate a Phidget matching your requirements on the local computer.
    The CPhidgetHandle should be a valid handle previously allocated by CPhidget(device)_create. Before
    calling CPhidget_open, we recommend registering the event handlers your application will use.
    SerialNumber specifies the desired serial number, allowing the call to open a specific Phidget.
    Specifying -1 for the serial number will cause it to open the first available device.
    Open is pervasive. What this means is that you can call open on a device before it is plugged in, and
    keep the device opened across device dis- and re-connections.
    Open is Asynchronous. What this means is that open will return immediately – before the device being
    opened is actually available. What this means is that you need to either poll CPhidget_getDeviceStatus
    for an attached status, or handle the attach event, in order to wait for the device to become available
    before trying to use it.

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

  3. #3

    Re: One problem after another!

    Quote Originally Posted by Alex View Post
    I am not all that familiar with whatever version of C you are using, but the first thing that comes to mind given my experience using Phidgets in other languages is that it doesn't look like you are calling the open method on the servo. Have you looked through the C API Manual?
    It's regular C!

    Yes I did, and I actually realized I wasn't using the _open command. Once I saw that I inserted the _open function into the program but whenever I try to run it I get a series of errors:
    Code:
    PHIDGET21: unable to open active device in findactivedevices: 1
    I then reverted to the example in page 3 of the C_API_Manual, with the same results. It never seems to be able to open the device.

    I think I e-mailed you about this as I didn't think I was going to get any response here, is your e-mail [email protected]?

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

    Re: One problem after another!

    Thanks, I was wondering I know a little C++, and I know that C++ syntax varies slightly between versions, but that didn't look like any C++ I've seen. I'm hoping to learn the basics of C someday soon because I have some ideas for some of our products that I think will be of great interest to others.

    Anyways, could you paste your newest code so I can better diagnose what's going on?


    I think I e-mailed you about this as I didn't think I was going to get any response here, is your e-mail [email protected]?
    I still get those emails, but my actual address is listed in our contacts page:

    [email protected]

    Sometimes questions can't get answered right away, and patience is always greatly appreciated

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

  5. #5

    Re: One problem after another!

    The code is pretty much exactly what on page 3 of the API manual, only modified for the Servo controller:
    Code:
    #include <phidget21.h>
     
    
    int main() { CPhidgetServoHandle phidgetServo; CPhidgetServo_create (&phidgetServo); CPhidget_open (phidgetServo, -1); CPhidget_waitForAttachment ((CPhidgetHandle)phidgetServo, 0); CPhidget_close ((CPhidgetHandle)phidgetServo); CPhidget_delete ((CPhidgetHandle)phidgetServo);
    }

    And it outputs that error 4 or 5 times a second until I stop the process with [ctrl]+C! If I change the timeout of _waitForAttachment it'll just end the program after that amount of seconds, that is, it wasn't able to find anything attached.

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

    Re: One problem after another!

    Do you happen to have a Windows machine that you could test the Servo controller out on, just to make sure that the board itself isn't faulty?

    Download and run the Phidget.msi onto a Windows machine (preferably XP if you can) and this will install all your library files. In "C:\Program Files\Phidgets" run Phidget21Manager.exe. You'll see an icon pop up in your system tray. Double click on it, and in the General tab under Locally Attached Devices, when you plug and unplug the servo controller, you should see it displayed here. When you plug in a device, give it a minute or two so that it can register in the system.

    If you do see it displayed, cool. One down, one to go Next, we want to be sure that the USB data transfer is ok. On the same Windows machine, download the attached file, rename the extension to .exe and with your Servo Controller attached and the servo plugged into port #0 (or with a power supply connected then the servo can be attached to any port) run the EXE. Do you see the message "PhidgetServo Attached"? If so, move the slider around. Does the servo move?

    Let me know how all this goes.


    Sorry, I wish I could explain how to do all this on a Linux box, but I don't know Linux at all.
    Last edited by Alex; 02-01-2007 at 07:21 PM. Reason: Forgot to upload file:(

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

  7. #7

    Re: One problem after another!

    Quote Originally Posted by Alex View Post
    Do you happen to have a Windows machine that you could test the Servo controller out on, just to make sure that the board itself isn't faulty?

    Download and run the Phidget.msi onto a Windows machine (preferably XP if you can) and this will install all your library files. In "C:\Program Files\Phidgets" run Phidget21Manager.exe. You'll see an icon pop up in your system tray. Double click on it, and in the General tab under Locally Attached Devices, when you plug and unplug the servo controller, you should see it displayed here. When you plug in a device, give it a minute or two so that it can register in the system.
    I do Windows installed, I just don't have a C compiler for it that's why I've been programming in Linux. I'm at work right now, so I'll have to do this when I get home later today.

    If you do see it displayed, cool. One down, one to go Next, we want to be sure that the USB data transfer is ok. On the same Windows machine, download the attached file, rename the extension to .exe and with your Servo Controller attached and the servo plugged into port #0 (or with a power supply connected then the servo can be attached to any port) run the EXE. Do you see the message "PhidgetServo Attached"? If so, move the slider around. Does the servo move?
    Which attachment are you talking about? I don't see anything attached to this post, where can I find the file?

    Sorry, I wish I could explain how to do all this on a Linux box, but I don't know Linux at all.
    That's fine, not a lot of people do. I use it on a daily basis so it's Windows that's strange to me, not to mention the issue with not having a compiler.

  8. #8

    Re: One problem after another!

    Well, since I didn't know what file you were talking about so I rename Phidget21.msi to Phidget21.exe, but it complains:
    Code:
    Program too big to fit in memory
    So anyway, this is where I stand! The test with Phidget21Manager worked, I see the PhidgetServo listed.

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

    Re: One problem after another!

    Sorry about that. I just uploaded it now, check out my previous post. However, don't rename the file, just download, extract, then run it with your servo motor controller connected to your Windows machine, with a power supply connected.

    You do need to run the Phidget21.msi on a Windows machine as itself, without renaming it. This will install all the necessary library files for Phidgets to be understood in a Windows machine. In my post above, I've added a hyperlink to that download, but here's the direct link:

    http://www.phidgets.com/modules.php?...q=getit&lid=27


    On a side note, you don't have to worry about a compiler or anything to run this exe. The exe that I sent you is a fully compiled executable VB 6 file, which doesn't need anything other than the Phidget.msi installed.

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

  10. #10

    Re: One problem after another!

    Yeah, I got the Phidget21.msi software installed, no problems! The servo-slider program gives the following error:
    Code:
    Component 'MSCOMCTL.OCX' or one of its dependencies not correctly registered: a file is missing or invalid
    I'm assuming you created this file using Visual Studios (I can see that from the icon) I wonder if it needs VS installed in order to run it.

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
  •