API SM_NONE (integer value 0)

Hi Everyone,

I’m trying to use Python to create a wrapper that will interact with a Granite servo motor using the SimpleMotion V2 API. However, I when I try to open the bus using “smbus smOpenBus( const char * devicename )” I get a return of “0”. Which according to the documentation is never returned.

SM_NONE (integer value 0)

Never returned

Now I know it accesses the COM port because once I run the command, the COM port is locked to all other devices. But the return code baffles me.

Any help or insight would be appreciated.

I guess the devicename is something that could go wrong… and it is also platform dependant.

Thanks for the reply Mika. What do you mean the device name could go wrong? The device name according to the documentation is just the COM port.

    #Import Ctypes library for calling C type functions
    from ctypes import *
    import time

    #Load of smv2 dll library
    smv2 = cdll.LoadLibrary(r"C:\Users\me\Granite Source     Files\SMV2VScppExample\VScppExample\Debug\smv2.dll")

    #Com port pointer set
    comPort = c_char_p('COM12'.encode('utf-8'))

    #Call command
    busHandle = smv2.smOpenBus(comPort)

    #Print SM Status
    print(busHandle)

Documentation is at simplemotion.h header.

-devicename: formatted string that depend on device type to attempt opening. Supported formats/drivers:
--Serial port device:
---on Windows: COMn where n=port number, i.e. COM2
---on Linux: /dev/ttyN where N=port name, i.e. /dev/ttyUSB0 or /dev/ttyS0
---on macOS: /dev/tty.cuN where N=port name

… but you are on Windows, so COM12 should work. I wonder what is then causing it to return 0…

the smOpenBus shoudl return an index (from 0 to SM_MAX_BUSES) and a 0 is a valid handle, if I understand the code correctly.

Ok. I see what you’re looking at. However the documentation wiki says it should never be returned. It also doesn’t say what 0 would mean even if it is a valid handle :fearful:

I’ve also now tried the same code and USB dongle on a different machine. I know it’s not the dongle because the Granity software can connect with it.

So it seems to be something with the API.

Well the smOpenBus does not return a SM_STATUS but a handle. -1 would be an error handle.

OK! So I’ve gotten it to work. It turns out you are right Mika. 0 is a valid handle. I recompiled a different library from the git and it worked.

I think the documentation needs updating to say that 0 is valid, not “Never Returned”