NI-XNET API for LabVIEW and C

nxWriteFrame

  • Updated2023-11-11
  • 3 minute(s) read
 nxWriteFrame

nxWriteFrame

Purpose

Writes data to a session as an array of raw bytes.

Format

nxStatus_t nxWriteFrame (

   nxSessionRef_t SessionRef,

   void * Buffer,

   u32 NumberOfBytesForFrames,

   f64 Timeout);

Inputs

nxSessionRef_t SessionRef

The session to write. This session is returned from nxCreateSession. The session mode must be Frame Output Stream Mode, Frame Output Queued Mode, or Frame Output Single-Point Mode.

void * Buffer

Provides the array of bytes, representing frames to transmit.

The raw bytes encode one or more frames using the Raw Frame Format. This frame format is the same for read and write of raw data and also is used for log file examples.

If needed, you can write data for a partial frame. For example, if a complete raw frame is 24 bytes, you can write 12 bytes, then write the next 12 bytes. You typically do this when you are reading raw frame data from a logfile and want to avoid iterating through the data to detect the start and end of each frame.

Note Note  For PDU sessions, the array of bytes represents the payload of the specified PDU only, not that of the entire frame.

For information about which elements of the raw frame are applicable, refer to Raw Frame Format.

The data you write is queued up for transmit on the network. Using the default queue configuration for this mode, you can safely write 1536 frames if you have a sufficiently long timeout. To write more data, refer to the XNET Session Number of Values Unused property to determine the actual amount of queue space available for writing.

For an example of how this data applies to network traffic, refer to Frame Output Stream Mode, Frame Output Queued Mode, or Frame Output Single-Point Mode.

Additionally, you can use nxWriteFrame on any signal or frame input session if it contains CAN Event Remote frames (refer to CAN:TimingType). In this case, it signals an event to transmit those remote frames. The Buffer parameter is ignored, and you can set it to NULL in that case.

u32 NumberOfBytesForFrames

The size (in bytes) of the buffer passed to Buffer. This is used to calculate the number of frames to transmit.

f64 Timeout

The time to wait for the raw data to be queued up for transmit.

The timeout is represented as 64-bit floating-point in units of seconds.

If Timeout is positive, nxWriteFrame waits up to that timeout for space to become available in queues. If the space is not available prior to the timeout, a timeout error is returned.

If Timeout is negative, nxWriteFrame waits indefinitely for space to become available in queues.

If Timeout is 0, nxWriteFrame does not wait and immediately returns with a timeout error if all data cannot be queued. Regardless of the timeout used, if a timeout error occurs, none of the data is queued, so you can attempt to call nxWriteFrame again at a later time with the same data.

If the session mode is Frame Output Single-Point, you must set Timeout to 0.0. Because this mode writes the most recent value of each frame, Timeout does not apply.

Return Value

nxStatus_t

The error code the function returns in the event of an error or warning. A value of 0 indicates success. A positive value indicates a warning. A negative value indicates an error.

Description

The raw bytes encode one or more frames using the Raw Frame Format. The session must use a mode of Frame Output Stream, Frame Output Queued, or Frame Output Single-Point. The raw frame format is protocol independent.

The raw frames are associated to the session's list of frames as follows:

  • Frame Output Stream Mode: Array of all frame values for transmit (list ignored). For LIN, if the payload length is 0, only the header part of the LIN frame is transmitted. If the payload length is nonzero, the header and response parts of the LIN frame are transmitted.
  • Frame Output Queued Mode: Array of frame values to transmit for the single frame specified in the list.
  • Frame Output Single-Point Mode: Array of single frame values, one for each frame specified in the list.
  • Any signal or frame input mode: The Buffer parameter is ignored, and you can set it to NULL. The function transmits an event remote frame.

Log in to get a better experience