MessageBasedInstrument

public protocol MessageBasedInstrument : Instrument

A type that can communicate using the NI-VISA protocol with ASCII strings.

  • The size in bytes to store incoming messages in.

    Declaration

    Swift

    var bufferSize: Int { get set }
  • The buffer where incoming messages are stored in.

    Declaration

    Swift

    var buffer: UnsafeMutableRawBufferPointer { get }
  • Writes the given message to the instrument and then reads data from the given instrument and decodes it to the given type using the given decoder.

    Throws

    One of the following VISAError errors:
    • .invalidSession
    • .unsupportedOperations
    • .resourceLocked
    • .timeout
    • .rawWriteProtocolViolation
    • .rawReadProtocolViolation
    • inputProtocolViolation
    • .outputProtocolViolation
    • .busError
    • .invalidSetup
    • .notControllerInCharge
    • .noListeners
    • .parityError
    • .framingError
    • .overrunError
    • .ioError
    • .connectionLost
    • .couldNotDecode

    Declaration

    Swift

    public func query<T, D>(_ message: String, as type: T.Type, decoder: D, readDelay: TimeInterval = 0.0) throws -> T where T == D.DecodingType, D : VISADecoder

    Parameters

    message

    The message to write to the instrument.

    type

    The type to return.

    decoder

    The decoder to use to decode the data.

    Return Value

    The decoded value.

  • query(_:as:readDelay:) Extension method

    Writes the given message to the instrument and then reads data from the given instrument and decodes it to the given type using the default decoder.

    Throws

    One of the following VISAError errors:
    • .invalidSession
    • .unsupportedOperations
    • .resourceLocked
    • .timeout
    • .rawWriteProtocolViolation
    • .rawReadProtocolViolation
    • inputProtocolViolation
    • .outputProtocolViolation
    • .busError
    • .invalidSetup
    • .notControllerInCharge
    • .noListeners
    • .parityError
    • .framingError
    • .overrunError
    • .ioError
    • .connectionLost
    • .couldNotDecode

    Declaration

    Swift

    public func query<T>(_ message: String, as type: T.Type, readDelay: TimeInterval = 0.0) throws -> T where T : VISADecodable

    Parameters

    message

    The message to write to the instrument.

    type

    The type to return.

    Return Value

    The decoded value.

  • Writes the given message to the instrument and then reads multiple data points from the given instrument and decodes it to the given type using the default decoder.

    Throws

    One of the following VISAError errors:
    • .invalidSession
    • .unsupportedOperations
    • .resourceLocked
    • .timeout
    • .rawWriteProtocolViolation
    • .rawReadProtocolViolation
    • inputProtocolViolation
    • .outputProtocolViolation
    • .busError
    • .invalidSetup
    • .notControllerInCharge
    • .noListeners
    • .parityError
    • .framingError
    • .overrunError
    • .ioError
    • .connectionLost
    • .couldNotDecode

    Declaration

    Swift

    public func query<T>(_ message: String, as type: T.Type, numberOfReads: Int, timeBetweenReads: TimeInterval = 0.5, readDelay: TimeInterval = 0.0) throws -> [T?] where T : VISADecodable

    Parameters

    message

    The message to write to the instrument.

    type

    The type to return.

    Return Value

    The decoded value.

  • Writes the given message to the instrument and then reads data from the given instrument and decodes it to the given type using the given decoder.

    Throws

    One of the following VISAError errors:
    • .invalidSession
    • .unsupportedOperations
    • .resourceLocked
    • .timeout
    • .rawWriteProtocolViolation
    • .rawReadProtocolViolation
    • inputProtocolViolation
    • .outputProtocolViolation
    • .busError
    • .invalidSetup
    • .notControllerInCharge
    • .noListeners
    • .parityError
    • .framingError
    • .overrunError
    • .ioError
    • .connectionLost
    • .couldNotDecode

    Declaration

    Swift

    public func query<T, D>(_ message: String, as type: T.Type, decoder: D, numberOfReads: Int, timeBetweenReads: TimeInterval = 0.5, readDelay: TimeInterval = 0.0) throws -> [T?] where T == D.DecodingType, D : VISADecoder

    Parameters

    message

    The message to write to the instrument.

    type

    The type to return.

    decoder

    The decoder to use to decode the data.

    Return Value

    The decoded value.

  • read(as:decoder:) Extension method

    Reads data from the instrument and decodes it into the given type using the given decoder.

    Throws

    One of the following VISAError errors:
    • .invalidSession
    • .unsupportedOperations
    • .resourceLocked
    • .timeout
    • .rawWriteProtocolViolation
    • .rawReadProtocolViolation
    • .outputProtocolViolation
    • .busError
    • .invalidSetup
    • .notControllerInCharge
    • .noListeners
    • .parityError
    • .framingError
    • .overrunError
    • .ioError
    • .connectionLost
    • .couldNotDecode

    Declaration

    Swift

    public func read<T, D>(as type: T.Type, decoder: D) throws -> T where T == D.DecodingType, D : VISADecoder

    Parameters

    type

    The type to return.

    decoder

    The decoder to use to decode the data.

    Return Value

    The decoded value.

  • read(as:) Extension method

    Reads data from the instrument and decodes it into the given type using the default decoder.

    Throws

    One of the following VISAError errors:
    • .invalidSession
    • .unsupportedOperations
    • .resourceLocked
    • .timeout
    • .rawWriteProtocolViolation
    • .rawReadProtocolViolation
    • .outputProtocolViolation
    • .busError
    • .invalidSetup
    • .notControllerInCharge
    • .noListeners
    • .parityError
    • .framingError
    • .overrunError
    • .ioError
    • .connectionLost
    • .couldNotDecode

    Declaration

    Swift

    public func read<T>(as type: T.Type) throws -> T where T : VISADecodable

    Parameters

    type

    The type to return.

    Return Value

    The decoded value.

  • Repeatedly reads values from an instrument with the specified amount of time between each read and returns an array of these values.

    This function performs numberOfReads number of reads sequentially and returns the results from the read as an array. Each reading is taken with timeDelay number of seconds between them. Each non-nil sequential value in the array is guarenteed to have occurred with timeDelay number of seconds between them. If the instrument’s read could not be completed in timeDelay number of seconds, then the next value(s) in the array are nil, indicating that this time index was skipped. Further, the resuling array will always have numberOfReads elements.

    The resulting array is returned:

    [3, 5, 6, nil, 5]
    

    Throws

    One of the following VISAError errors:
    • .invalidSession
    • .unsupportedOperations
    • .resourceLocked
    • .timeout
    • .rawWriteProtocolViolation
    • .rawReadProtocolViolation
    • .outputProtocolViolation
    • .busError
    • .invalidSetup
    • .notControllerInCharge
    • .noListeners
    • .parityError
    • .framingError
    • .overrunError
    • .ioError
    • .connectionLost
    • .couldNotDecode

    Declaration

    Swift

    public func read<T, D>(as type: T.Type, decoder: D, numberOfReads: Int, timeBetweenReads: TimeInterval = 0.025) throws -> [T?] where T == D.DecodingType, D : VISADecoder

    Parameters

    numberOfReads

    The number of reads to perform.

    type

    The type to be returned from each read.

    decoder

    The decoder to use to decode the data.

    timeDelay

    The amount of time between each successive read operation, defaults to 25 ms.

    Return Value

    An array of the results of the successive read operations.

  • readRaw() Extension method

    Reads data from the instrument and does nothing but convert it straight to a string – doesn’t even strip the termination characters.

    Throws

    One of the following VISAError errors:
    • .invalidSession
    • .unsupportedOperations
    • .resourceLocked
    • .timeout
    • .rawWriteProtocolViolation
    • .rawReadProtocolViolation
    • .outputProtocolViolation
    • .busError
    • .invalidSetup
    • .notControllerInCharge
    • .noListeners
    • .parityError
    • .framingError
    • .overrunError
    • .ioError
    • .connectionLost
    • .couldNotDecode

    Declaration

    Swift

    public func readRaw() throws -> String

    Parameters

    type

    The type to return.

    decoder

    The decoder to use to decode the data.

    Return Value

    The decoded value.

  • readStatusByte() Extension method

    Reads the service request status byte.

    Throws

    TODO: Add errors.

    Declaration

    Swift

    public func readStatusByte() throws -> Data

    Return Value

    The service request byte.

  • assertTrigger() Extension method

    Sends a software trigger to the device.

    According to NI-VISA, you can configure the hardware to wait for a trigger to do anything. This sends that trigger

    Declaration

    Swift

    public func assertTrigger() throws
  • write(_:) Extension method

    Writes the given message to the instrument.

    Throws

    One of the following VISAError errors:
    • .invalidSession
    • .unsupportedOperation
    • .resourceLocked
    • .timeout
    • .rawWriteViolationProtocolViolation
    • .rawReadViolationProtocolViolation
    • .inputProtocolViolation
    • .busError
    • .invalidSetup
    • .notControllerInCharge
    • .noListeners
    • .ioError
    • .connectionLost

    Declaration

    Swift

    public func write(_ message: String) throws

    Parameters

    message

    The message to write.