Python/C/RTW

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lskov
    New Member
    • Apr 2007
    • 14

    #1

    Python/C/RTW

    Hey

    Im in a project where i neet to execute some c functions there is generated with, matlab RTW.

    So my question is:
    Is there anybody there have experience with this?
    Or just with execute c code og exe in python including parameters?

    Thanks

    /LSkov
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    Originally posted by lskov
    Hey

    Im in a project where i neet to execute some c functions there is generated with, matlab RTW.

    So my question is:
    Is there anybody there have experience with this?
    Or just with execute c code og exe in python including parameters?

    Thanks

    /LSkov
    For version 2.4 of python you can download the ctypes library module (it's included in version 2.5). With ctypes, you can call functions in DLLs and other extention modules written in C. There may also be an interface already written; I'd have to do some searching...

    Comment

    • bartonc
      Recognized Expert Expert
      • Sep 2006
      • 6478

      #3
      Originally posted by bartonc
      For version 2.4 of python you can download the ctypes library module (it's included in version 2.5). With ctypes, you can call functions in DLLs and other extention modules written in C. There may also be an interface already written; I'd have to do some searching...
      Turned up only 1 Open Source site: http://www.realtimelinuxfoundation.o.../projects.html

      Comment

      • Peter Watkins
        New Member
        • May 2007
        • 3

        #4
        It is very possible to use RTW with Python. Here's some (untested) example code using the COM DLLs to get started.

        You'll need win32com, the RTW COM DLLs downloadable from Mathworks, and you'll need to spend a lot of time with their API reference.

        Code:
        import win32com.client as win32comclient
        
        # Create an object that we can use for calling COM functions
        RTWCOM = win32comclient.Dispatch("xpcapicom.xpcprotocol")
        
        # Initialize the RTW protocol--this is a COM function
        RTWCOM.Init()
        
        #Now connect to your target machine using TCP/IP
        ip = '192.168.0.1'
        port = '22222'
        RTWCOM.TcpIpConnect(ip, port)
        You'll need to do a lot more such as loading the application onto the target, but that's in the API reference.

        There's probably something I left out (exactly which DLLs you need where, etc.) so let me know if you get any errors.

        Peter

        Comment

        Working...