Welcome, Guest
Username Password: Remember me
Messages posted to this category need to be reviewed by the moderator before it gets posted.
  • Page:
  • 1
  • 2

TOPIC: Need Python Code Example for SMIEngine

Need Python Code Example for SMIEngine 1 year, 6 months ago #1761

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)?

Re: Need Python Code Example for SMIEngine 1 year, 6 months ago #1762

  • csearcy
  • OFFLINE
  • Posts: 480
  • Karma: 23
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

Re: Need Python Code Example for SMIEngine 1 year, 6 months ago #1763

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

Re: Need Python Code Example for SMIEngine 1 year, 6 months ago #1764

  • csearcy
  • OFFLINE
  • Posts: 480
  • Karma: 23
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')

Re: Need Python Code Example for SMIEngine 1 year, 6 months ago #1765

Hey that's good stuff. I'll go ahead and download the comtypes (Python2.x) module and give it a try.

Re: Need Python Code Example for SMIEngine 1 year, 6 months ago #1766

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()
Last Edit: 1 year, 6 months ago by stephenmoore.
  • Page:
  • 1
  • 2
Moderators: hsummer, csearcy
Time to create page: 0.46 seconds