/* * urecv.c -- receive text from RS-232 serial connexion * last modification: may 12, 2006 * * Copyright (c) 2006 David HENRY * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, * copy, modify, merge, publish, distribute, sublicense, and/or * sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include #include #include "uart.h" int main (int argc, const char *argv[]) { int port; if (argc != 2) { fprintf (stderr, "usage:\n%s \n", argv[0]); return EXIT_FAILURE; } /* get port from program argument */ switch (atoi (argv[1])) { case 1: port = COM1; break; case 2: port = COM2; break; case 3: port = COM3; break; case 4: port = COM4; break; default: fprintf (stderr, "bad port selected!\n"); return EXIT_FAILURE; } /* setup RS-232 connection */ uart_init (port); uart_set_baud_rate (9600); uart_set_word_lenght (8); uart_set_stop_bits (1); uart_set_parity (UART_EVEN_PARITY); printf ("waiting for data on port %i (%03x)\n", atoi (argv[1]), port); while (1) { /* test if there is a character in the receive buffer/fifo */ if (uart_test_receive_char ()) { /* get the character and print it to standard output */ char ch = uart_read_char (); printf ("%c", ch); } } /* exit properly */ uart_release (); return 0; }

AltStyle によって変換されたページ (->オリジナル) /