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

  • SEARCH
  • Home
  • 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 9158521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:16:00+00:00 2026-06-17T13:16:00+00:00

Foreword: I’m pretty familiar with Python but had never touched C until a week

  • 0

Foreword: I’m pretty familiar with Python but had never touched C until a week ago… now I’m trying to speak to a motor controller using ctypes.

So i’ve been playing around with this particular function (VCS_GetProtocolStackSettings), and was unable to get it to work until just recently. My problem is that, although it’s returning a ‘1’ (ie is sucessful per the spec below), I seem unable to access the return parameters.

Here is the my code. You can see that I am storing the return parameters in pointers to uint32 objects, I just have no idea how to get at them.

lib=ctypes.WinDLL('C:\\Program Files (x86)\\maxon motor ag\\EPOS Positioning Controller\\EPOS2\\04 Programming\\Windows DLL\\EposCmd64.dll')

typeDict={  'char': ctypes.c_char,
        'char*': ctypes.c_char_p,
        '__int8': ctypes.c_int8,
        'BYTE': ctypes.c_uint8,
        'short': ctypes.c_int16,
        'WORD': ctypes.c_uint16,
        'long': ctypes.c_int32,
        'DWORD': ctypes.c_uint32,
        'BOOL': ctypes.c_int32,
        'HANDLE': ctypes.POINTER(ctypes.c_uint32)
        }

def VCS_GetProtocolStackSettings(KeyHandle):
    '''Returns the communication parameters 'baudrate and 
        'timeout'
    '''

    func=lib['VCS_GetProtocolStackSettings']
    func.argtypes
    func.restype=typeDict['BOOL']   

    pBaudrate=ctypes.pointer(typeDict['DWORD']())
    pTimeout=ctypes.pointer(typeDict['DWORD']())
    pErrorCode=ctypes.pointer(typeDict['DWORD']())

    cKeyHandle=typeDict['HANDLE'](KeyHandle)

    return func(KeyHandle,pBaudrate,pTimeout,pErrorCode)

enter image description here

  • 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-17T13:16:01+00:00Added an answer on June 17, 2026 at 1:16 pm

    pBaudrate.contents.value will access the value in the pointer, but you only really need a c_uint() and pass it by reference to the function. Below is an example. It is also an example of making a function more “Pythonic” by throwing an exception on failure.

    import ctypes
    from ctypes import wintypes
    
    lib = ctypes.WinDLL(dllnamehere)
    lib.VCS_GetProtocolStackSettings.argtypes = [wintypes.HANDLE,wintypes.PDWORD,wintypes.PDWORD,wintypes.PDWORD]
    lib.VCS_GetProtocolStackSettings.restype = wintypes.BOOL
    
    def VCS_GetProtocolStackSettings(KeyHandle):
        baudrate = wintypes.DWORD()
        timeout = wintypes.DWORD()
        errorcode = wintypes.DWORD()
        result = lib.VCS_GetProtocolStackSettings(KeyHandle,ctypes.byref(baudrate),ctypes.byref(timeout),ctypes.byref(errorcode))
        if not result:
            raise RuntimeError('error code = {}'.format(errorcode.value))
        return baudrate.value,timeout.value
    

    P.S. Double check that WinDLL is appropriate. Windows system DLLs use the __stdcall calling convention, but many DLLs use __cdecl calling convention and you would use CDLL instead.

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

Sidebar

Related Questions

Edit: Updated code. Now works well enough. Foreword. I am an OpenGL newb tasked
Foreword: I am not trying to write an alternative either to Subversion or to
Foreword: I am trying to describe the scenario very precisely here. The TL;DR version
Foreword: Okay I've used APIs in the past such as TwitterAPI but I always
Current demo here: http://www.studioimbrue.com/sites/eliotdudik I have the tabs system working wonderfully. I'm trying to
I am new to Android and trying to setup Android Development Environment. I have
foreword: I have a component, lets call it IView. This component is implemented by
Foreword: Although I don't think it's exactly a duplicate, feel free to close if
I'm trying to use internal references to link an index atop my wiki page
I'm using MOQ with tdd, i'm comfortable with the simple mock objects. Now moving

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.