Sensoray 2410 API User Manual
Page 38

Sensoray 24xx Programming Guide
34
Model 2426 Multi-Function I/O Module
7.5.4 s2426_ComportWrite()
Function:
Enqueue data for transmission on the comport.
Prototype:
u32 s2426_ComportWrite( HSESSION sess, u32 *err, void *buf, int len, BOOL wait );
Returns:
Number of data bytes that were enqueued for transmission. If an error occurs, zero is returned and an error code is
stored in
err
.
Notes:
This function copies data from
buf
to the comport’s transmit FIFO. The comport consumes byte data from the
FIFO output and transmits the bytes onto the comport’s physical interface. Data bytes are transmitted in the same
order they were enqueued. Previously enqueued, but unsent data pending in the FIFO will be transmitted before
new data. This function doesn’t actually transmit data on the comport; it only enqueues data for later transmission.
If
wait
is False and the transmit FIFO would overflow as a result of enqueing all of the new data, only a portion of
the data will be enqueued and the returned value will be less than
len
.
The comport must be attached to the specified session when this function is called. If the comport is closed, the
function will return zero and
err
will be set to
COMPORT_UNATTACHED
.
Example:
// Send a text string to the comport.
char
msg[] = "This is a test\n";
u32 err = ERR_NONE;
u32 len =
sizeof
(msg) - 1;
// exclude NUL char at end of string
u32 nsent = s2426_ComSend( sess, &err, msg, len, TRUE );
if
( nsent == len )
printf( "sent string\n" );
else if
( err != ERR_NONE )
printf( "Error: %s\n", s24xx_ErrorText(err) );
else
printf( "Error: no data sent\n" );
Argument
Description
sess
Session handle obtained from
s24xx_SessionOpen()
.
err
Pointer to error code. See Section 4.3.1 for details.
buf
Pointer to a buffer that contains data to be enqueued for transmission.
len
Number of bytes to be enqueued.
wait
Enable blocking operation. When True, this function will return when data has been
enqueued or upon error. When False, the function will return immediately regardless
of whether data was successfully enqueued.