Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7931969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:52:28+00:00 2026-06-03T20:52:28+00:00

I’m in the process of working on interfacing a haptic robot and eye tracker.

  • 0

I’m in the process of working on interfacing a haptic robot and eye tracker. So, both come with their own programming requirements, namely that the eye tracker software is based in python and is the main language in which I’m programming. Our haptic robot has an API in C, so I’ve had to write a wrapper in C, compile it as a DLL, and use ctypes in python to load the functions.

I’ve tested my DLL with MATLAB, and everything works just fine. However, something about my implementation of ctypes in my python class is not giving me the expected return value when i query the robot’s positional coordinates.

I’ll post the code here, and a clearer explanation of the problem at the bottom.

C source code for DLL wrapper:

#include <QHHeadersGLUT.h>
using namespace std;
class myHapClass{
public:
void InitOmni()
{
    DeviceSpace* Omni = new DeviceSpace; //Find a the default phantom
}
double GetCoord(int index)
{
    HDdouble hapPos[3];
    hdGetDoublev(HD_CURRENT_POSITION,hapPos);
    return hapPos[index];
}
};

extern "C" {
int index = 1;
__declspec(dllexport) myHapClass* myHap_new(){ return new myHapClass();}
__declspec(dllexport) void myHapInit(myHapClass* myHapObj){ myHapObj->InitOmni();}
__declspec(dllexport) double myHapCoord(myHapClass* myHapObj){ double nowCoord = myHapObj->GetCoord(index); return nowCoord;}
}

The theory for this code is simply to have 3 available C (not C++) calls that will be compatible with python/ctypes:

  1. myHap_new() returns a pointer to an instance of the class
  2. myHapInit initializes the haptics device
  3. myHapCoord returns a double for the current position, of the axis referenced by int Index.

The python class follows here:

import sreb
from ctypes import cdll
lib = cdll.LoadLibrary('C:\Documents and Settings\EyeLink\My Documents\Visual Studio 2010\Projects\myHapDLLSolution\Debug\myHapDLL.dll')

class CustomClassTemplate(sreb.EBObject):
def __init__(self):
    sreb.EBObject.__init__(self)
    self.pyMyHapObj = pyMyHap()
    self.coordval=2.0

def setCoordval(self,c):
    self.coordval = c
    pass

def getCoordval(self):
    return self.coordval

def initOmni(self):
    self.pyMyHapObj.pyHapInit()
    pass

def getCoord(self):
    self.coordval = self.pyMyHapObj.pyHapCoord()
    return self.coordval

class pyMyHap(object):
def __init__(self):
    self.obj = lib.myHap_new()
    self.coord = 1.0

def pyHapInit(self):
        lib.myHapInit(self.obj)

    def pyHapCoord(self):
    self.coord = lib.myHapCoord(self.obj)
    return self.coord

The theory of the python custom class is to instantiate an object (self.pyMyHapObj = pyMyHap()) of the loaded DLL class. Making a call to the function ‘initOmni’ successfully initializes the robot, however a call to ‘getCoord’ does not return the expected value. In fact, the result I get from ‘getCoord’ is 1 (and it is listed as 1, not 1.0, so I think it is returning an integer, not a double as it should).

In MATLAB, I have use the DLL library, and both the myHapInit and myHapCoord functions work, and I can initialize the robot and query the position coordinates successfully.

So what is it about my python class that is causing ctypes to not have the proper value returned from myHapCoord from my DLL?

Any help would be appreciated.
Thanks

edit: Python version 2.3, if it matters… I’m stuck to that version.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T20:52:30+00:00Added an answer on June 3, 2026 at 8:52 pm

    Return values default to int. Use something like:

    lib.myHapCoord.restype = ctypes.c_double
    

    before calling the function to interpret the return value properly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have thousands of HTML files to process using Groovy/Java and I need to
I am writing an app with both english and french support. The app requests
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.