Skip to content

How to establish MPI-connection with python-libnodave? #1

Open

Description

@mattbue

Hi, i need to know how to establish a MPI-connection (USB-MPI-Adapter) to my PLC in python.
Can someone provice me some demo code?

In the web i can only find how to establish TCP-connections.

Thanks

Activity

  1. keremcelenn commented on May 20, 2021

    @keremcelenn

    Hello, did you solve the communication between mpi and python-plc? Can you help me?

  2. mathias-ch1903 commented on Oct 30, 2021

    @mathias-ch1903

    Hi
    After long debugging sessions and tests direct with the libnodave I found the following working (only with Python 3, python 2.7 is always seg-faulting) solution:

    -- snipp --
    import libnodave

    link = libnodave.libnodave()

    def main():

    localMPI = 0
    plcMPI = 2 #anpassen, je nach CPU Adresse
    plcRack = 0
    plcSlot = 0
    
    #link.SetDebug(99)
    print('01')
    link.set_port(b'/dev/ttyUSB0', b'38400', b'o')
    
    print('02')       
    link.new_interface(b'IF1', localMPI, libnodave.daveProtoMPI2, libnodave.daveSpeed187k)
    
    print('03')
    link.set_timeout(5000000)
    
    print('04')
    link.init_adapter()   
    
    print('05')
    link.connect_plc(plcMPI, plcRack, plcSlot)   
    
    print('06')   
    print('M200.0 Immer EIN', link.get_marker(200,0))   
    link.disconnect()
    

    if name == 'main':
    main()
    -- snapp --

    Adapter is a Siemens RS232/MPI Adapter (via FTDI USB/RS232) connected to a S7-315DP CPU
    You have to convert the python-libnodave to python3 by using "2to3" and apply the change:
    self.buffer = ctypes.create_string_buffer(b'buffer')

    self.buffer = ctypes.create_string_buffer('buffer')

    Hopt it helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions