• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ni / nixnet-python / #631999863

08 Apr 2025 07:22AM UTC coverage: 67.546% (-0.005%) from 67.551%
#631999863

Pull #302

travis-ci

Pull Request #302: Fix `tox -e mypy` errors with `mypy 1.14.1`

22 of 66 new or added lines in 15 files covered. (33.33%)

10 existing lines in 1 file now uncovered.

4712 of 6976 relevant lines covered (67.55%)

0.68 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

49.29
/nixnet/_session/base.py
1
import ctypes  # type: ignore
1✔
2
import typing  # NOQA: F401
1✔
3
import warnings
1✔
4

5
from nixnet import _ctypedefs
1✔
6
from nixnet import _errors
1✔
7
from nixnet import _funcs
1✔
8
from nixnet import _props
9
from nixnet import _utils
1✔
10
from nixnet import constants
1✔
11
from nixnet import errors
1✔
12
from nixnet import types  # NOQA: F401
1✔
13

1✔
14
from nixnet._session import intf as session_intf
1✔
15
from nixnet._session import j1939 as session_j1939
1✔
16

1✔
17

18
class SessionBase(object):
1✔
19
    """Session base object."""
1✔
20

21
    def __init__(
22
            self,
1✔
23
            database_name,  # type: typing.Text
24
            cluster_name,  # type: typing.Text
25
            list,  # type: typing.Text
1✔
26
            interface_name,  # type: typing.Text
27
            mode,  # type: constants.CreateSessionMode
28
    ):
29
        # type: (...) -> None
30
        """Create an XNET session at run time using named references to database objects.
31

32
        This function creates a session using the named database objects
33
        specified in 'list' from the database named in 'database_name'.
34

35
        This function is intended to be used by session classes that derive from
36
        SessionBase; therefore, it is not public.
37

38
        Args:
39
            database_name: A string representing the XNET database to use for
40
                interface configuration. The database name must use the <alias>
41
                or <filepath> syntax (refer to Databases).
42
            cluster_name: A string representing the XNET cluster to use for
43
                interface configuration. The name must specify a cluster from
44
                the database given in the database_name parameter. If it is left
45
                blank, the cluster is extracted from the list parameter; this is
46
                not allowed for modes of 'constants.CreateSessionMode.FRAME_IN_STREAM'
47
                or 'constants.CreateSessionMode.FRAME_OUT_STREAM'.
48
            list: A list of strings describing signals or frames for the session.
49
                The list syntax depends on the mode. Refer to mode spefic
50
                session classes defined below for 'list' syntax.
51
            interface_name: A string representing the XNET Interface to use for
52
                this session. If Mode is
53
                'constants.CreateSessionMode.SIGNAL_CONVERSION_SINGLE_POINT',
54
                this input is ignored. You can set it to an empty string.
55
            mode: The session mode. See :any:`nixnet._enums.CreateSessionMode`.
56

57
        Returns:
58
            A session base object.
59
        """
60
        self._handle = None  # To satisfy `__del__` in case nx_create_session throws
61
        self._handle = _funcs.nx_create_session(database_name, cluster_name, list, interface_name, mode)
62
        self._intf = session_intf.Interface(self._handle)
63
        self._j1939 = session_j1939.J1939(self._handle)
64

1✔
65
    def __del__(self):
1✔
66
        if self._handle is not None:
1✔
67
            warnings.warn(
1✔
68
                'Session was not explicitly closed before it was destructed. '
69
                'Resources on the device may still be reserved.',
1✔
70
                errors.XnetResourceWarning)
1✔
71

×
72
    def __enter__(self):
73
        return self
74

75
    def __exit__(self, exception_type, exception_value, traceback):
76
        self.close()
1✔
77

1✔
78
    def __eq__(self, other):
79
        if isinstance(other, self.__class__):
1✔
80
            return self._handle == typing.cast(SessionBase, other)._handle
1✔
81
        else:
82
            return NotImplemented
1✔
83

×
84
    def __ne__(self, other):
×
85
        result = self.__eq__(other)
86
        if result is NotImplemented:
×
87
            return result
88
        else:
1✔
89
            return not result
×
90

×
91
    def __hash__(self):
×
92
        return hash(self._handle)
93

×
94
    def __repr__(self):
95
        # type: () -> typing.Text
1✔
96
        return '{}(handle={})'.format(type(self).__name__, self._handle)
×
97

98
    def close(self):
1✔
99
        # type: () -> None
100
        """Close (clear) the XNET session.
×
101

102
        This function stops communication for the session and releases all
1✔
103
        resources the session uses. It internally calls
104
        :any:`nixnet._session.base.SessionBase.stop` with normal scope, so if
105
        this is the last session using the interface, communication stops.
106

107
        You typically use 'close' when you need to close the existing session to
108
        create a new session that uses the same objects. For example, if you
109
        create a session for a frame named frame_a using Frame Output
110
        Single-Point mode, then you create a second session for frame_a using
111
        Frame Output Queued mode, the second call to the session constructor
112
        returns an error, because frame_a can be accessed using only one output
113
        mode. If you call 'close' before the second constructor call, you can
114
        close the previous use of frame_a to create the new session.
115
        """
116
        if self._handle is None:
117
            warnings.warn(
118
                'Attempting to close NI-XNET session but session was already '
119
                'closed', errors.XnetResourceWarning)
120
            return
1✔
121

×
122
        _funcs.nx_clear(self._handle)
123

124
        self._handle = None
×
125

126
    def start(self, scope=constants.StartStopScope.NORMAL):
1✔
127
        # type: (constants.StartStopScope) -> None
128
        """Start communication for the XNET session.
1✔
129

130
        Because the session is started automatically by default, this function
1✔
131
        is optional. This function is for more advanced applications to start
132
        multiple sessions in a specific order. For more information about the
133
        automatic start feature, refer to the
134
        :any:`nixnet._session.base.SessionBase.auto_start` property.
135

136
        For each physical interface, the NI-XNET hardware is divided into two logical units:
137

138
            Sessions: You can create one or more sessions, each of which contains
139
            frames or signals to be transmitted (or received) on the bus.
140

141
            Interface: The interface physically connects to the bus and transmits
142
            (or receives) data for the sessions.
143

144
        You can start each logical unit separately. When a session is started,
145
        all contained frames or signals are placed in a state where they are
146
        ready to communicate. When the interface is started, it takes data from
147
        all started sessions to communicate with other nodes on the bus. For a
148
        specification of the state models for the session and interface, refer
149
        to State Models.
150

151
        If an output session starts before you write data, or you read an input
152
        session before it receives a frame, default data is used. For more
153
        information, refer to the XNET Frame Default Payload and XNET Signal
154
        Default Value properties.
155

156
        Args:
157
            scope(:any:`nixnet._enums.StartStopScope`): Describes the impact of
158
                this operation on the underlying state models for the session
159
                and its interface.
160
        """
161
        _funcs.nx_start(self._handle, scope)  # type: ignore
162

163
    def stop(self, scope=constants.StartStopScope.NORMAL):
164
        # type: (constants.StartStopScope) -> None
165
        """Stop communication for the XNET session.
1✔
166

167
        Because the session is stopped automatically when closed (cleared),
1✔
168
        this function is optional.
169

170
        For each physical interface, the NI-XNET hardware is divided into two logical units:
171

172
            Sessions: You can create one or more sessions, each of which contains
173
            frames or signals to be transmitted (or received) on the bus.
174

175
            Interface: The interface physically connects to the bus and transmits
176
            (or receives) data for the sessions.
177

178
        You can stop each logical unit separately. When a session is stopped,
179
        all contained frames or signals are placed in a state where they are no
180
        longer ready to communicate. When the interface is stopped, it no longer
181
        takes data from sessions to communicate with other nodes on the bus. For
182
        a specification of the state models for the session and interface, refer
183
        to State Models.
184

185
        Args:
186
            scope(:any:`nixnet._enums.StartStopScope`): Describes the impact of
187
                this operation on the underlying state models for the session
188
                and its interface.
189
        """
190
        _funcs.nx_stop(self._handle, scope)  # type: ignore
191

192
    def flush(self):
193
        # type: () -> None
NEW
194
        """Flushes (empties) all XNET session queues.
×
195

196
        With the exception of single-point modes, all sessions use queues to
1✔
197
        store frames. For input modes, the queues store frame values (or
198
        corresponding signal values) that have been received, but not obtained
199
        by calling the read function. For output sessions, the queues store
200
        frame values provided to write function, but not transmitted successfully.
201

202
        :any:`nixnet._session.base.SessionBase.start` and
203
        :any:`nixnet._session.base.SessionBase.stop` have no effect on these
204
        queues. Use 'flush' to discard all values in the session's queues.
205

206
        For example, if you call a write function to write three frames, then
207
        immediately call :any:`nixnet._session.base.SessionBase.stop`, then
208
        call :any:`nixnet._session.base.SessionBase.start` a few seconds
209
        later, the three frames transmit. If you call 'flush' between
210
        :any:`nixnet._session.base.SessionBase.stop` and
211
        :any:`nixnet._session.base.SessionBase.start`, no frames transmit.
212

213
        As another example, if you receive three frames, then call
214
        :any:`nixnet._session.base.SessionBase.stop`, the three frames remains
215
        in the queue. If you call :any:`nixnet._session.base.SessionBase.start`
216
        a few seconds later, then call a read function, you obtain the three
217
        frames received earlier, potentially followed by other frames received
218
        after calling :any:`nixnet._session.base.SessionBase.start`. If you
219
        call 'flush' between :any:`nixnet._session.base.SessionBase.stop` and
220
        :any:`nixnet._session.base.SessionBase.start`, read function returns
221
        only frames received after the calling
222
        :any:`nixnet._session.base.SessionBase.start`.
223
        """
224
        _funcs.nx_flush(self._handle)  # type: ignore
225

226
    def wait_for_transmit_complete(self, timeout=10):
227
        # type: (float) -> None
NEW
228
        """Wait for transmition to complete.
×
229

230
        All frames written for the session have been transmitted on the bus.
1✔
231
        This condition applies to CAN, LIN, and FlexRay. This condition is state
232
        based, and the state is Boolean (true/false).
233

234
        Args:
235
            timeout(float): The maximum amount of time to wait in seconds.
236
        """
237
        _funcs.nx_wait(
238
            self._handle,  # type: ignore
239
            constants.Condition.TRANSMIT_COMPLETE,
240
            0,
NEW
241
            timeout)
×
242

243
    def wait_for_intf_communicating(self, timeout=10):
244
        # type: (float) -> None
245
        """Wait for the interface to begin communication on the network.
246

247
        If a start trigger is configured for the interface, this first waits for
1✔
248
        the trigger. Once the interface is started, this waits for the
249
        protocol's communication state to transition to a value that indicates
250
        communication with remote nodes.
251

252
        After this wait succeeds, calls to 'read_state' will return:
253

254
            :any:`nixnet._enums.CanCommState`: 'constants.CAN_COMM.ERROR_ACTIVE'
255

256
            :any:`nixnet._enums.CanCommState`: 'constants.CAN_COMM.ERROR_PASSIVE'
257

258
            'constants.ReadState.TIME_COMMUNICATING': Valid time for
259
            communication (invalid time of 0 prior)
260

261
        Args:
262
            timeout(float): The maximum amount of time to wait in seconds.
263
        """
264
        _funcs.nx_wait(
265
            self._handle,  # type: ignore
266
            constants.Condition.INTF_COMMUNICATING,
267
            0,
NEW
268
            timeout)
×
269

270
    def wait_for_intf_remote_wakeup(self, timeout=10):
271
        # type: (float) -> None
272
        """Wait for interface remote wakeup.
273

274
        Wait for the interface to wakeup due to activity by a remote node on the
1✔
275
        network. This wait is used for CAN, when you set the 'can_tcvr_state'
276
        property to 'constants.CanTcvrState.SLEEP'. Although the interface
277
        itself is ready to communicate, this places the transceiver into a sleep
278
        state. When a remote CAN node transmits a frame, the transceiver wakes
279
        up, and communication is restored. This wait detects that remote wakeup.
280

281
        This wait is used for LIN when you set 'lin_sleep' property to
282
        'constants.LinSleep.REMOTE_SLEEP' or 'constants.LinSleep.LOCAL_SLEEP'.
283
        When asleep, if a remote LIN ECU transmits the wakeup pattern (break),
284
        the XNET LIN interface detects this transmission and wakes up. This wait
285
        detects that remote wakeup.
286

287
        Args:
288
            timeout(float): The maximum amount of time to wait in seconds.
289
        """
290
        _funcs.nx_wait(
291
            self._handle,  # type: ignore
292
            constants.Condition.INTF_REMOTE_WAKEUP,
293
            0,
NEW
294
            timeout)
×
295

296
    def connect_terminals(self, source, destination):
297
        # type: (typing.Text, typing.Text) -> None
298
        """Connect terminals on the XNET interface.
299

300
        This function connects a source terminal to a destination terminal on
1✔
301
        the interface hardware. The XNET terminal represents an external or
302
        internal hardware connection point on a National Instruments XNET
303
        hardware product. External terminals include PXI Trigger lines for a PXI
304
        card, RTSI terminals for a PCI card, or the single external terminal for
305
        a C Series module. Internal terminals include timebases (clocks) and
306
        logical entities such as a start trigger.
307

308
        The terminal inputs use the Terminal I/O names. Typically, one of the
309
        pair is an internal and the other an external.
310

311
        Args:
312
            source(str): Connection source name.
313
            destination(str): Connection destination name.
314
        """
315
        _funcs.nx_connect_terminals(self._handle, source, destination)  # type: ignore
316

317
    def disconnect_terminals(self, source, destination):
318
        # type: (typing.Text, typing.Text) -> None
NEW
319
        """Disconnect terminals on the XNET interface.
×
320

321
        This function disconnects a specific pair of source/destination terminals
1✔
322
        previously connected with :any:`nixnet._session.base.SessionBase.connect_terminals`.
323

324
        When the final session for a given interface is cleared, NI-XNET
325
        automatically disconnects all terminal connections for that interface.
326
        Therefore, 'disconnect_terminals' is not required for most applications.
327

328
        This function typically is used to change terminal connections
329
        dynamically while an application is running. To disconnect a terminal,
330
        you first must stop the interface using
331
        :any:`nixnet._session.base.SessionBase.stop` with the Interface Only
332
        scope. Then you can call 'disconnect_terminals' and
333
        :any:`nixnet._session.base.SessionBase.connect_terminals` to adjust
334
        terminal connections. Finally, you can call
335
        :any:`nixnet._session.base.SessionBase.start` with the Interface Only
336
        scope to restart the interface.
337

338
        You can disconnect only a terminal that has been previously connected.
339
        Attempting to disconnect a nonconnected terminal results in an error.
340

341
        Args:
342
            source(str): Connection source name.
343
            destination(str): Connection destination name.
344
        """
345
        _funcs.nx_disconnect_terminals(self._handle, source, destination)  # type: ignore
346

347
    def change_lin_schedule(self, sched_index):
348
        # type: (int) -> None
NEW
349
        """Writes communication states of an XNET session.
×
350

351
        This function writes a request for the LIN interface to change
1✔
352
        the running schedule.
353

354
        According to the LIN protocol, only the master executes schedules,
355
        not slaves. If the
356
        :any:`nixnet._session.intf.Interface.lin_master` property is false (slave),
357
        this write function implicitly sets that property to true (master). If the
358
        interface currently is running as a slave, this write returns an error,
359
        because it cannot change to master while running.
360

361
        Args:
362
            sched_index(int): Index to the schedule table that the LIN master executes.
363

364
                The schedule tables are sorted the way they are returned from the
365
                database with the `nixnet.database._cluster.Cluster.lin_schedules`
366
                property.
367
        """
368
        _funcs.nx_write_state(
369
            self._handle,  # type: ignore
370
            constants.WriteState.LIN_SCHEDULE_CHANGE,
371
            _ctypedefs.u32(sched_index))
372

1✔
373
    def change_lin_diagnostic_schedule(self, schedule):
374
        # type: (constants.LinDiagnosticSchedule) -> None
375
        """Writes communication states of an XNET session.
376

377
        This function writes a request for the LIN interface to change
1✔
378
        the diagnostic schedule.
379

380
        Args:
381
            schedule(:any:`nixnet._enums.LinDiagnosticSchedule`): Diagnostic schedule
382
                that the LIN master executes.
383
        """
384
        _funcs.nx_write_state(
385
            self._handle,  # type: ignore
386
            constants.WriteState.LIN_DIAGNOSTIC_SCHEDULE_CHANGE,
387
            _ctypedefs.u32(schedule.value))
NEW
388

×
389
    @property
390
    def time_current(self):
391
        # type: () -> int
392
        """int: Current interface time."""
393
        state_value_ctypes = _ctypedefs.nxTimestamp_t()
1✔
394
        state_size = ctypes.sizeof(state_value_ctypes)
395
        _funcs.nx_read_state(
396
            self._handle,  # type: ignore
397
            constants.ReadState.TIME_CURRENT,
×
398
            state_size,
×
399
            ctypes.pointer(state_value_ctypes))
×
400
        time = state_value_ctypes.value
401
        return time
402

403
    @property
404
    def time_start(self):
×
405
        # type: () -> int
×
406
        """int: Time the interface was started."""
407
        state_value_ctypes = _ctypedefs.nxTimestamp_t()
1✔
408
        state_size = ctypes.sizeof(state_value_ctypes)
409
        _funcs.nx_read_state(
410
            self._handle,  # type: ignore
411
            constants.ReadState.TIME_START,
×
412
            state_size,
×
413
            ctypes.pointer(state_value_ctypes))
×
414
        time = state_value_ctypes.value
415
        if time == 0:
416
            # The interface is not communicating.
417
            _errors.check_for_error(constants.Err.SESSION_NOT_STARTED.value)
418
        return time
×
419

×
420
    @property
421
    def time_communicating(self):
×
422
        # type: () -> int
×
423
        """int: Time the interface started communicating.
424

1✔
425
        The time is usually later than ``time_start`` because the interface
426
        must undergo a communication startup procedure.
427
        """
428
        state_value_ctypes = _ctypedefs.nxTimestamp_t()
429
        state_size = ctypes.sizeof(state_value_ctypes)
430
        _funcs.nx_read_state(
431
            self._handle,  # type: ignore
432
            constants.ReadState.TIME_COMMUNICATING,
×
433
            state_size,
×
434
            ctypes.pointer(state_value_ctypes))
×
435
        time = state_value_ctypes.value
436
        if time == 0:
437
            # The interface is not communicating.
438
            _errors.check_for_error(constants.Err.SESSION_NOT_STARTED.value)
439
        return time
×
440

×
441
    @property
442
    def state(self):
×
443
        # type: () -> constants.SessionInfoState
×
444
        """:any:`nixnet._enums.SessionInfoState`: Session running state."""
445
        state_value_ctypes = _ctypedefs.u32()
1✔
446
        state_size = ctypes.sizeof(state_value_ctypes)
447
        _funcs.nx_read_state(
448
            self._handle,  # type: ignore
449
            constants.ReadState.SESSION_INFO,
×
450
            state_size,
×
451
            ctypes.pointer(state_value_ctypes))
×
452
        state = state_value_ctypes.value
453
        return constants.SessionInfoState(state)
454

455
    @property
456
    def can_comm(self):
×
457
        # type: () -> types.CanComm
×
458
        """:any:`nixnet.types.CanComm`: CAN Communication state"""
459
        state_value_ctypes = _ctypedefs.u32()
1✔
460
        state_size = ctypes.sizeof(state_value_ctypes)
461
        _funcs.nx_read_state(
462
            self._handle,  # type: ignore
463
            constants.ReadState.CAN_COMM,
×
464
            state_size,
×
465
            ctypes.pointer(state_value_ctypes))
×
466
        bitfield = state_value_ctypes.value
467
        return _utils.parse_can_comm_bitfield(bitfield)
468

469
    @property
470
    def lin_comm(self):
×
471
        # type: () -> types.LinComm
×
472
        """:any:`nixnet.types.LinComm`: LIN Communication state"""
473
        state_value_ctypes = (_ctypedefs.u32 * 2)()  # type: ignore
1✔
474
        state_size = ctypes.sizeof(state_value_ctypes)
475
        _funcs.nx_read_state(
476
            self._handle,  # type: ignore
477
            constants.ReadState.LIN_COMM,
×
478
            state_size,
×
479
            ctypes.pointer(state_value_ctypes))
×
480
        first = state_value_ctypes[0].value
481
        second = state_value_ctypes[1].value
482
        return _utils.parse_lin_comm_bitfield(first, second)
483

484
    def check_fault(self):
×
485
        # type: () -> None
×
486
        """Check for an asynchronous fault.
×
487

488
        A fault is an error that occurs asynchronously to the NI-XNET
1✔
489
        application calls. The fault cause may be related to network
490
        communication, but it also can be related to XNET hardware, such as a
491
        fault in the onboard processor. Although faults are extremely rare,
492
        nxReadState provides a detection method distinct from the status of
493
        NI-XNET function calls, yet easy to use alongside the common practice
494
        of checking the communication state.
495
        """
496
        state_value_ctypes = _ctypedefs.u32()
497
        state_size = ctypes.sizeof(state_value_ctypes)
498
        fault = _funcs.nx_read_state(
499
            self._handle,  # type: ignore
500
            constants.ReadState.SESSION_INFO,
×
501
            state_size,
×
502
            ctypes.pointer(state_value_ctypes))
×
503
        _errors.check_for_error(fault)
504

505
    @property
506
    def intf(self):
507
        # type: () -> session_intf.Interface
×
508
        """:any:`nixnet._session.intf.Interface`: Returns the Interface configuration object for the session."""
509
        return self._intf
1✔
510

511
    @property
512
    def j1939(self):
513
        # type: () -> session_j1939.J1939
1✔
514
        """:any:`nixnet._session.j1939.J1939`: Returns the J1939 configuration object for the session."""
515
        return self._j1939
1✔
516

517
    @property
518
    def application_protocol(self):
519
        # type: () -> constants.AppProtocol
×
520
        """:any:`nixnet._enums.AppProtocol`: This property returns the application protocol that the session uses.
521

1✔
522
        The database used with the session determines the application protocol.
523
        """
524
        return constants.AppProtocol(
525
            _props.get_session_application_protocol(self._handle))  # type: ignore
526

527
    @property
NEW
528
    def auto_start(self):
×
529
        # type: () -> bool
530
        """bool: Automatically starts the output session on the first call to the appropriate write function.
531

1✔
532
        For input sessions, start always is performed within the first call to
533
        the appropriate read function (if not already started using
534
        :any:`nixnet._session.base.SessionBase.start`). This is done
535
        because there is no known use case for reading a stopped input session.
536

537
        For output sessions, as long as the first call to the appropriate write
538
        function contains valid data, you can leave this property at its default
539
        value of true. If you need to call the appropriate write function
540
        multiple times prior to starting the session, or if you are starting
541
        multiple sessions simultaneously, you can set this property to false.
542
        After calling the appropriate write function as desired, you can call
543
        :any:`nixnet._session.base.SessionBase.start` to start the session(s).
544

545
        When automatic start is performed, it is equivalent to
546
        :any:`nixnet._session.base.SessionBase.start` with scope set to Normal.
547
        This starts the session itself, and if the interface is not already
548
        started, it starts the interface also.
549
        """
550
        return _props.get_session_auto_start(self._handle)  # type: ignore
551

552
    @auto_start.setter
553
    def auto_start(self, value):
NEW
554
        # type: (bool) -> None
×
555
        _props.set_session_auto_start(self._handle, value)  # type: ignore
556

1✔
557
    @property
558
    def cluster_name(self):
NEW
559
        # type: () -> typing.Text
×
560
        """str: This property returns the cluster (network) name used with the session."""
561
        return _props.get_session_cluster_name(self._handle)  # type: ignore
1✔
562

563
    @property
564
    def database_name(self):
NEW
565
        # type: () -> typing.Text
×
566
        """str: This property returns the database name used with the session."""
567
        return _props.get_session_database_name(self._handle)  # type: ignore
1✔
568

569
    @property
570
    def mode(self):
NEW
571
        # type: () -> constants.CreateSessionMode
×
572
        """:any:`nixnet._enums.CreateSessionMode`: This property returns the mode associated with the session.
573

1✔
574
        For more information, refer to :any:`nixnet._enums.CreateSessionMode`.
575
        """
576
        return constants.CreateSessionMode(
577
            _props.get_session_mode(self._handle))  # type: ignore
578

579
    @property
NEW
580
    def num_pend(self):
×
581
        # type: () -> int
582
        """int: This property returns the number of values (frames or signals) pending for the session.
583

1✔
584
        For input sessions, this is the number of frame/signal values available
585
        to the appropriate read function. If you call the appropriate read
586
        function with number to read of this number and timeout of 0.0, the
587
        appropriate read function should return this number of values successfully.
588

589
        For output sessions, this is the number of frames/signal values provided
590
        to the appropriate write function but not yet transmitted onto the network.
591

592
        Stream frame sessions using FlexRay or CAN FD protocol may use a
593
        variable size of frames. In these cases, this property assumes the
594
        largest possible frame size. If you use smaller frames, the real number
595
        of pending values might be higher.
596

597
        The largest possible frames sizes are:
598

599
            CAN FD: 64 byte payload.
600

601
            FlexRay: The higher value of the frame size in the static segment
602
            and the maximum frame size in the dynamic segment. The XNET Cluster
603
            FlexRay Payload Length Maximum property provides this value.
604
        """
605
        return _props.get_session_num_pend(self._handle)  # type: ignore
606

607
    @property
608
    def num_unused(self):
NEW
609
        # type: () -> int
×
610
        """int: This property returns the number of values (frames or signals) unused for the session.
611

1✔
612
        If you get this property prior to starting the session, it provides the
613
        size of the underlying queue(s). Contrary to the Queue Size property,
614
        this value is in number of frames for Frame I/O, not number of bytes;
615
        for Signal I/O, it is the number of signal values in both cases. After
616
        start, this property returns the queue size minus the
617
        :any:`Number of Values Pending <nixnet._session.base.SessionBase.num_pend>`
618
        property.
619

620
        For input sessions, this is the number of frame/signal values unused in
621
        the underlying queue(s).
622

623
        For output sessions, this is the number of frame/signal values you can
624
        provide to a subsequent call to the appropriate write function. If you
625
        call the appropriate write function with this number of values and
626
        timeout of 0.0, it should return success.
627

628
        Stream frame sessions using FlexRay or CAN FD protocol may use a
629
        variable size of frames. In these cases, this property assumes the
630
        largest possible frame size. If you use smaller frames, the real number
631
        of pending values might be higher.
632

633
        The largest possible frames sizes are:
634

635
            CAN FD: 64 byte payload.
636

637
            FlexRay: The higher value of the frame size in the static segment
638
            and the maximum frame size in the dynamic segment. The XNET Cluster
639
            FlexRay Payload Length Maximum property provides this value.
640
        """
641
        return _props.get_session_num_unused(self._handle)  # type: ignore
642

643
    @property
644
    def protocol(self):
NEW
645
        # type: () -> constants.Protocol
×
646
        """:any:`nixnet._enums.Protocol`: This property returns the protocol that the interface in the session uses."""
647
        return constants.Protocol(
1✔
648
            _props.get_session_protocol(self._handle))  # type: ignore
649

650
    @property
NEW
651
    def queue_size(self):
×
652
        # type: () -> int
653
        """int: Get or set queue size.
654

1✔
655
        For output sessions, queues store data passed to the appropriate
656
        write function and not yet transmitted onto the network. For input
657
        sessions, queues store data received from the network and not yet
658
        obtained using the appropriate read function.
659

660
        For most applications, the default queue sizes are sufficient. You can
661
        write to this property to override the default. When you write (set)
662
        this property, you must do so prior to the first session start. You
663
        cannot set this property again after calling
664
        :any:`nixnet._session.base.SessionBase.stop`.
665

666
        For signal I/O sessions, this property is the number of signal values
667
        stored. This is analogous to the number of values you use with the
668
        appropriate read or write function.
669

670
        For frame I/O sessions, this property is the number of bytes of frame
671
        data stored.
672

673
        For standard CAN or LIN frame I/O sessions, each frame uses exactly 24
674
        bytes. You can use this number to convert the Queue Size (in bytes)
675
        to/from the number of frame values.
676

677
        For CAN FD and FlexRay frame I/O sessions, each frame value size can
678
        vary depending on the payload length. For more information, refer to
679
        Raw Frame Format.
680

681
        For Signal I/O XY sessions, you can use signals from more than one frame.
682
        Within the implementation, each frame uses a dedicated queue. According
683
        to the formulas below, the default queue sizes can be different for each
684
        frame. If you read the default Queue Size property for a Signal Input XY
685
        session, the largest queue size is returned, so that a call to the
686
        appropriate read function of that size can empty all queues. If you
687
        read the default Queue Size property for a Signal Output XY session, the
688
        smallest queue size is returned, so that a call to the appropriate write
689
        function of that size can succeed when all queues are empty. If you
690
        write the Queue Size property for a Signal I/O XY session, that size is
691
        used for all frames, so you must ensure that it is sufficient for the
692
        frame with the fastest transmit time.
693

694
        For Signal I/O Waveform sessions, you can use signals from more than one
695
        frame. Within the implementation, each frame uses a dedicated queue. The
696
        Queue Size property does not represent the memory in these queues, but
697
        rather the amount of time stored. The default queue allocations store
698
        Application Time worth of resampled signal values. If you read the
699
        default Queue Size property for a Signal I/O Waveform session, it
700
        returns Application Time multiplied by the time Resample Rate. If you
701
        write the Queue Size property for a Signal I/O Waveform session, that
702
        value is translated from a number of samples to a time, and that time is
703
        used to allocate memory for each queue.
704

705
        For Single-Point sessions (signal or frame), this property is ignored.
706
        Single-Point sessions always use a value of 1 as the effective queue size.
707
        """
708
        return _props.get_session_queue_size(self._handle)  # type: ignore
709

710
    @queue_size.setter
711
    def queue_size(self, value):
NEW
712
        # type: (int) -> None
×
713
        _props.set_session_queue_size(self._handle, value)  # type: ignore
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc