serial: |
Identifies which serial port to use. On Windows machines, this will be
'COM1', 'COM3', etc. On Unix machines, it will be the name of the
serial port device file, such as '/dev/ttyS1'.
|
baud: |
Pass a constant which denotes the baud rate at which you want to connect. Note
that you do not pass the actual baud rate (eg the number 9600); you must
pass a pre-defined constant which represents the baud rate you desire. See the
API reference
page for a complete list of baud rate constants. Also note that you must pass
the baud rate that matches the currently set baud rate on the actual serial board
(set with jumpers) in order for the computer and serial board to successfully
communicate. In other words, the serial board will not automatically
adjust its baud rate to the value you specify here.
|
result: |
This is a pointer to the integer variable where the result code for this
function will be stored. Since the return value of the function
is a handle to the serial board, this variable is used to give you access to
the actual error code if an error occurs. If the function succeeds,
a value of zero will be written to result. Also note that if you
are not interested in the actual error code, you may pass a NULL pointer here.
|
/* declare the variables */
ser_sr24 handle;
int result;
/* attempt to open the board */
handle = ser_sr24_open("COM1", SER_9600, &result);
/* see if the board was successfully opened */
if(handle == 0) /* if we got a NULL pointer */
{
switch(result)
{
case SER_SERIAL_ERROR:
printf("Oops! COM1 is busy or doesn't exist\n");
break;
case SER_DEVICE_NOTFOUND:
printf("Is the serial board turned on?\n");
break;
default:
printf("The following error occurred: %s\n", ser_sr24_error_string(result));
break;
}
}
else
{
printf("Successfully opened the board.");
}