4 Copyright (c) 2011-2016 ARM Limited 6 Licensed under the Apache License, Version 2.0 (the "License"); 7 you may not use this file except in compliance with the License. 8 You may obtain a copy of the License at 10 http://www.apache.org/licenses/LICENSE-2.0 12 Unless required by applicable law or agreed to in writing, software 13 distributed under the License is distributed on an "AS IS" BASIS, 14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 See the License for the specific language governing permissions and 16 limitations under the License. 21 from serial
import Serial, SerialException
22 from mbed_host_tests
import host_tests_plugins
24 from .conn_primitive
import ConnectorPrimitive, ConnectorPrimitiveException
28 def __init__(self, name, port, baudrate, config):
29 ConnectorPrimitive.__init__(self, name)
48 if serial_port
is None:
51 if serial_port != self.
port:
53 self.
logger.prn_inf(
"serial port changed from '%s to '%s')"% (self.
port, serial_port))
54 self.
port = serial_port
56 startTime = time.time()
64 except SerialException
as e:
66 self.
LAST_ERROR =
"connection lost, serial.Serial(%s, %d, %d, %d): %s"% (self.
port,
71 self.
logger.prn_err(str(e))
80 """! Reset device using selected method, calls one of the reset plugins """ 81 reset_type = self.
config.get(
'reset_type',
'default')
83 reset_type =
'default' 84 disk = self.
config.get(
'disk',
None)
86 self.
logger.prn_inf(
"reset device using '%s' plugin..."% reset_type)
87 result = host_tests_plugins.call_plugin(
'ResetMethod',
92 polling_timeout=self.
config.get(
'polling_timeout'))
95 self.
logger.prn_inf(
"waiting %.2f sec after reset"% delay)
97 self.
logger.prn_inf(
"wait for it...")
101 """! Read data from serial port RX buffer """ 109 except SerialException
as e:
111 self.
LAST_ERROR =
"connection lost, serial.read(%d): %s"% (count, str(e))
112 self.
logger.prn_err(str(e))
115 def write(self, payload, log=False):
116 """! Write data to serial port TX buffer """ 121 self.
logger.prn_txd(payload)
123 except SerialException
as e:
125 self.
LAST_ERROR =
"connection lost, serial.write(%d bytes): %s"% (len(payload), str(e))
126 self.
logger.prn_err(str(e))
Base class for all plugins used with host tests.
def __init__(self, name, port, baudrate, config)
def write(self, payload, log=False)
Write data to serial port TX buffer.
def reset_dev_via_serial(self, delay=1)
Reset device using selected method, calls one of the reset plugins.
def read(self, count)
Read data from serial port RX buffer.
def finish(self)
Handle DUT dtor like (close resource) operations here.