Sensoray 2410 API User Manual
Page 39
Sensoray 24xx Programming Guide
35
Model 2426 Multi-Function I/O Module
7.5.5 s2426_ComportIoctl()
Function:
Execute an I/O control operation on the comport.
Prototype:
BOOL s2426_ComportIoctl( HSESSION sess, u32 *err, u32 ioctl, void *val );
Returns:
True if the operation was successful, otherwise False is returned and
err
will contain the associated error code.
Notes:
Some operations (
BAUDRATE
,
PARITY
,
DATABITS
, and
STOPBITS
) make use of the
val
argument, while others
(
TXBREAKON
,
TXBREAKOFF
and
RXFLUSH
) don’t. For those that do, setting val to a non-zero value and then calling
this function will cause the comport’s control setting to change to the target value. For example, the comport’s baud
rate can be changed by storing the desired baud rate value in
val
and then calling this function with the operation
type set to
BAUDRATE
.
The current setting will remain in effect if
val
contains zero when this function is called. This can be used to read a
setting without making changes to it. The comport’s current setting, whether new or unchanged, is returned in
val
.
Upon returning,
val
indicates the actual setting in effect on the comport, which can differ from the desired setting
if it is a non-standard value. For example, attempting to set the baud rate to 9625 will result in it being set to 9600.
TXBREAKON
and
TXBREAKOFF
are used to begin and end a line break condition on the comport transmitter.
RXFLUSH
may be used to “reset” the receive pipeline to compensate for a receive error (e.g., a parity, framing or
overrun). When a receive error occurs, the contents of the receiver pipeline should be considered corrupt and
therefore all queued data should be discarded.
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:
// Set baud rate to 9600.
u32 err = ERR_NONE;
u32 val = 9600;
if ( !
s2426_ComportIoctl( sess, &err, BAUDRATE, &val ) )
printf( "Error: %s\n", s24xx_ErrorText(err) );
else
printf( "Baud rate was set to %d\n", val );
Argument
Description
sess
Session handle obtained from
s24xx_SessionOpen()
.
err
Pointer to error code. See Section 4.3.1 for details.
ioctl
Operation type code. Specify one of these values:
BAUDRATE
Set/get baud rate
PARITY
Set/get parity type
DATABITS
Set/get character size in bits
STOPBITS
Set/get number of stop bits per character
TXBREAKON
Begin transmit break (
val
not used)
TXBREAKOFF
End transmit break (
val
not used)
RXFLUSH
Flush receive pipeline (
val
not used)
val
Pointer to storage for the operation’s value. Before calling this function, set
val
to the
desired new value, or to zero to keep the current comport setting. Upon return,
val
contains
the current setting (in the case of
BAUDRATE
,
PARITY
,
DATABITS
and
STOPBITS
).