Open davrm opened 6 years ago
I used the example code "poll_example_many_with_write.py". I have modified this code to be able to communicate with my module. This is the code:
import logging import random import sys import time import threading import traceback import cpppo #cpppo.log_cfg['level'] = logging.DETAIL logging.basicConfig( **cpppo.log_cfg ) from cpppo.history import timestamp # requires 'pip install pytz' from cpppo.server.enip import poll, client, enip_format from cpppo.server.enip.ab import powerflex_750_series address = ("192.168.0.7", 44818) targets = { .5: ["Identity" , ('@4/0x64/3','UINT'), ('@4/0x65/3','UINT')], } timeout = .5 values = {} # { <parameter>: (<timer>, <value>), ... } failed = [] # [ (<timer>, <exc>), ... ] # Capture a timestamp with each event def failure( exc ): failed.append( (cpppo.timer(),str(exc)) ) def process( p, v ): values[p] = (cpppo.timer(),v) process.done = False poller = [] via = powerflex_750_series( host=address[0], port=address[1], timeout=timeout ) for cycle,params in targets.items(): poller += [ threading.Thread( target=poll.run, kwargs={ 'via': via, 'cycle': cycle, 'process': process, 'failure': failure, 'params': params, })] poller[-1].start() # Monitor the values and failed containers (updated in another Thread) try: while True: while values: par,(tmr,val) = values.popitem() print( "%s: %-32s == %r" % ( timestamp( tmr ), par, val )) while failed: tmr,exc = failed.pop( 0 ) print( "%s: %s" %( timestamp( tmr ), exc )) time.sleep( 1 ) try: param = "@4/0x64/3=(UINT)0,0,0,0,0,0,0,0,0" with via: # establish gateway, detects Exception (closing gateway) val, = via.write( via.parameter_substitution( param ), checking=True ) print( "%s: %-32s == %s" % ( timestamp(), param, val)) except Exception as exc: logging.detail( "Exception writing Parameter: %s, %s", exc, traceback.format_exc() ) failure( exc ) finally: process.done = True for p in poller: p.join()
This it is the output from the code:
2018-07-17 08:32:49.046: ('@4/0x65/3', 'UINT') == [0, 5801] 2018-07-17 08:32:49.046: ('@4/0x64/3', 'UINT') == [0, 0, 0, 0, 0, 0, 0, 0, 0] 2018-07-17 08:32:49.046: Identity == [894, 43, 59, 257, 52, -1023340580, u'Acromag XT1542-xxx'] 2018-07-17 08:32:49.102: read failed to access 1 attributes: @4/0x64/3=(UINT)0,0,0,0,0,0,0,0,0: status 8
I would like to know what I am doing wrong when writing in the attribute "@4/0x64/3" , since the readings work correctly.
I used the example code "poll_example_many_with_write.py". I have modified this code to be able to communicate with my module. This is the code:
This it is the output from the code:
I would like to know what I am doing wrong when writing in the attribute "@4/0x64/3" , since the readings work correctly.