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.
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)
-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…
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
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.