Skip to content

Rename Package serial -> serial_labgrid #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions examples/at_protocol.py
Original file line number Diff line number Diff line change
@@ -12,8 +12,8 @@
sys.path.insert(0, '..')

import logging
import serial
import serial.threaded
import serial_labgrid
import serial_labgrid.threaded
import threading

try:
@@ -26,7 +26,7 @@ class ATException(Exception):
pass


class ATProtocol(serial.threaded.LineReader):
class ATProtocol(serial_labgrid.threaded.LineReader):

TERMINATOR = b'\r\n'

@@ -146,9 +146,9 @@ def get_mac_address(self):
# requests hardware / calibration info as event
return self.command_with_event_response("AT+JRBD")

ser = serial.serial_for_url('spy://COM1', baudrate=115200, timeout=1)
ser = serial_labgrid.serial_for_url('spy://COM1', baudrate=115200, timeout=1)
#~ ser = serial.Serial('COM1', baudrate=115200, timeout=1)
with serial.threaded.ReaderThread(ser, PAN1322) as bt_module:
with serial_labgrid.threaded.ReaderThread(ser, PAN1322) as bt_module:
bt_module.reset()
print("reset OK")
print("MAC address is", bt_module.get_mac_address())
16 changes: 8 additions & 8 deletions examples/port_publisher.py
Original file line number Diff line number Diff line change
@@ -20,9 +20,9 @@
import time
import traceback

import serial
import serial.rfc2217
import serial.tools.list_ports
import serial_labgrid
import serial_labgrid.rfc2217
import serial_labgrid.tools.list_ports

import dbus

@@ -105,7 +105,7 @@ def __init__(self, device, name, network_port, on_close=None, log=None):
self.on_close = on_close
self.log = log
self.device = device
self.serial = serial.Serial()
self.serial = serial_labgrid.Serial()
self.serial.port = device
self.serial.baudrate = 115200
self.serial.timeout = 0
@@ -220,7 +220,7 @@ def handle_serial_read(self):
if self.socket is not None:
# escape outgoing data when needed (Telnet IAC (0xff) character)
if self.rfc2217:
data = serial.to_bytes(self.rfc2217.escape(data))
data = serial_labgrid.to_bytes(self.rfc2217.escape(data))
self.buffer_ser2net.extend(data)
else:
self.handle_serial_error()
@@ -299,9 +299,9 @@ def handle_connect(self):
self.serial.rts = True
self.serial.dtr = True
if self.log is not None:
self.rfc2217 = serial.rfc2217.PortManager(self.serial, self, logger=log.getChild(self.device))
self.rfc2217 = serial_labgrid.rfc2217.PortManager(self.serial, self, logger=log.getChild(self.device))
else:
self.rfc2217 = serial.rfc2217.PortManager(self.serial, self)
self.rfc2217 = serial_labgrid.rfc2217.PortManager(self.serial, self)
else:
# reject connection if there is already one
connection.close()
@@ -527,7 +527,7 @@ def unpublish(forwarder):
now = time.time()
if now > next_check:
next_check = now + 5
connected = [d for d, p, i in serial.tools.list_ports.grep(args.ports_regex)]
connected = [d for d, p, i in serial_labgrid.tools.list_ports.grep(args.ports_regex)]
# Handle devices that are published, but no longer connected
for device in set(published).difference(connected):
log.info("unpublish: {}".format(published[device]))
10 changes: 5 additions & 5 deletions examples/rfc2217_server.py
Original file line number Diff line number Diff line change
@@ -12,16 +12,16 @@
import sys
import time
import threading
import serial
import serial.rfc2217
import serial_labgrid
import serial_labgrid.rfc2217


class Redirector(object):
def __init__(self, serial_instance, socket, debug=False):
self.serial = serial_instance
self.socket = socket
self._write_lock = threading.Lock()
self.rfc2217 = serial.rfc2217.PortManager(
self.rfc2217 = serial_labgrid.rfc2217.PortManager(
self.serial,
self,
logger=logging.getLogger('rfc2217.server') if debug else None)
@@ -134,7 +134,7 @@ def stop(self):
logging.getLogger('rfc2217').setLevel(level)

# connect to serial port
ser = serial.serial_for_url(args.SERIALPORT, do_not_open=True)
ser = serial_labgrid.serial_for_url(args.SERIALPORT, do_not_open=True)
ser.timeout = 3 # required so that the reader thread can exit
# reset control line as no _remote_ "terminal" has been connected yet
ser.dtr = False
@@ -144,7 +144,7 @@ def stop(self):

try:
ser.open()
except serial.SerialException as e:
except serial_labgrid.SerialException as e:
logging.error("Could not open serial port {}: {}".format(ser.name, e))
sys.exit(1)

4 changes: 2 additions & 2 deletions examples/setup-miniterm-py2exe.py
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@

sys.path.insert(0, '..')

import serial.tools.miniterm
import serial_labgrid.tools.miniterm


sys.argv.extend("py2exe --bundle 1".split())
@@ -28,6 +28,6 @@
}
},
console=[
serial.tools.miniterm.__file__
serial_labgrid.tools.miniterm.__file__
],
)
12 changes: 6 additions & 6 deletions examples/tcp_serial_redirect.py
Original file line number Diff line number Diff line change
@@ -8,12 +8,12 @@

import sys
import socket
import serial
import serial.threaded
import serial_labgrid
import serial_labgrid.threaded
import time


class SerialToNet(serial.threaded.Protocol):
class SerialToNet(serial_labgrid.threaded.Protocol):
"""serial->socket"""

def __init__(self):
@@ -129,7 +129,7 @@ def data_received(self, data):
args = parser.parse_args()

# connect to serial port
ser = serial.serial_for_url(args.SERIALPORT, do_not_open=True)
ser = serial_labgrid.serial_for_url(args.SERIALPORT, do_not_open=True)
ser.baudrate = args.BAUDRATE
ser.bytesize = args.bytesize
ser.parity = args.parity
@@ -150,12 +150,12 @@ def data_received(self, data):

try:
ser.open()
except serial.SerialException as e:
except serial_labgrid.SerialException as e:
sys.stderr.write('Could not open serial port {}: {}\n'.format(ser.name, e))
sys.exit(1)

ser_to_net = SerialToNet()
serial_worker = serial.threaded.ReaderThread(ser, ser_to_net)
serial_worker = serial_labgrid.threaded.ReaderThread(ser, ser_to_net)
serial_worker.start()

if not args.client:
10 changes: 5 additions & 5 deletions examples/wxSerialConfigDialog.py
Original file line number Diff line number Diff line change
@@ -8,8 +8,8 @@
# SPDX-License-Identifier: BSD-3-Clause

import wx
import serial
import serial.tools.list_ports
import serial_labgrid
import serial_labgrid.tools.list_ports

SHOW_BAUDRATE = 1 << 0
SHOW_FORMAT = 1 << 1
@@ -98,7 +98,7 @@ def __set_properties(self):
preferred_index = 0
self.choice_port.Clear()
self.ports = []
for n, (portname, desc, hwid) in enumerate(sorted(serial.tools.list_ports.comports())):
for n, (portname, desc, hwid) in enumerate(sorted(serial_labgrid.tools.list_ports.comports())):
self.choice_port.Append(u'{} - {}'.format(portname, desc))
self.ports.append(portname)
if self.serial.name == portname:
@@ -134,7 +134,7 @@ def __set_properties(self):
# fill in parities and select current setting
self.choice_parity.Clear()
for n, parity in enumerate(self.serial.PARITIES):
self.choice_parity.Append(str(serial.PARITY_NAMES[parity]))
self.choice_parity.Append(str(serial_labgrid.PARITY_NAMES[parity]))
if self.serial.parity == parity:
index = n
self.choice_parity.SetSelection(index)
@@ -264,7 +264,7 @@ class MyApp(wx.App):
def OnInit(self):
wx.InitAllImageHandlers()

ser = serial.Serial()
ser = serial_labgrid.Serial()
print(ser)
# loop until cancel is pressed, old values are used as start for the next run
# show the different views, one after the other
8 changes: 4 additions & 4 deletions examples/wxTerminal.py
Original file line number Diff line number Diff line change
@@ -7,8 +7,8 @@
# SPDX-License-Identifier: BSD-3-Clause

import codecs
from serial.tools.miniterm import unichr
import serial
from serial_labgrid.tools.miniterm import unichr
import serial_labgrid
import threading
import wx
import wx.lib.newevent
@@ -125,7 +125,7 @@ class TerminalFrame(wx.Frame):
"""Simple terminal program for wxPython"""

def __init__(self, *args, **kwds):
self.serial = serial.Serial()
self.serial = serial_labgrid.Serial()
self.serial.timeout = 0.5 # make sure that the alive event can be checked from time to time
self.settings = TerminalSetup() # placeholder for the settings
self.thread = None
@@ -265,7 +265,7 @@ def OnPortSettings(self, event): # wxGlade: TerminalFrame.<event_handler>
if result == wx.ID_OK or event is not None:
try:
self.serial.open()
except serial.SerialException as e:
except serial_labgrid.SerialException as e:
with wx.MessageDialog(self, str(e), "Serial Port Error", wx.OK | wx.ICON_ERROR)as dlg:
dlg.ShowModal()
else:
12 changes: 6 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -27,16 +27,16 @@ local_scheme = "no-local-version"
"Bug Tracker" = "https://github.com/labgrid-project/labgrid/issues"

[project.scripts]
pyserial-miniterm = "serial.tools.miniterm:main"
pyserial-ports = "serial.tools.list_ports:main"
pyserial-miniterm = "serial_labgrid.tools.miniterm:main"
pyserial-ports = "serial_labgrid.tools.list_ports:main"

[project.optional-dependencies]
cp2110 = ['hidapi']

[tool.setuptools]
packages = [
"serial",
"serial.threaded",
"serial.tools",
"serial.urlhandler",
"serial_labgrid",
"serial_labgrid.threaded",
"serial_labgrid.tools",
"serial_labgrid.urlhandler",
]
12 changes: 6 additions & 6 deletions serial/__init__.py → serial_labgrid/__init__.py
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@
import sys
import importlib

from serial.serialutil import *
from serial_labgrid.serialutil import *
#~ SerialBase, SerialException, to_bytes, iterbytes

__version__ = '3.5.0.2'
@@ -21,22 +21,22 @@

# pylint: disable=wrong-import-position
if sys.platform == 'cli':
from serial.serialcli import Serial
from serial_labgrid.serialcli import Serial
else:
import os
# chose an implementation, depending on os
if os.name == 'nt': # sys.platform == 'win32':
from serial.serialwin32 import Serial
from serial_labgrid.serialwin32 import Serial
elif os.name == 'posix':
from serial.serialposix import Serial, PosixPollSerial, VTIMESerial # noqa
from serial_labgrid.serialposix import Serial, PosixPollSerial, VTIMESerial # noqa
elif os.name == 'java':
from serial.serialjava import Serial
from serial_labgrid.serialjava import Serial
else:
raise ImportError("Sorry: no implementation for your platform ('{}') available".format(os.name))


protocol_handler_packages = [
'serial.urlhandler',
'serial_labgrid.urlhandler',
]


File renamed without changes.
20 changes: 10 additions & 10 deletions serial/rfc2217.py → serial_labgrid/rfc2217.py
Original file line number Diff line number Diff line change
@@ -74,8 +74,8 @@
except ImportError:
import queue as Queue

import serial
from serial.serialutil import SerialBase, SerialException, to_bytes, \
import serial_labgrid
from serial_labgrid.serialutil import SerialBase, SerialException, to_bytes, \
iterbytes, PortNotOpenError, Timeout

# port string is expected to be something like this:
@@ -207,18 +207,18 @@


RFC2217_PARITY_MAP = {
serial.PARITY_NONE: 1,
serial.PARITY_ODD: 2,
serial.PARITY_EVEN: 3,
serial.PARITY_MARK: 4,
serial.PARITY_SPACE: 5,
serial_labgrid.PARITY_NONE: 1,
serial_labgrid.PARITY_ODD: 2,
serial_labgrid.PARITY_EVEN: 3,
serial_labgrid.PARITY_MARK: 4,
serial_labgrid.PARITY_SPACE: 5,
}
RFC2217_REVERSE_PARITY_MAP = dict((v, k) for k, v in RFC2217_PARITY_MAP.items())

RFC2217_STOPBIT_MAP = {
serial.STOPBITS_ONE: 1,
serial.STOPBITS_ONE_POINT_FIVE: 3,
serial.STOPBITS_TWO: 2,
serial_labgrid.STOPBITS_ONE: 1,
serial_labgrid.STOPBITS_ONE_POINT_FIVE: 3,
serial_labgrid.STOPBITS_TWO: 2,
}
RFC2217_REVERSE_STOPBIT_MAP = dict((v, k) for k, v in RFC2217_STOPBIT_MAP.items())

4 changes: 2 additions & 2 deletions serial/rs485.py → serial_labgrid/rs485.py
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@
from __future__ import absolute_import

import time
import serial
import serial_labgrid


class RS485Settings(object):
@@ -34,7 +34,7 @@ def __init__(
self.delay_before_rx = delay_before_rx


class RS485(serial.Serial):
class RS485(serial_labgrid.Serial):
"""\
A subclass that replaces the write method with one that toggles RTS
according to the RS485 settings.
2 changes: 1 addition & 1 deletion serial/serialcli.py → serial_labgrid/serialcli.py
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@

import System
import System.IO.Ports
from serial.serialutil import *
from serial_labgrid.serialutil import *

# must invoke function with byte array, make a helper to convert strings
# to byte arrays
2 changes: 1 addition & 1 deletion serial/serialjava.py → serial_labgrid/serialjava.py
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@

from __future__ import absolute_import

from serial.serialutil import *
from serial_labgrid.serialutil import *


def my_import(name):
Loading