python-libnodave
python-libnodave copied to clipboard
How to establish MPI-connection with python-libnodave?
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
Hello, did you solve the communication between mpi and python-plc? Can you help me?
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!