Skip to content
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

Add int64in/out record support #161

Merged
merged 5 commits into from
Jun 7, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Unreleased_

Added:

- `Add int64In/Out record support <../../pull/161>`_
- `Enable setting alarm status of Out records <../../pull/157>`_
- `Adding the non_interactive_ioc function <../../pull/156>`_

Expand Down
25 changes: 18 additions & 7 deletions docs/reference/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ and stderr streams, is sent directly to the terminal.
but note that only the following records types have direct support from this
module:

ai, ao, bi, bo, longin, longout, mbbi, mbbo, stringin, stringout, waveform
ai, ao, bi, bo, int64in, int64out, longin, longout, mbbi, mbbo, stringin, stringout, waveform

The following methods create records of the corresponding type. For all records
the `initial_value` parameter can be used to specify an initial value for the
Expand Down Expand Up @@ -285,6 +285,15 @@ All functions return a wrapped `ProcessDeviceSupportIn` or
Create ``bi`` and ``bo`` records with the specified names for false (zero)
and true (one).

.. function::
int64In(name, LOPR=None, HOPR=None, EGU=None, **fields)
int64Out(name, DRVL=None, DRVH=None, EGU=None, **fields)

Create ``int64In`` and ``int64Out`` records with specified limits and units.
The lower and upper display limits for the record can be specified. For
``int64Out`` records the ``LOPR`` and ``HOPR`` fields will be set by default
to the values of the ``DRVL`` and ``DRVH`` fields respectively.

.. function::
longIn(name, LOPR=None, HOPR=None, EGU=None, **fields)
longOut(name, DRVL=None, DRVH=None, EGU=None, **fields)
Expand Down Expand Up @@ -532,15 +541,17 @@ Create IN records (used for publishing data *from* the IOC, the naming of the
direction is confusing) using the following `softioc.builder` methods:

:func:`~softioc.builder.aIn`, :func:`~softioc.builder.boolIn`,
:func:`~softioc.builder.longIn`, :func:`~softioc.builder.stringIn`,
:func:`~softioc.builder.mbbIn`, :func:`~softioc.builder.WaveformIn`.
:func:`~softioc.builder.int64In` :func:`~softioc.builder.longIn`,
:func:`~softioc.builder.stringIn`, :func:`~softioc.builder.mbbIn`,
:func:`~softioc.builder.WaveformIn`.

Create OUT records for receiving control information into the IOC using the
following methods:

:func:`~softioc.builder.aOut`, :func:`~softioc.builder.boolOut`,
:func:`~softioc.builder.longOut`, :func:`~softioc.builder.stringOut`,
:func:`~softioc.builder.mbbOut`, :func:`~softioc.builder.WaveformOut`.
:func:`~softioc.builder.int64Out`, :func:`~softioc.builder.longOut`,
:func:`~softioc.builder.stringOut`, :func:`~softioc.builder.mbbOut`,
:func:`~softioc.builder.WaveformOut`.

For all records the `initial_value` keyword argument can be used to specify the
records value on startup.
Expand All @@ -554,7 +565,7 @@ class which provides the methods documented below.
.. class:: ProcessDeviceSupportIn

This class is used to implement Python device support for the record types
``ai``, ``bi``, ``longin``, ``mbbi`` and IN ``waveform`` records.
``ai``, ``bi``, ``int64in``, ``longin``, ``mbbi`` and IN ``waveform`` records.
AlexanderWells-diamond marked this conversation as resolved.
Show resolved Hide resolved

.. method:: set(value, severity=NO_ALARM, alarm=NO_ALARM, timestamp=None)

Expand Down Expand Up @@ -612,7 +623,7 @@ Working with OUT records
.. class:: ProcessDeviceSupportOut

This class is used to implement Python device support for the record types
``ao``, ``bo``, ``longout``, ``mbbo`` and OUT ``waveform`` records. All OUT
``ao``, ``bo``, ``int64out``, ``longout``, ``mbbo`` and OUT ``waveform`` records. All OUT
records support the following methods.

.. method:: set(value, process=True, severity=NO_ALARM, alarm=NO_ALARM)
Expand Down
11 changes: 11 additions & 0 deletions softioc/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ def longOut(name, DRVL=None, DRVH=None, EGU=None, **fields):
_set_scalar_out_defaults(fields, DRVL, DRVH)
return PythonDevice.longout(name, EGU = EGU, **fields)

def int64In(name, LOPR=None, HOPR=None, EGU=None, **fields):
_set_in_defaults(fields)
fields.setdefault('MDEL', -1)
return PythonDevice.int64in(
name, LOPR = LOPR, HOPR = HOPR, EGU = EGU, **fields)

def int64Out(name, DRVL=None, DRVH=None, EGU=None, **fields):
_set_out_defaults(fields)
_set_scalar_out_defaults(fields, DRVL, DRVH)
return PythonDevice.int64out(name, EGU = EGU, **fields)


# Field name prefixes for mbbi/mbbo records.
_mbbPrefixes = [
Expand Down
2 changes: 2 additions & 0 deletions softioc/device.dbd
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
device(longin, INST_IO, devPython_longin, "Python")
device(longout, INST_IO, devPython_longout, "Python")
device(int64in, INST_IO, devPython_int64in, "Python")
device(int64out, INST_IO, devPython_int64out, "Python")
device(ai, INST_IO, devPython_ai, "Python")
device(ao, INST_IO, devPython_ao, "Python")
device(bi, INST_IO, devPython_bi, "Python")
Expand Down
2 changes: 2 additions & 0 deletions softioc/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ def _Device_Out(*args, **kargs):

longin = _Device_In('longin', c_int32, fields.DBF_LONG, EPICS_OK)
longout = _Device_Out('longout', c_int32, fields.DBF_LONG, EPICS_OK)
int64in = _Device_In('int64in', c_int64, fields.DBF_INT64, EPICS_OK)
int64out = _Device_Out('int64out', c_int64, fields.DBF_INT64, EPICS_OK)
bi = _Device_In('bi', c_uint16, fields.DBF_CHAR, NO_CONVERT)
bo = _Device_Out('bo', c_uint16, fields.DBF_CHAR, NO_CONVERT)
mbbi = _Device_In('mbbi', c_uint16, fields.DBF_SHORT, NO_CONVERT)
Expand Down
4 changes: 3 additions & 1 deletion softioc/extension.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static void set_dict_item_steal(

/* Alas, EPICS has changed the numerical assignments of the DBF_ enums between
* versions, so to avoid unpleasant surprises, we compute thes values here in C
* and pass them back to the Python layer. */
* and pass them back to the Python layer. Order matches dbFldTypes.h. */
static PyObject *get_DBF_values(PyObject *self, PyObject *args)
{
PyObject *dict = PyDict_New();
Expand All @@ -43,6 +43,8 @@ static PyObject *get_DBF_values(PyObject *self, PyObject *args)
ADD_ENUM(dict, DBF_USHORT);
ADD_ENUM(dict, DBF_LONG);
ADD_ENUM(dict, DBF_ULONG);
ADD_ENUM(dict, DBF_INT64);
ADD_ENUM(dict, DBF_UINT64);
ADD_ENUM(dict, DBF_FLOAT);
ADD_ENUM(dict, DBF_DOUBLE);
ADD_ENUM(dict, DBF_ENUM);
Expand Down
16 changes: 3 additions & 13 deletions softioc/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

from __future__ import print_function

import sys
from ctypes import *
from .imports import get_field_offsets, get_DBF_values
import numpy


from epicscorelibs.ca.dbr import *
from epicscorelibs.ca.dbr import ca_timestamp, EPICS_epoch
Expand All @@ -32,6 +31,8 @@
DBF_SHORT: c_int16,
DBF_USHORT: c_uint16,
DBF_LONG: c_int32,
DBF_INT64: c_int64,
DBF_UINT64: c_uint64,
DBF_ULONG: c_int32, # Should be uint32, but causes trouble later.
DBF_FLOAT: c_float,
DBF_DOUBLE: c_double,
Expand All @@ -42,17 +43,6 @@
DBF_NOACCESS: c_void_p,
}

# Mapping from basic DBR_ codes to DBF_ values
DbrToDbfCode = {
DBR_STRING: DBF_STRING,
DBR_SHORT: DBF_SHORT,
DBR_FLOAT: DBF_FLOAT,
DBR_ENUM: DBF_ENUM,
DBR_CHAR: DBF_CHAR,
DBR_LONG: DBF_LONG,
DBR_DOUBLE: DBF_DOUBLE
}


class RecordFactory(object):
def __init__(self, record_type, fields):
Expand Down
5 changes: 3 additions & 2 deletions softioc/pythonSoftIoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ class PythonDevice(object):
@classmethod
def __init_class__(cls):
for name in [
'ai', 'bi', 'longin', 'mbbi', 'stringin',
'ao', 'bo', 'longout', 'mbbo', 'stringout', 'waveform']:
'ai', 'bi', 'longin', 'mbbi', 'stringin', 'int64in',
'ao', 'bo', 'longout', 'mbbo', 'stringout', 'int64out',
'waveform']:
builder = getattr(epicsdbbuilder.records, name)
record = getattr(device, name)
setattr(cls, name, cls.makeRecord(builder, record))
Expand Down
12 changes: 12 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,20 @@
from typing import Any
import pytest

from softioc import builder
from softioc.builder import ClearRecords

in_records = [
builder.aIn,
builder.boolIn,
builder.longIn,
builder.int64In,
builder.mbbIn,
builder.stringIn,
builder.WaveformIn,
builder.longStringIn,
]

requires_cothread = pytest.mark.skipif(
sys.platform.startswith("win"), reason="Cothread doesn't work on windows"
)
Expand Down
Loading
Loading