# longMbbRecords

`longMbbRecords` (long multi-bit binary records) is an EPICS module that provides the `mbbi30` and `mbbo30` record types, which support up to 30 states, compared to the 16 states in the standard `mbbi` and `mbbo`. For more information on the standard records, see:

- [mbbi Record](https://epics.anl.gov/base/R7-0/6-docs/mbbiRecord.html)
- [mbbo Record](https://epics.anl.gov/base/R7-0/6-docs/mbboRecord.html)

## Table of Contents
1. [State Fields](#state-fields)
2. [Device Support](#device-support)
3. [Usage](#usage)
4. [Limitations](#limitations)

## State Fields

The `mbbi30` and `mbbo30` records support 30 states. Each state is associated with the following fields:

| State # | Raw Value | Enum String | State Severity |
| ------- | --------- | ----------- | -------------- |
| 0       | ZRVL      | ZRST        | ZRSV           |
| 1       | ONVL      | ONST        | ONSV           |
| 2       | TWVL      | TWST        | TWSV           |
| 3       | THVL      | THST        | THSV           |
| 4       | FRVL      | FRST        | FRSV           |
| 5       | FVVL      | FVST        | FVSV           |
| 6       | SXVL      | SXST        | SXSV           |
| 7       | SVVL      | SVST        | SVSV           |
| 8       | EIVL      | EIST        | EISV           |
| 9       | NIVL      | NIST        | NISV           |
| 10      | TEVL      | TEST        | TESV           |
| 11      | ELVL      | ELST        | ELSV           |
| 12      | TVVL      | TVST        | TVSV           |
| 13      | TTVL      | TTST        | TTSV           |
| 14      | FTVL      | FTST        | FTSV           |
| 15      | FFVL      | FFST        | FFSV           |
| 16      | STVL      | STST        | STSV           |
| 17      | VTVL      | VTST        | VTSV           |
| 18      | ETVL      | ETST        | ETSV           |
| 19      | NTVL      | NTST        | NTSV           |
| 20      | WTVL      | WTST        | WTSV           |
| 21      | WOVL      | WOST        | WOSV           |
| 22      | WWVL      | WWST        | WWSV           |
| 23      | WHVL      | WHST        | WHSV           |
| 24      | WFVL      | WFST        | WFSV           |
| 25      | WIVL      | WIST        | WISV           |
| 26      | WSVL      | WSST        | WSSV           |
| 27      | WVVL      | WVST        | WVSV           |
| 28      | WEVL      | WEST        | WESV           |
| 29      | WNVL      | WNST        | WNSV           |

> Note: The number of states is limited to **30** based on `DB_MAX_CHOICES`, a constant in EPICS base that defines the maximum number of choices for an enum field.

In addition, the `STRV` field stores the enum string corresponding to the current value of `VAL`.

## Device Support

Two soft device support modules are provided for `mbbi30` and `mbbo30`: **Soft Channel** and **Raw Soft Channel**.

### mbbi30

- **Soft Channel**: Reads value directly into `VAL`.
- **Raw Soft Channel**: Reads value into `RVAL` and converts it into `VAL` by matching `RVAL` to one of the state value fields, `ZRVL-WNVL`.

### mbbo30

- **Soft Channel**: Writes value of `VAL` to output link.
- **Raw Soft Channel**: Converts `VAL` to `RVAL` and writes it to the output link, setting `RVAL` to the corresponding state value from the `ZRVL-WNVL` fields.

## Usage

To include `longMbbRecords` in your EPICS application:

1. Include the path to the `longMbbRecords` module in your `configure/RELEASE`:

    ```bash
    LONGMBBRECORDS_MODULE_VERSION = R0.0.1
    LONGMBBRECORDS = $(EPICS_MODULES)/longMbbRecords/$(LONGMBBRECORDS_MODULE_VERSION)
    ```

2. Include `longMbbSupport.dbd` and link in `longMbbSupport` in your `src/Makefile`:

    ```bash
    {appName}_DBD += longMbbSupport.dbd
    {appName}_LIBS += longMbbSupport
    ```

3. Use `mbbi30` or `mbbo30` in your database file with the appropriate device support:

    ```text
    record(mbbo30, "EXAMPLE:STATE") {
        field(DTYP, "Soft Channel")
        field(ONST, "One")
        field(TWST, "Two")
        ...
    }
    ```

## Limitations

1. **Graphical clients**: 
   - Labels are not displayed correctly when `VAL >= 16`.
       - **Workaround**: Use the `STRV` field.
   - Combo boxes can only display up to 16 states.

2. **Channel access**: The `caput` command refuses to write when the argument is an enum string corresponding to a state index of 16 or greater.
