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 }
-
query(_:as:decoder:readDelay:)Extension methodWrites 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 followingVISAErrorerrors:.invalidSession.unsupportedOperations.resourceLocked.timeout.rawWriteProtocolViolation.rawReadProtocolViolationinputProtocolViolation.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 : VISADecoderParameters
messageThe message to write to the instrument.
typeThe type to return.
decoderThe decoder to use to decode the data.
Return Value
The decoded value.
-
query(_:as:readDelay:)Extension methodWrites 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 followingVISAErrorerrors:.invalidSession.unsupportedOperations.resourceLocked.timeout.rawWriteProtocolViolation.rawReadProtocolViolationinputProtocolViolation.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 : VISADecodableParameters
messageThe message to write to the instrument.
typeThe type to return.
Return Value
The decoded value.
-
query(_:as:numberOfReads:timeBetweenReads:readDelay:)Extension methodWrites 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 followingVISAErrorerrors:.invalidSession.unsupportedOperations.resourceLocked.timeout.rawWriteProtocolViolation.rawReadProtocolViolationinputProtocolViolation.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 : VISADecodableParameters
messageThe message to write to the instrument.
typeThe type to return.
Return Value
The decoded value.
-
query(_:as:decoder:numberOfReads:timeBetweenReads:readDelay:)Extension methodWrites 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 followingVISAErrorerrors:.invalidSession.unsupportedOperations.resourceLocked.timeout.rawWriteProtocolViolation.rawReadProtocolViolationinputProtocolViolation.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 : VISADecoderParameters
messageThe message to write to the instrument.
typeThe type to return.
decoderThe decoder to use to decode the data.
Return Value
The decoded value.
-
read(as:decoder:)Extension methodReads data from the instrument and decodes it into the given type using the given decoder.
Throws
One of the followingVISAErrorerrors:.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 : VISADecoderParameters
typeThe type to return.
decoderThe decoder to use to decode the data.
Return Value
The decoded value.
-
read(as:)Extension methodReads data from the instrument and decodes it into the given type using the default decoder.
Throws
One of the followingVISAErrorerrors:.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 : VISADecodableParameters
typeThe type to return.
Return Value
The decoded value.
-
read(as:decoder:numberOfReads:timeBetweenReads:)Extension methodRepeatedly reads values from an instrument with the specified amount of time between each read and returns an array of these values.
This function performs
numberOfReadsnumber of reads sequentially and returns the results from the read as an array. Each reading is taken withtimeDelaynumber of seconds between them. Each non-nil sequential value in the array is guarenteed to have occurred withtimeDelaynumber of seconds between them. If the instrument’s read could not be completed intimeDelaynumber of seconds, then the next value(s) in the array arenil, indicating that this time index was skipped. Further, the resuling array will always havenumberOfReadselements.The resulting array is returned:
[3, 5, 6, nil, 5]Throws
One of the followingVISAErrorerrors:.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 : VISADecoderParameters
numberOfReadsThe number of reads to perform.
typeThe type to be returned from each read.
decoderThe decoder to use to decode the data.
timeDelayThe 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 methodReads 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 followingVISAErrorerrors:.invalidSession.unsupportedOperations.resourceLocked.timeout.rawWriteProtocolViolation.rawReadProtocolViolation.outputProtocolViolation.busError.invalidSetup.notControllerInCharge.noListeners.parityError.framingError.overrunError.ioError.connectionLost.couldNotDecode
Declaration
Swift
public func readRaw() throws -> StringParameters
typeThe type to return.
decoderThe decoder to use to decode the data.
Return Value
The decoded value.
-
readStatusByte()Extension methodReads the service request status byte.
Throws
TODO: Add errors.Declaration
Swift
public func readStatusByte() throws -> DataReturn Value
The service request byte.
-
assertTrigger()Extension methodSends 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 methodWrites the given message to the instrument.
Throws
One of the followingVISAErrorerrors:.invalidSession.unsupportedOperation.resourceLocked.timeout.rawWriteViolationProtocolViolation.rawReadViolationProtocolViolation.inputProtocolViolation.busError.invalidSetup.notControllerInCharge.noListeners.ioError.connectionLost
Declaration
Swift
public func write(_ message: String) throwsParameters
messageThe message to write.
MessageBasedInstrument Protocol Reference