| Header | {z88dk}/include/rs232.h |
|---|---|
| Source | {z88dk}/z88dk/libsrc/rs232 |
| Include | #include <rs232.h> |
| Linking | n/a |
| Compile | n/a |
| Comments |
Support for RS232. Not all the platforms are supported, at the moment.
The following program requires a serial terminal connected to the serial port to test.
#include <stdio.h>
#include <stdlib.h>
#include <rs232.h>
char byte[1];
int f;
int main()
{
printf ("%cChecking basic RS232 capabilities...\n",12);
if (rs232_params(RS_BAUD_1200, RS_PAR_NONE) == RS_ERR_OK)
printf (" 1200 baud, N, 8, 1\n");
if (rs232_params(RS_BAUD_2400, RS_PAR_NONE) == RS_ERR_OK)
printf (" 2400 baud, N, 8, 1\n");
if (rs232_params(RS_BAUD_4800, RS_PAR_NONE) == RS_ERR_OK)
printf (" 4800 baud, N, 8, 1\n");
if (rs232_params(RS_BAUD_9600, RS_PAR_NONE) == RS_ERR_OK)
printf (" 9600 baud, N, 8, 1\n");
if (rs232_params(RS_BAUD_19200, RS_PAR_NONE) == RS_ERR_OK)
printf (" 19200 baud, N, 8, 1\n");
printf ("\nInitializing at 1200 baud:");
if (rs232_params(RS_BAUD_1200, RS_PAR_NONE) != RS_ERR_OK) {
printf (" Error setting baud rate. Exiting...\n");
exit(0);
}
if (rs232_init() != RS_ERR_OK) {
printf (" Initialization error. Exiting...\n");
exit(0);
}
printf (" Done.\n");
rs232_put('-');
rs232_put('>');
printf ("\nEchoing 10 bytes to console: ");
for (f=0; f<10; f++) {
while (rs232_get(&byte[0]) != RS_ERR_OK);
//printf ("%c",byte[0]);
fputc_cons (byte[0]);
}
rs232_put('.');
printf ("\n\nClosing RS232 port:\n");
if (rs232_close() != RS_ERR_OK) {
printf (" Error. Exiting...\n");
exit(0);
}
}