当前位置: 首页>>代码示例>>Python>>正文


Python SCSI.write10方法代码示例

本文整理汇总了Python中pyscsi.pyscsi.scsi.SCSI.write10方法的典型用法代码示例。如果您正苦于以下问题:Python SCSI.write10方法的具体用法?Python SCSI.write10怎么用?Python SCSI.write10使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyscsi.pyscsi.scsi.SCSI的用法示例。


在下文中一共展示了SCSI.write10方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from pyscsi.pyscsi.scsi import SCSI [as 别名]
# 或者: from pyscsi.pyscsi.scsi.SCSI import write10 [as 别名]
def main():
    dev = MockWrite10()
    dev.opcodes = sbc
    s = SCSI(dev)
    s.blocksize = 512

    data = bytearray(27 * 512)

    w = s.write10(1024, 27, data)
    cdb = w.cdb
    assert cdb[0] == s.device.opcodes.WRITE_10.value
    assert cdb[1] == 0
    assert scsi_ba_to_int(cdb[2:6]) == 1024
    assert cdb[6] == 0
    assert scsi_ba_to_int(cdb[7:9]) == 27
    assert cdb[9] == 0
    cdb = w.unmarshall_cdb(cdb)
    assert cdb['opcode'] == s.device.opcodes.WRITE_10.value
    assert cdb['wrprotect'] == 0
    assert cdb['dpo'] == 0
    assert cdb['fua'] == 0
    assert cdb['lba'] == 1024
    assert cdb['group'] == 0
    assert cdb['tl'] == 27

    d = Write10.unmarshall_cdb(Write10.marshall_cdb(cdb))
    assert d == cdb

    w = s.write10(65536, 27, data, wrprotect=2, dpo=1, fua=1, group=19)
    cdb = w.cdb
    assert cdb[0] == s.device.opcodes.WRITE_10.value
    assert cdb[1] == 0x58
    assert scsi_ba_to_int(cdb[2:6]) == 65536
    assert cdb[6] == 0x13
    assert scsi_ba_to_int(cdb[7:9]) == 27
    assert cdb[9] == 0
    cdb = w.unmarshall_cdb(cdb)
    assert cdb['opcode'] == s.device.opcodes.WRITE_10.value
    assert cdb['wrprotect'] == 2
    assert cdb['dpo'] == 1
    assert cdb['fua'] == 1
    assert cdb['lba'] == 65536
    assert cdb['group'] == 19
    assert cdb['tl'] == 27

    d = Write10.unmarshall_cdb(Write10.marshall_cdb(cdb))
    assert d == cdb
开发者ID:Katana-Steel,项目名称:python-scsi,代码行数:49,代码来源:test_cdb_write10.py

示例2: __init__

# 需要导入模块: from pyscsi.pyscsi.scsi import SCSI [as 别名]
# 或者: from pyscsi.pyscsi.scsi.SCSI import write10 [as 别名]
class Device:
    def __init__(self, device):
        if not device:
            raise exceptions.CommandLineError(
                '--device parameter is required, should point to the disk '
                'device representing the meter.')

        self.device_name_ = device
        self.scsi_device_ = SCSIDevice(device, readwrite=True)
        self.scsi_ = SCSI(self.scsi_device_)
        self.scsi_.blocksize = _REGISTER_SIZE

    def connect(self):
        inq = self.scsi_.inquiry()
        logging.debug('Device connected: %r', inq.result)
        vendor = inq.result['t10_vendor_identification'][:32]
        if vendor != b'LifeScan':
            raise exceptions.ConnectionFailed(
                'Device %s is not a LifeScan glucometer.' % self.device_name_)

    def disconnect(self):  # pylint: disable=no-self-use
        return

    def _send_request(self, lba, request_format, request_obj, response_format):
        """Send a request to the meter, and read its response.

        Args:
          lba: (int) the address of the block register to use, known
            valid addresses are 3, 4 and 5.
          request_format: a construct format identifier of the request to send
          request_obj: the object to format with the provided identifier
          response_format: a construct format identifier to parse the returned
            message with.

        Returns:
          The Container object parsed from the response received by the meter.

        Raises:
          lifescan.MalformedCommand if Construct fails to build the request or
            parse the response.

        """
        try:
            request = request_format.build(request_obj)
            request_raw = _PACKET.build({'data': {'value': {
                'message': request,
            }}})
            logging.debug(
                'Request sent: %s', binascii.hexlify(request_raw))
            self.scsi_.write10(lba, 1, request_raw)

            response_raw = self.scsi_.read10(lba, 1)
            logging.debug(
                'Response received: %s', binascii.hexlify(response_raw.datain))
            response_pkt = _PACKET.parse(response_raw.datain).data
            logging.debug('Response packet: %r', response_pkt)

            response = response_format.parse(response_pkt.value.message)
            logging.debug('Response parsed: %r', response)

            return response
        except construct.ConstructError as e:
            raise lifescan.MalformedCommand(str(e))

    def _query_string(self, selector):
        response = self._send_request(
            3, _QUERY_REQUEST, {'selector': selector}, _QUERY_RESPONSE)

        return response.value

    def get_meter_info(self):
        return common.MeterInfo(
            'OneTouch %s glucometer' % self._query_string('model'),
            serial_number=self.get_serial_number(),
            version_info=(
                'Software version: ' + self.get_version(),),
            native_unit=self.get_glucose_unit())

    def get_serial_number(self):
        return self._query_string('serial')

    def get_version(self):
        return self._query_string('software')

    def get_datetime(self):
        response = self._send_request(
            3, _READ_RTC_REQUEST, None, _READ_RTC_RESPONSE)
        return response.timestamp

    def set_datetime(self, date=datetime.datetime.now()):
        self._send_request(
            3, _WRITE_RTC_REQUEST, {'timestamp': date},
            _COMMAND_SUCCESS)

        # The device does not return the new datetime, so confirm by calling
        # READ RTC again.
        return self.get_datetime()

    def zero_log(self):
        self._send_request(
#.........这里部分代码省略.........
开发者ID:Flameeyes,项目名称:glucometerutils,代码行数:103,代码来源:otverio2015.py


注:本文中的pyscsi.pyscsi.scsi.SCSI.write10方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。