<commit_before>#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
Copyright (C) 2011-2012, <NAME> <<EMAIL>>

This file is part of IMPLib2 a small Python library implementing
the IMPBUS-2 data transmission protocol.

IMPLib2 is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.

IMPLib2 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with IMPLib2. If not, see <http://www.gnu.org/licenses/>.
"""

import time
import serial
from struct import unpack

class DeviceError(Exception):
    pass

class Device(object):
    def __init__(self, port):
        self.ser = serial.Serial()
        self.ser.port = port
        self.open_device()

    def _timeout(self, length):
        baudrate = self.ser.baudrate / 100
        return 600.0 / baudrate * length

    def open_device(self, baudrate=9600):
        self.ser.baudrate = baudrate
        self.ser.bytesize = serial.EIGHTBITS
        self.ser.parity   = serial.PARITY_ODD
        self.ser.stopbits = serial.STOPBITS_TWO
        self.ser.timeout  = 0 # act nonblocking
        self.ser.xonxoff  = 0
        self.ser.rtscts   = 0
        self.ser.dsrdtr   = 0
        self.ser.open()
        self.ser.flush()
        time.sleep(0.050)

    def close_device(self):
        if self.ser.isOpen():
            self.ser.flush()
            self.ser.close()
        time.sleep(0.050)

    def write_pkg(self, packet):
        bytes_send = self.ser.write(packet)
        if not bytes_send == len(packet):
            raise DeviceError("Couldn't write all bytes!")
<commit_msg>Fixes a little "Division by Zero" bug ;-)<commit_after>#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
Copyright (C) 2011-2012, <NAME> <<EMAIL>>

This file is part of IMPLib2 a small Python library implementing
the IMPBUS-2 data transmission protocol.

IMPLib2 is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.

IMPLib2 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with IMPLib2. If not, see <http://www.gnu.org/licenses/>.
"""

import time
import serial
from struct import unpack

from binascii import b2a_hex as b2a

class DeviceError(Exception):
    pass

class Device(object):
    def __init__(self, port):
        self.ser = serial.Serial()
        self.ser.port = port
        self.open_device()

    def _timeout(self, length):
        if length == 0: return 0
        baudrate = self.ser.baudrate
        return 600.0 / baudrate * length

    def open_device(self, baudrate=9600):
        self.ser.baudrate = baudrate
        self.ser.bytesize = serial.EIGHTBITS
        self.ser.parity   = serial.PARITY_ODD
        self.ser.stopbits = serial.STOPBITS_TWO
        self.ser.timeout  = 0 # act nonblocking
        self.ser.xonxoff  = 0
        self.ser.rtscts   = 0
        self.ser.dsrdtr   = 0
        self.ser.open()
        self.ser.flush()
        time.sleep(0.050)

    def close_device(self):
        if self.ser.isOpen():
            self.ser.flush()
            self.ser.close()
        time.sleep(0.050)

    def write_pkg(self, packet):
        bytes_send = self.ser.write(packet)
        if not bytes_send == len(packet):
            raise DeviceError("Couldn't write all bytes!")

{'fraction_non_alphanumeric': 0.08920539730134933, 'fraction_numerical': 0.01924037981009495, 'mean_word_length': 2.689400921658986, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2446670', 'n_tokens_mistral': 1241, 'n_tokens_neox': 1176, 'n_words': 417}