Skip to content

PTB330¤

Vaisala PTB330 Barometer.

The PTB330 barometer is available with one, two, or three barometer modules.

PTB330 (PTU300) ¤

PTB330(equipment: Equipment)

              flowchart LR
              msl.equipment_resources.vaisala.ptb330.PTB330[PTB330]
              msl.equipment_resources.vaisala.ptu300.PTU300[PTU300]
              msl.equipment.interfaces.serial.Serial[Serial]
              msl.equipment.interfaces.message_based.MessageBased[MessageBased]
              msl.equipment.schema.Interface[Interface]

                              msl.equipment_resources.vaisala.ptu300.PTU300 --> msl.equipment_resources.vaisala.ptb330.PTB330
                                msl.equipment.interfaces.serial.Serial --> msl.equipment_resources.vaisala.ptu300.PTU300
                                msl.equipment.interfaces.message_based.MessageBased --> msl.equipment.interfaces.serial.Serial
                                msl.equipment.schema.Interface --> msl.equipment.interfaces.message_based.MessageBased
                





              click msl.equipment_resources.vaisala.ptb330.PTB330 href "" "msl.equipment_resources.vaisala.ptb330.PTB330"
              click msl.equipment_resources.vaisala.ptu300.PTU300 href "" "msl.equipment_resources.vaisala.ptu300.PTU300"
              click msl.equipment.interfaces.serial.Serial href "" "msl.equipment.interfaces.serial.Serial"
              click msl.equipment.interfaces.message_based.MessageBased href "" "msl.equipment.interfaces.message_based.MessageBased"
              click msl.equipment.schema.Interface href "" "msl.equipment.schema.Interface"
            

Vaisala PTB330 Barometer.

The device manual is available here.

The default settings for the RS232 connection are:

  • Baud rate: 4800
  • Data bits: 7
  • Parity: EVEN

Regular-expression patterns that are used to select this Resource when connect() is called.

manufacturer=r"Vaisala"
model=r"PTB330"
flags=IGNORECASE

Warning

Ensure the device is in STOP or SEND mode before initiating communication.

Parameters:

Name Type Description Default
equipment Equipment

An Equipment instance.

required
Source code in packages/resources/src/msl/equipment_resources/vaisala/ptb330.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
def __init__(self, equipment: Equipment) -> None:
    """Vaisala PTB330 Barometer.

    The device manual is available [here](https://docs.vaisala.com/r/M210855EN-E/en-US){:target="_blank"}.

    The default settings for the RS232 connection are:

    * Baud rate: 4800
    * Data bits: 7
    * Parity: EVEN

    Regular-expression patterns that are used to select this Resource when
    [connect()][msl.equipment.schema.Equipment.connect] is called.
    ```python
    manufacturer=r"Vaisala"
    model=r"PTB330"
    flags=IGNORECASE
    ```

    !!! warning
        Ensure the device is in `STOP` or `SEND` mode before initiating communication.

    Args:
        equipment: An [Equipment][] instance.
    """
    super().__init__(equipment)

device_info property ¤

device_info: dict[str, str]

Returns a dictionary of information about the Vaisala device.

units property ¤

units: dict[str, str]

A dictionary of measured quantities and their associated units.

The units are set by set_units.

check_for_errors ¤

check_for_errors() -> None

Raise an error, if present.

Source code in packages/resources/src/msl/equipment_resources/vaisala/ptu300.py
92
93
94
95
96
97
98
99
def check_for_errors(self) -> None:
    """Raise an error, if present."""
    err = self.query("ERRS")  # List present transmitter errors
    # a PASS or FAIL line is returned from PTB330 modules first
    if err in {"PASS", "FAIL"}:
        err = self.read()
    if err and err != "No errors":
        raise MSLConnectionError(self, err)

get_format ¤

get_format() -> str

Get the currently active formatter string.

Returns:

Type Description
str

The formatter string.

Source code in packages/resources/src/msl/equipment_resources/vaisala/ptu300.py
106
107
108
109
110
111
112
113
def get_format(self) -> str:
    """Get the currently active formatter string.

    Returns:
        The formatter string.
    """
    # The hash symbol "#" is used to set the format, but then appears as a backslash "\\" on the device.
    return self.query("FORM ?")[len("Output format  :") :].replace("\\", "#")

get_reading_str ¤

get_reading_str() -> str

Output the reading once.

Returns:

Type Description
str

A string that follows the format set by set_format.

Source code in packages/resources/src/msl/equipment_resources/vaisala/ptu300.py
115
116
117
118
119
120
121
122
def get_reading_str(self) -> str:
    """Output the reading once.

    Returns:
        A string that follows the format set by
            [set_format][msl.equipment_resources.vaisala.ptu300.PTU300.set_format].
    """
    return self.query("SEND")

set_format ¤

set_format(fmt: str) -> None

Set the format of data output to follow the pattern in the format string.

For example, in the format string 4.3 P " " 3.3 T " " 3.3 RH " " SN " " #r #n, x.y is the number of digits and decimal places of the values; P, T, RH, and SN are placeholders for pressure, temperature, relative humidity, and serial number values; and " ", #r, and #n represent a string constant, carriage-return, and line-feed respectively. Additional allowed modifiers include ERR for error flags, U5 for unit field and (optional) length, TIME for time as [hh:mm:ss], and DATE for date as [yyyy-mm-dd]. For more options, refer to the manual.

Parameters:

Name Type Description Default
fmt str

String representing desired output format.

required
Source code in packages/resources/src/msl/equipment_resources/vaisala/ptu300.py
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
def set_format(self, fmt: str) -> None:
    """Set the format of data output to follow the pattern in the format string.

    For example, in the format string `4.3 P " " 3.3 T " " 3.3 RH " " SN " " #r #n`, `x.y` is the number
    of digits and decimal places of the values; `P`, `T`, `RH`, and `SN` are placeholders for pressure,
    temperature, relative humidity, and serial number values; and `" "`, `#r`, and `#n` represent a string
    constant, carriage-return, and line-feed respectively. Additional allowed modifiers include `ERR` for
    error flags, `U5` for unit field and (optional) length, `TIME` for time as [hh:mm:ss], and `DATE` for
    date as [yyyy-mm-dd]. For more options, refer to the manual.

    Args:
        fmt: String representing desired output format.
    """
    reply = self.query(f"FORM {fmt}")
    if reply.startswith("Output format  :"):  # format is returned by some devices when set
        form = reply[len("Output format  :") :].replace("\\", "#")
    elif "ok" in reply.lower():  # if OK is returned then we need to ask for the format
        form = self.get_format()
    else:  # this is not expected so raise an error
        msg = f"Unexpected reply={reply!r}"
        raise MSLConnectionError(self, msg)

    if form.upper().replace(" ", "") != fmt.upper().replace(" ", ""):
        # the format was not set as specified
        self.check_for_errors()
        msg = f"Could not set format of output. \nExpected: {fmt} \nReceived: {form}."
        raise MSLConnectionError(self, msg)

    self._info["Output format"] = form

set_units ¤

set_units(desired_units: dict[str, str]) -> None

Set units of specified quantities.

Parameters:

Name Type Description Default
desired_units dict[str, str]

Dictionary of quantity (as keys) and their unit (as values) as specified in the instrument manual on pages 12 and 68.

These may include the following (available options depend on the barometer components):

  • Pressure quantity: P, P3h, P1, P2, QNH, QFE, HCP, ...
  • Pressure unit: hPa, psi, inHg, torr, bar, mbar, mmHg, kPa, Pa, mmH2O, inH2O
  • Temperature quantity: T, TP1, TP2, TP3, ...
  • Temperature unit: 'C, 'F, or K (C and F are also supported but are returned as 'C or 'F)
required
Source code in packages/resources/src/msl/equipment_resources/vaisala/ptb330.py
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
def set_units(self, desired_units: dict[str, str]) -> None:  # pyright: ignore[reportImplicitOverride]
    """Set units of specified quantities.

    Args:
        desired_units: Dictionary of *quantity* (as keys) and their *unit* (as values)
            as specified in the instrument manual on pages 12 and 68.

            These may include the following (available options depend on the barometer components):

            * Pressure *quantity*: P, P3h, P1, P2, QNH, QFE, HCP, ...
            * Pressure *unit*: hPa, psi, inHg, torr, bar, mbar, mmHg, kPa, Pa, mmH2O, inH2O
            * Temperature *quantity*: T, TP1, TP2, TP3, ...
            * Temperature *unit*: 'C, 'F, or K (C and F are also supported but are returned as 'C or 'F)
    """
    allowed_quantities_units: dict[str, str] = {}
    _ = self.write("UNIT ??")  # list the available measurement units for the quantities
    for _ in range(6 + len(self._pressure_modules)):
        reply = self.read()
        _q, _u = [qu.strip() for qu in reply.split(":")]
        allowed_quantities_units[_q] = _u

    for quantity, unit in desired_units.items():
        if quantity not in allowed_quantities_units:
            msg = (
                f"{quantity} is not a known quantity on this {self._info['Model']} device.\n"
                f"Please select from: {', '.join(allowed_quantities_units)}"
            )
            raise MSLConnectionError(self, msg)

        if unit in allowed_quantities_units[quantity]:
            if unit in ["C", "F"]:
                unit = "'" + unit  # noqa: PLW2901

            _ = self.write(f"UNIT {quantity} {unit}")
            for _ in range(6 + len(self._pressure_modules)):
                reply = self.read()
                _q, _u = [qu.strip() for qu in reply.split(":")]
                self._units[_q] = _u

            if quantity in self._units:
                if self._units[quantity] != unit:
                    msg = f"{quantity} unit '{unit}' not set correctly. Current units are {self._units}"
                    raise MSLConnectionError(self, msg)
            else:
                msg = f"{quantity} unit '{unit}' not set correctly. Current units are {self._units}"
                raise MSLConnectionError(self, msg)
        else:
            msg = (
                f"{unit} is not an allowed unit. "
                f"Please select from: {', '.join(allowed_quantities_units[quantity].split())}"
            )
            raise MSLConnectionError(self, msg)