@@ -115,7 +115,7 @@ const PORT = {
115115 appendFields ( this . appendDummyInput ( ) , PORT_TYPE_EXPANSION_HUB_SERVO_PORT , iField ++ ) ;
116116 break ;
117117 default :
118- throw new Error ( 'Unexpected portType: ' + state . portType )
118+ throw new Error ( 'Unexpected portType: ' + state . portType ) ;
119119 }
120120 this . mrcPortType = state . portType ;
121121 this . mrcPortCount = iField ;
@@ -129,17 +129,20 @@ export const setup = function () {
129129export const pythonFromBlock = function (
130130 block : PortBlock ,
131131 generator : ExtendedPythonGenerator ) {
132- generator . addImport ( 'port' ) ;
133-
132+
134133 const ports : string [ ] = [ ] ;
135134 for ( let i = 0 ; i < block . mrcPortCount ; i ++ ) {
136135 ports . push ( block . getFieldValue ( FIELD_PREFIX_PORT_NUM + i ) ) ;
137136 }
138137
139- let code = 'port.' ;
138+ const portType = generator . importModuleName ( 'port' , 'PortType' ) ;
139+ const simplePort = generator . importModuleName ( 'port' , 'SimplePort' ) ;
140+ const compoundPort = ( ports . length === 2 ) ? generator . importModuleName ( 'port' , 'CompoundPort' ) : '' ;
141+
142+ let code = '' ;
140143
141144 if ( ports . length === 1 ) {
142- code += `SimplePort (port_type = port.PortType .${ block . mrcPortType } , location = ${ ports [ 0 ] } )` ;
145+ code += `${ simplePort } (port_type = ${ portType } .${ block . mrcPortType } , location = ${ ports [ 0 ] } )` ;
143146
144147 } else if ( ports . length === 2 ) {
145148 let port1Type = 'UNKNOWN' ;
@@ -159,9 +162,9 @@ export const pythonFromBlock = function (
159162 port2Type = PORT_TYPE_EXPANSION_HUB_SERVO_PORT ;
160163 break ;
161164 }
162- code += `CompoundPort (port_type = port.PortType .${ block . mrcPortType } ,\n` ;
163- code += `${ generator . INDENT } port1 = port.SimplePort (port_type = port.PortType .${ port1Type } , location = ${ ports [ 0 ] } ),\n` ;
164- code += `${ generator . INDENT } port2 = port.SimplePort (port_type = port.PortType .${ port2Type } , location = ${ ports [ 1 ] } ))` ;
165+ code += `${ compoundPort } (port_type = ${ portType } .${ block . mrcPortType } ,\n` ;
166+ code += `${ generator . INDENT } port1 = ${ simplePort } (port_type = ${ portType } .${ port1Type } , location = ${ ports [ 0 ] } ),\n` ;
167+ code += `${ generator . INDENT } port2 = ${ simplePort } (port_type = ${ portType } .${ port2Type } , location = ${ ports [ 1 ] } ))` ;
165168 }
166169
167170 return [ code , Order . FUNCTION_CALL ] ;
0 commit comments