<s> from ztag . transform import ZGrabTransform , ZMapTransformOutput <EOL> from ztag . transform import Transformable <EOL> from ztag import protocols , errors <EOL> class ModbusTransform ( ZGrabTransform ) : <EOL> name = "<STR_LIT>" <EOL> port = <NUM_LIT> <EOL> protocol = protocols . MODBUS <EOL> subprotocol = protocols . MODBUS . DEVICE_ID <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( ModbusTransform , self ) . __init__ ( * args , ** kwargs ) <EOL> def _transform_object ( self , obj ) : <EOL> zout = ZMapTransformOutput ( ) <EOL> wrapped = Transformable ( obj ) <EOL> modbus = wrapped [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] <EOL> if not modbus [ '<STR_LIT>' ] . resolve ( ) : <EOL> raise errors . IgnoreObject ( ) <EOL> out = dict ( ) <EOL> out [ "<STR_LIT>" ] = True <EOL> function_code = modbus [ '<STR_LIT>' ] . resolve ( ) <EOL> if function_code : <EOL> out [ '<STR_LIT>' ] = function_code <EOL> mei_response = modbus [ '<STR_LIT>' ] <EOL> if mei_response : <EOL> conformity_level = mei_response [ '<STR_LIT>' ] . resolve ( ) <EOL> objects = mei_response [ '<STR_LIT>' ] <EOL> vendor = objects [ '<STR_LIT>' ] . resolve ( ) <EOL> product_code = objects [ '<STR_LIT>' ] . resolve ( ) <EOL> revision = objects [ '<STR_LIT>' ] . resolve ( ) <EOL> vendor_url = objects [ '<STR_LIT>' ] . resolve ( ) <EOL> product_name = objects [ '<STR_LIT>' ] . resolve ( ) <EOL> model_name = objects [ '<STR_LIT>' ] . resolve ( ) <EOL> user_application_name = objects [ '<STR_LIT>' ] . resolve ( ) <EOL> if conformity_level or vendor or product_code or revision or vendor_url or product_name or model_name or user_application_name : <EOL> out [ '<STR_LIT>' ] = dict ( ) <EOL> if vendor or product_code or revision or vendor_url or product_name or model_name or user_application_name : <EOL> out [ '<STR_LIT>' ] [ '<STR_LIT>' ] = dict ( ) <EOL> if conformity_level : <EOL> out [ '<STR_LIT>' ] [ '<STR_LIT>' ] = conformity_level <EOL> if vendor : <EOL> out [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] = vendor <EOL> if product_code : <EOL> out [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] = product_code <EOL> if revision : <EOL> out [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] = revision <EOL> if vendor_url : <EOL> out [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] = vendor_url <EOL> if product_name : <EOL> out [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] = product_name <EOL> if model_name : <EOL> out [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] = model_name <EOL> if user_application_name : <EOL> out [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] = user_application_name <EOL> zout . transformed = out <EOL> return zout </s>
