source:
ntrip/trunk/BNC/src/test_serial.cpp@
10911
| Last change on this file since 10911 was 10911, checked in by , 8 days ago | |
|---|---|
| File size: 457 bytes | |
| Rev | Line | |
|---|---|---|
| [1608] | 1 | |
| [9952] | 2 | #ifndef WIN32 |
| [1608] | 3 | #include <unistd.h> |
| [9954] | 4 | #else |
| [10911] | 5 | #define _HAS_STD_BYTE 0 |
| [9958] | 6 | #include <windows.h> |
| [9952] | 7 | #endif |
| [1608] | 8 | #include <stdio.h> |
| 9 | #include <stdlib.h> | |
| 10 | ||
| 11 | int main(int argc, char* argv[]) { | |
| 12 | ||
| [1633] | 13 | FILE* fp = fopen("/dev/ttyS0", "r"); |
| [1608] | 14 | |
| 15 | if (!fp) { | |
| 16 | printf("Cannot open file.\n"); | |
| [9854] | 17 | exit(9); |
| [1608] | 18 | } |
| 19 | ||
| [1633] | 20 | char msg[100]; |
| [1608] | 21 | |
| 22 | while (true) { | |
| [1633] | 23 | int nb = fread(msg, sizeof(msg), 1, fp); |
| 24 | printf("read %d\n", nb); | |
| [9958] | 25 | #ifndef WIN32 |
| 26 | sleep(1); | |
| 27 | #else | |
| 28 | Sleep(1000); | |
| 29 | #endif | |
| [1608] | 30 | } |
| 31 | ||
| 32 | return 0; | |
| 33 | } |
Note:
See TracBrowser
for help on using the repository browser.
