I do not know what happened to my previous post concerning this topic. I am still looking for some code example that demonstrated how to open the IntegMotorInterface.dll in Python 3.3. I have not tried using Python 2.7 comptypes module yet.
I wrote a Python 3.3 HMI that works fine over the RS-232 port but would like to utilize the CAN interface for the HMI so that I can do code downloads/debug over RS-232.
Anybody have an example? Other versions of DLL (that are conventional DLL versus COM)?
I don't have any code examples, but you may have another option.
You can open an RS485 port on I/O ports 4 and 5 (with respect to pin13) on the 15pin D-Sub.
If opened in command mode, you can download/debug over this port also.
OCHN(RS4,1,N,9600,1,8,C) 'Open RS485 port at 9600
Thanks. I am actually using the RS-485 to talk to an ADAM-4024 module (with Andy Barret's help).
I also am talking to Kvaser directly to see what we might be able to do in Python. Though VB will work for our HMI and I am converti ng over to it, we do alot of code development in Python and it would be good to have ability to access the dll.
I do not want to re-invent the wheel but even a single frame build method to to access Smart Motor command strings (COB-ID 2501 I think) would work. However, I know very little about CAN communications.
Regards,
sm
Sorry I can't offer much more.
Here are the only notes I have on Python.
There are two ways of using COM from Python.
One is Python Win32 extension, and is popular.
The other is comtypes.
These are not Python's native library (module Python calls it).
So you must get it from source forge.
PythonWin32Extension needs IDispatch interface, but SMIEngine doesn't provide it.
So I tried comtypes.
Below is how to create an instance of SMIEnginer.SMIHost, get ISMIComm interface
and open it with 'COM1'.
>>> import comtypes.client as cc
>>> smi = cc.CreateObject('SMIEngine.SMIHost')
>>> cc.GetModule('IntegMotorInterface.dll')
>>> import comtypes.gen.INTEGMOTORINTERFACELib
>>> smiCom = smi.QueryInterface(comtypes.gen.INTEGMOTORINTERFACELib.ISMIComm)
>>> smiCom.OpenPort('COM1')
Hey that's good stuff. I'll go ahead and download the comtypes (Python2.x) module and give it a try.
It works, so far. When I get back to my lab I will test it out with our HMI
import comtypes.client as cc def main(): """ CAN communications. """ smi = cc.CreateObject('SMIEngine.SMIHost') cc.GetModule('IntegMotorInterface.dll') import comtypes.gen.INTEGMOTORINTERFACELib as commLib smiCom = smi.QueryInterface(commLib.ISMIComm) smiCom.OpenPort('can0') if __name__ == "__main__": main()
Great! Please let us know how it goes.
This works just fine with the Kvaser CAN interface...
import comtypes.client as cc def main(): """ CAN communications. """ smiHost = cc.CreateObject('SMIEngine.SMIHost') cc.GetModule('IntegMotorInterface.dll') import comtypes.gen.INTEGMOTORINTERFACELib as commLib smiCom = smiHost.QueryInterface(commLib.ISMIComm) smiCom.InitCANOpen(3) smiCom.BaudRate = 125000 smiCom.OpenPort('CANopen') findMotor = smiCom.DetectCANOpenMotors(5, 0) print('Found motors = ', findMotor) numMotor = smiCom.NoOfMotors smiCom.DefaultMotor = numMotor print('Number of motor = ', numMotor) cmd = 'RSP2' print('Sending SMI command = ' + cmd) response = smiCom.GetResponseOf(cmd) print('Motor response = ' + response) if __name__ == "__main__": main()
Thank you for your help. My Python HMI was completely re-usable with the CAN interface. This really streamlines our development.
Regards,
sm
I have tried this and it works.
I have a query to how to send the commands from python to the SMI interface. Now i am writing directly to the com port .
Yes it is really neede
I am not sure I understand your problem. Are you trying to use the serial port or the CANbus port with the Kvaser adaptrer?
It should be possible to just send animatics commands over the interface.
e.g.
""" Using comtypes to access Animatics Smart Motor library """ import comtypes.client as cc smiHost = cc.CreateObject('SMIEngine.SMIHost') cc.GetModule('IntegMotorInterface.dll') import comtypes.gen.INTEGMOTORINTERFACELib as commLib smiCom = smiHost.QueryInterface(commLib.ISMIComm) smiCom.InitCANOpen(3) smiCom.BaudRate = 125000 smiCom.OpenPort('CANopen') ## findMotor = smiCom.DetectCANOpenMotors(5, 0) ## print('Found motors = ', findMotor) ## numMotor = smiCom.NoOfMotors ## print('Motor number = ', numMotor) numMotor = 1 smiCom.DefaultMotor = numMotor command = 'RUN' response = smiCom.GetResponseOf(command)