Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mattbue opened this issue Oct 28, 2015 · 2 comments
Open

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

mattbue opened this issue Oct 28, 2015 · 2 comments

Comments

@mattbue
Copy link

mattbue commented Oct 28, 2015

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

@keremcelenn
Copy link

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

@mathias-ch1903
Copy link

mathias-ch1903 commented Oct 30, 2021

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants