4Copyright (c) 2011-2016 ARM Limited
6Licensed under the Apache License, Version 2.0 (the "License");
7you may not use this file except in compliance with the License.
8You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12Unless required by applicable law or agreed to
in writing, software
13distributed under the License
is distributed on an
"AS IS" BASIS,
14WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied.
15See the License
for the specific language governing permissions
and
16limitations under the License.
21from serial import Serial, SerialException
22from mbed_host_tests import host_tests_plugins
23from mbed_host_tests.host_tests_plugins.host_test_plugins import HostTestPluginBase
24from .conn_primitive import ConnectorPrimitive, ConnectorPrimitiveException
27class SerialConnectorPrimitive(ConnectorPrimitive):
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:
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:
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_ERRORLAST_ERROR =
"connection lost, serial.write(%d bytes): %s"% (len(payload), str(e))
126 self.
logger.prn_err(str(e))
def finish(self)
Handle DUT dtor like (close resource) operations here.
def reset(self)
Reset the dut.
def reset_dev_via_serial(self, delay=1)
Reset device using selected method, calls one of the reset plugins.
def finish(self)
Handle DUT dtor like (close resource) operations here.
def connected(self)
Check if there is a connection to DUT.
def flush(self)
Flush read/write channels of DUT.
def __init__(self, name, port, baudrate, config)
def read(self, count)
Read data from serial port RX buffer.
def write(self, payload, log=False)
Write data to serial port TX buffer.
Base class for all plugins used with host tests.