Syntax
Syntax
viWrite(int vi, byte[] buffer, int count, out int retCount);
Description
Synchronously transfers data to a device. The data to be written is in the buffer represented by buffer. This function returns only when the transfer terminates. Only one synchronous write function can occur at any one time. Parameters
Name |
Dir |
Type |
Description |
vi |
IN |
int |
Unique logical identifier to a session. |
buffer |
IN |
byte[] |
Represents the location of a data block to be sent to device. |
count |
IN |
int |
Specifies number of bytes to be written. |
retCount |
OUT |
out int |
Represents the location of an integer that will be set to the number of bytes actually transferred. |
Return Values
Completion Codes |
Description |
VI_SUCCESS |
Transfer completed. |
Error Codes |
Description |
VI_ERROR_BERR |
Bus error occurred during transfer. |
VI_ERROR_CONN_LOST |
The I/O connection for the given session has been lost. |
VI_ERROR_INP_PROT_VIOL |
Device reported an input protocol error occurred during transfer. |
VI_ERROR_INV_SESSION |
The given session or object reference is invalid (both are the same value). |
VI_ERROR_INV_SETUP |
Unable to start write function because setup is invalid (due to attributes being set to an inconsistent state). |
VI_ERROR_IO |
Unknown I/O error occurred during transfer. |
VI_ERROR_NCIC |
The interface associated with the given vi is not currently the controller in charge. |
VI_ERROR_NLISTENERS |
No Listeners condition is detected (both NRFD and NDAC are deasserted). |
VI_ERROR_NSUP_OPER |
The given vi does not support this function. |
VI_ERROR_RAW_RD_PROT_VIOL |
Violation of raw read protocol occurred during transfer. |
VI_ERROR_RAW_WR_PROT_VIOL |
Violation of raw write protocol occurred during transfer. |
VI_ERROR_RSRC_LOCKED |
Specified operation could not be performed because the resource identified by vi has been locked for this kind of access. |
VI_ERROR_TMO |
Timeout expired before function completed. |
C# Example
public int WriteBytes(int session, int requestCount, byte[] data) { int viError, outCount; viError = visa32.viWrite(session, data, requestCount, out outCount); if (viError < visa32.VI_SUCCESS) { System.Text.StringBuilder error = new System.Text.StringBuilder(256); visa32.viStatusDesc(session, viError, error); throw new ApplicationException(error.ToString()); } return outCount; }
VB .NET Example
Public Function WriteBytes(ByVal session As Integer, _ ByVal requestCount As Integer, _ ByVal data() As Byte) As Integer Dim viError As Integer, outCount As Integer = 0 viError = visa32.viWrite(session, data, requestCount, outCount) If viError < visa32.VI_SUCCESS Then Dim err As System.Text.StringBuilder = New System.Text.StringBuilder(256) visa32.viStatusDesc(session, viError, err) Throw New ApplicationException(err.ToString()) End If Return outCount End Function