-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestSerial.cpp
More file actions
32 lines (25 loc) · 818 Bytes
/
Copy pathtestSerial.cpp
File metadata and controls
32 lines (25 loc) · 818 Bytes
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
#include <stdio.h>
//#include <tchar.h>
#include "SerialClass.h" // Library described above
#include <string>
// application reads from the specified serial port and reports the collected data
int _tmain(int argc, _TCHAR* argv[])
{
printf("Welcome to the serial test app!\n\n");
Serial* SP = new Serial("\\\\.\\COM10"); // adjust as needed
if (SP->IsConnected())
printf("We're connected");
char incomingData[256] = ""; // don't forget to pre-allocate memory
//printf("%s\n",incomingData);
int dataLength = 255;
int readResult = 0;
while(SP->IsConnected())
{
readResult = SP->ReadData(incomingData,dataLength);
// printf("Bytes read: (0 means no data available) %i\n",readResult);
incomingData[readResult] = 0;
printf("%s",incomingData);
Sleep(500);
}
return 0;
}