Skip to content

Commit

Permalink
Adding pyHydrabus looking forward for its publication to PyPI
Browse files Browse the repository at this point in the history
  • Loading branch information
ghecko committed Oct 4, 2019
1 parent dd8bed9 commit e424a38
Show file tree
Hide file tree
Showing 17 changed files with 2,040 additions and 198 deletions.
40 changes: 13 additions & 27 deletions hydrabus_framework/utils/hb_generic_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,34 +47,20 @@ def hb_wait_ubtn(serial_instance):
"""
# timeout=1 minute
timeout = time.time() + 60 * 1
while True:
if serial_instance.read(1) == 'B'.encode('utf-8'):
if serial_instance.read(3) == 'BIO'.encode('utf-8'):
# carriage return needed to reset interface
serial_instance.write(b'\x0D\x0A')
time.sleep(0.2)
serial_instance.read(serial_instance.in_waiting)
try:
while True:
if serial_instance.hydrabus.read(1) == 'B'.encode('utf-8'):
if serial_instance.hydrabus.read(3) == 'BIO'.encode('utf-8'):
# carriage return needed to reset interface
serial_instance.hydrabus.write(b'\x0D\x0A')
time.sleep(0.2)
serial_instance.read(serial_instance.hydrabus.in_waiting)
break
if time.time() > timeout:
Logger().handle("Wait UBTN timeout reached", Logger.ERROR)
break
if time.time() > timeout:
Logger().handle("Wait UBTN timeout reached", Logger.ERROR)
break


def hb_connect_bbio(device, baudrate, timeout):
"""
Connect to the hydrabus device, and then, switch to bbio mode
:param device: String, hydrabus device path
:param baudrate: integer, baudrate speed to communicate with hydrabus
:param timeout: integer, read timeout value (sec)
:return: serial instance
"""
serial_instance = hb_connect(device, baudrate, timeout)
if isinstance(serial_instance, serial.Serial):
if hb_switch_bbio(serial_instance):
return serial_instance
else:
Logger().handle('Unable to switch hydrabus into bbio mode', Logger.ERROR)
return None
except KeyboardInterrupt:
pass


def hb_connect(device, baudrate, timeout):
Expand Down
1 change: 0 additions & 1 deletion hydrabus_framework/utils/protocols/__init__.py

This file was deleted.

117 changes: 0 additions & 117 deletions hydrabus_framework/utils/protocols/spi.py

This file was deleted.

53 changes: 0 additions & 53 deletions hydrabus_framework/utils/protocols/uart.py

This file was deleted.

33 changes: 33 additions & 0 deletions hydrabus_framework/utils/pyHydrabus/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2019 Nicolas OBERLI
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from .spi import *
from .i2c import *
from .onewire import *
from .rawwire import *
from .smartcard import *
from .uart import *
from .utils import *
from .swd import *

import logging

logger = logging.getLogger(__name__)
logger.addHandler(logging.NullHandler())

INPUT = 1
OUTPUT = 0

name = "pyHydrabus"
__version__ = 0.1
Loading

0 comments on commit e424a38

Please sign in to comment.