+
Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -199,5 +199,3 @@ $RECYCLE.BIN/
# Windows shortcuts
*.lnk

# Custom rules
pyrp3/_version.py
4 changes: 1 addition & 3 deletions pyrp3/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
import importlib_metadata

__version__ = importlib_metadata.version("pyrp3") # noqa: F401
from ._version import __version__ # noqa F401
1 change: 1 addition & 0 deletions pyrp3/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "1.1.1"
2 changes: 1 addition & 1 deletion pyrp3/client_memory.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np


class ClientMemory(object):
class ClientMemory:
def __init__(self, remote_connection):
self.remote_connection = remote_connection
self.remote_interface = remote_connection.root.mem()
Expand Down
110 changes: 0 additions & 110 deletions pyrp3/enum/enum.py → pyrp3/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,6 @@ def __call__(cls, key=None):
return cls._reverse_dct[int(key)]


class FullEnumMetaclass(EnumMetaclass):
"""Metaclass for full enumerations.

A full enumeration displays all the values defined in base classes.
"""

def __init__(cls, name, bases, dict):
super(FullEnumMetaclass, cls).__init__(name, bases, dict)
for obj in cls.__mro__:
if isinstance(obj, EnumMetaclass):
cls._reverse_dct.update(obj._reverse_dct)
for attr in obj._members:
# XXX inefficient
if attr not in cls._members:
cls._members.append(attr)


class EnumInstance(int):
"""Class to represent an enumeration value.

Expand All @@ -99,96 +82,3 @@ def __str__(self):

class Enum(metaclass=EnumMetaclass):
pass


class FullEnum(metaclass=FullEnumMetaclass):
pass


def _test():
class Color(Enum):
red = 1
green = 2
blue = 3

print(Color.red)

print(repr(Color.red))
print(Color.red == Color.red)
print(Color.red == Color.blue)
print(Color.red == 1)
print(Color.red == 2)

class ExtendedColor(Color):
white = 0
orange = 4
yellow = 5
purple = 6
black = 7

print(ExtendedColor.orange)
print(ExtendedColor.red)

print(Color.red == ExtendedColor.red)

class OtherColor(Enum):
white = 4
blue = 5

class MergedColor(Color, OtherColor):
pass

print(MergedColor.red)
print(MergedColor.white)

print(Color)
print(ExtendedColor)
print(OtherColor)
print(MergedColor)


def _test2():
class Color(FullEnum):
red = 1
green = 2
blue = 3

print(Color.red)

print(repr(Color.red))
print(Color.red == Color.red)
print(Color.red == Color.blue)
print(Color.red == 1)
print(Color.red == 2)

class ExtendedColor(Color):
white = 0
orange = 4
yellow = 5
purple = 6
black = 7

print(ExtendedColor.orange)
print(ExtendedColor.red)

print(Color.red == ExtendedColor.red)

class OtherColor(FullEnum):
white = 4
blue = 5

class MergedColor(Color, OtherColor):
pass

print(MergedColor.red)
print(MergedColor.white)

print(Color)
print(ExtendedColor)
print(OtherColor)
print(MergedColor)


if __name__ == "__main__":
_test()
_test2()
1 change: 0 additions & 1 deletion pyrp3/enum/__init__.py

This file was deleted.

49 changes: 15 additions & 34 deletions pyrp3/instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .memory import MemoryInterface


class UnsignedInteger(object):
class UnsignedInteger:
def __init__(self, size):
self.size = size

Expand All @@ -18,7 +18,7 @@ def to_binary(self, val):
return intbv(val, max=2**self.size, min=0)._val


class SignedInteger(object):
class SignedInteger:
def __init__(self, size):
self.size = size

Expand All @@ -36,7 +36,6 @@ def to_binary(self, val):
class EnumTypeWrapper(UnsignedInteger):
def __init__(self, enum_type):
self._enum_type = enum_type
maximum = max(self._enum_type._reverse_dct.keys())
size = int(ceil(log(16, 2)))
super(EnumTypeWrapper, self).__init__(size=size)

Expand Down Expand Up @@ -90,7 +89,7 @@ def to_binary(self, val):
return out[32:]._val


class RegisterProperty(object):
class RegisterProperty:
def __init__(self, addr, register_type, size=None):
if isinstance(register_type, type) and issubclass(register_type, Enum):
register_type = EnumTypeWrapper(register_type)
Expand Down Expand Up @@ -121,7 +120,7 @@ class GetSetRegister(SetRegister, GetRegister):
pass


class GetSetBit(object):
class GetSetBit:
def __init__(self, addr, pos, bit_type=None):
self._bit_type = bit_type
self.addr = addr
Expand All @@ -141,13 +140,6 @@ def __set__(self, instance, value):
return instance.write(self.addr, int(new_value))


# class EnumRegister(GetSetRegister):
# def __init__(self, addr, enum_type):
# assert issubclass(enum_type, Enum)
# register_type = EnumType(enum_type)
# super(EnumRegister, self).__init__(addr, register_type)


class HK(MemoryInterface):
def __init__(self, addr_base=0x40000000, **kwd):
kwd["addr_base"] = addr_base
Expand Down Expand Up @@ -200,10 +192,10 @@ def __init__(self, addr_base=0x40400000, **kwd):
class TriggerSource(Enum):
none = 0
immediately = 1
chA_posedge = 2
chA_negedge = 3
chB_posedge = 4
chB_negedge = 5
cha_posedge = 2
cha_negedge = 3
chb_posedge = 4
chb_negedge = 5
ext_posedge = 6
ext_negedge = 7
awg_posedge = 8
Expand Down Expand Up @@ -248,7 +240,7 @@ def arm_trigger(self, v=True):
dac2_on_ch1 = GetSetBit(0x50, pos=0)
dac1_on_ch2 = GetSetBit(0x50, pos=1)

## Function specific to read the array of data
# Function specific to read the array of data
def get_rawdata(self, addr):
x = self.reads(addr, self.data_length)
y = x.copy()
Expand Down Expand Up @@ -295,7 +287,7 @@ def setup(self, frequency=1, trigger_source=TriggerSource.immediately):
self.arm_trigger()

def rearm(self, frequency=None, trigger_source=8):
if not frequency is None:
if frequency is not None:
self.frequency = frequency
self.trigger_delay = self.data_length
self.trigger_source = trigger_source
Expand Down Expand Up @@ -515,7 +507,7 @@ def setup(self, frequency=1):
self.sm_reset = False

def trig(self, frequency=None):
if not frequency is None:
if frequency is not None:
self.frequency = frequency
self.start_offset = 0
self.trig_selector = 1
Expand Down Expand Up @@ -582,15 +574,15 @@ def derivative(self, val):

def initialize(self, setpoint=None, integral=0, proportional=0, derivative=0):
self.reset = True
if not setpoint is None:
if setpoint is not None:
self.setpoint = setpoint
self.integral = integral
self.proportional = proportional
self.derivative = derivative
self.reset = False


class InterfaceDescriptor(object):
class InterfaceDescriptor:
def __init__(self, cls, **kwd):
self._cls = cls
self.kwd = kwd
Expand All @@ -601,7 +593,7 @@ def __get__(self, instance, owner):
return self._cls(parent_memory=instance, **self.kwd)


class RedPitaya(object):
class RedPitaya:
hk = InterfaceDescriptor(HK)
ams = InterfaceDescriptor(AMS)
scope = InterfaceDescriptor(Scope)
Expand All @@ -613,21 +605,10 @@ class RedPitaya(object):
asgb = InterfaceDescriptor(ASG, channel="B")


# class BoardRedPitaya(RedPitaya, BoardRawMemory):
# pass


# class PCRedPitaya(RedPitaya, ClientMemory):
# pass

if __name__ == "__main__":
from time import sleep, time

import rpyc

# conn = rpyc.connect('134.157.6.206', 18861)
# red_pitaya = PCRedPitaya(remote_connection = conn)
red_pitaya = BoardRedPitaya()
red_pitaya = RedPitaya()
red_pitaya.scope.arm_trigger()
red_pitaya.scope.trigger_source = 1
sleep(1)
Expand Down
2 changes: 1 addition & 1 deletion pyrp3/memory.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class MemoryInterface(object):
class MemoryInterface:
def __init__(self, addr_base=0x00000000, parent_memory=None):
self.addr_base = addr_base
self._parent = parent_memory
Expand Down
2 changes: 1 addition & 1 deletion pyrp3/raw_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# Specify output types of read_value to uint32


class BoardRawMemory(object):
class BoardRawMemory:
"""Classes uses to interface de RedPitaya memory

This is a one to one match to the libmonitor.so library"""
Expand Down
22 changes: 19 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,37 @@
import re
from distutils.core import Extension, setup
from pathlib import Path

# from https://stackoverflow.com/a/7071358/2750945
VERSIONFILE = "pyrp3/_version.py"
verstrline = open(VERSIONFILE, "rt").read()
VSRE = r"^__version__ = ['\"]([^'\"]*)['\"]"
mo = re.search(VSRE, verstrline, re.M)
if mo:
verstr = mo.group(1)
else:
raise RuntimeError("Unable to find version string in %s." % (VERSIONFILE,))
this_directory = Path(__file__).parent
long_description = (this_directory / "README.rst").read_text()

setup(
name="pyrp3",
version="1.1.1",
version="1.2.0",
description="Python utilities for redpitaya",
author="Pierre Cladé",
author_email="pierre.clade@upmc.fr",
maintainer="Bastian Leykauf",
maintainer_email="leykauf@physik.hu-berlin.de",
long_description=long_description,
long_description_content_type="text/x-rst",
packages=["pyrp3", "pyrp3.enum"],
install_requires=["myhdl", "rpyc", "cached_property", "numpy"],
packages=["pyrp3"],
python_requires=">=3.5",
install_requires=[
"myhdl>=0.11",
"rpyc>=4.0,<5.0",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that rpyc >5.0 compatibility was fixed in version 0.3.2 of linien (according to linien's CHANGELOG.md).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with rpyc>=5.0 was that it was incompatible with the outdated python version of RedPitaya OS 1.0. The fix in that version is that the installed version was explicitly set to <5.0 to avoid conflicts between server and client. RedPitaya OS 2.0 apparently now has a stable release and the next version of Linien will only support OS 2.0.

That means that the requirement will be rpyc>=5.0,<6.0 from then on.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with rpyc>=5.0 was that it was incompatible with the outdated python version of RedPitaya OS 1.0

Python supports constraining that with the python version, as explained here: https://stackoverflow.com/questions/21082091/install-requires-based-on-python-version

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But we have to make sure that we always use the same version of rpyc for server and client since they are incompatible. Will be upgraded to >=5.0,<6.0 with the next release.

"cached_property>=1.5.2",
"numpy>=1.11.0",
],
classifiers=[
"Intended Audience :: Developers",
"Intended Audience :: Education",
Expand Down
Empty file added tests/__init__.py
Empty file.
43 changes: 43 additions & 0 deletions tests/test_enum.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from pyrp3.enum import Enum


def test_enum():
class Color(Enum):
red = 1
green = 2
blue = 3

print(Color.red)

print(repr(Color.red))
print(Color.red == Color.red)
print(Color.red == Color.blue)
print(Color.red == 1)
print(Color.red == 2)

class ExtendedColor(Color):
white = 0
orange = 4
yellow = 5
purple = 6
black = 7

print(ExtendedColor.orange)
print(ExtendedColor.red)

print(Color.red == ExtendedColor.red)

class OtherColor(Enum):
white = 4
blue = 5

class MergedColor(Color, OtherColor):
pass

print(MergedColor.red)
print(MergedColor.white)

print(Color)
print(ExtendedColor)
print(OtherColor)
print(MergedColor)
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载