How can i access plug variables outside the class in openhtf framework
- Dominant language
- Python
- Stars
- 722
- Forks
- 237
- Avg merge
- 11h 31m
- Merged PRs (30d)
- 4
Description
New to python and openhtf, please help me resolve this.
My Script looks like
class ExamplePlug(plugs.BasePlug):
@conf.inject_positional_args
def __init__(self):
try:
ser = serial.Serial(
#port='dev/ttyUSB0',
port = '/dev/ttyUSB0',
baudrate = 9600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=1, #read timeout
write_timeout=5 #write timeout
)
print ('Connection is open : ',str(ser.isOpen()))
except Exception as e:
print('ERRORRRR..', e)
@htf.plug(serial=ExamplePlug)
@htf.measures(htf.Measurement('value').equals(True))
def testing(test,serial):
packet = 'hello'
ser.write(packet.encode())
test.measurements.value = True
if __name__ == '__main__':
test = htf.Test(testing)
test.add_output_callbacks(
json_factory.OutputToJSON('./{dut_id}.test_result.json',
indent=2))
test.execute(test_start=user_input.prompt_for_test_start())
Earlier this script was working fine, but now it is throwing this error
Error: name 'ser' is not defined
Not sure what is missed here, but according to me this same thing was working perfectly earlier, please suggest something or any alternative to access this ser variable in my testing function.
Contributor guide
Assessment
This issue has not been assessed yet.