-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
39 lines (24 loc) · 1.34 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include "seriallib.h"
int main (int argc, char *argv []) {
char *port = malloc (sizeof (char) * 12); // Just for "straight to test purposes", in production, use the port detection functions instead
strcpy(port, "\\\\.\\COM5");
//------------------------------------ Stand-alone function to do their straight work the most synchronous way ------------------------------------
AVAILABLE_PORTS *ports; // Initializing the struct values
ports = malloc(sizeof(AVAILABLE_PORTS));
updateAvailablePortsInfo(ports); // Setup/load time, the function will update the living struct
DATA_BUFFER *wbuffer; // Initializing the struct values
wbuffer = malloc(sizeof(DATA_BUFFER)); // Buffer Containing Txed Data
strcpy(wbuffer->data, "Hello World");
writeSerialPort(port, 9600, wbuffer);
printf("TX Code %i - %s Data -> %s\n", wbuffer->code, wbuffer->message, wbuffer->data);
DATA_BUFFER *rbuffer; // Initializing the struct values
rbuffer = malloc(sizeof(DATA_BUFFER)); // Buffer Containing Rxed Data
while (1) {
listenSerialPort(port, 9600, rbuffer);
printf("RX Code %i - %s Data -> %s\n", rbuffer->code, rbuffer->message, rbuffer->data);
}
return 0;
}