5 comport functions – Sensoray 2410 API User Manual
Page 36

Sensoray 24xx Programming Guide
32
Model 2426 Multi-Function I/O Module
7.5 Comport Functions
7.5.1 s2426_ComportOpen()
Function:
Configure the comport and attach it to the specified session.
Prototype:
BOOL s2426_ComportOpen( HSESSION sess, u32 *err, u32 br, u32 parity, u32 databits, u32 stopbits );
Returns:
True if the operation was successful, otherwise False is returned and
err
will contain the associated error code.
Notes:
The comport must be attached to a session to enable the client to send or receive data over the module’s serial
communication interface. If the comport is already attached to another session, this function will fail and the error
code will be set to
ERR_COMPORTATTACHED
.
Example:
// Attach session to comport and set to 9600 baud, no parity, 8 data, 1 stop.
u32 err = ERR_NONE;
if ( !
s2426_ComportOpen( sess, &err, 9600, COMPORT_PARITY_NONE, 8, 1 ) )
printf( "Error: %s\n", s24xx_ErrorText(err) );
7.5.2 s2426_ComportClose()
Function:
Close comport and detach it from session.
Prototype:
BOOL s2426_ComportClose( HSESSION sess, u32 *err );
Returns:
True if the operation was successful, otherwise False is returned and
err
will contain the associated error code.
Notes:
This function flushes the target comport’s serial transmitter and receiver queues and detaches the comport from the
current session.
The comport must be attached to the session when this function is called. If the comport is closed, the function will
return False and
err
will be set to
COMPORT_UNATTACHED
.
Example:
// Close comport.
u32 err = ERR_NONE;
if ( !
s2426_ComportClose( sess, &err ) )
printf( "Problem closing comport\n" );
Argument
Description
sess
Session handle obtained from
s24xx_SessionOpen()
.
err
Pointer to error code. See Section 4.3.1 for details.
br
Baud rate. Specify any standard value from 110 to 115200.
parity
Parity type. Specify one of these values:
COMPORT_PARITY_NONE
COMPORT_PARITY_ODD
COMPORT_PARITY_EVEN
databits
Number of data bits per character: 5 to 8.
stopbits
Number of stop bits per character: 1 or 2.
Argument
Description
sess
Session handle obtained from
s24xx_SessionOpen()
.
err
Pointer to error code. See Section 4.3.1 for details.