forked from waynix/SPinGW
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME
39 lines (32 loc) · 1.13 KB
/
README
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
This Repository contains a wrapper to access the SerialPort in MinGW.
Website:http://r0sset.com/Projects/24
Dependencies:
Windows (tested under XP and 7)
MinGW (not tested with Visual Studio and Cygwin)
Usage:
1. Copy or fork SPinGW
2. Include serialport.h and serialport.c to your program.
3. Call openSerialPort from your program.
4. Use writeToSerialPort and readFromSerialPort to transfer data
5. Close the port with closeSerialPort when the communication is finished
example.c:
#include <stdio.h>
#include "serialport.h"
int main(void)
{
HANDLE h = openSerialPort("COM5",B9600,one,off);
char sendbuffer[] = "test";
char readbuffer[100];
//write test
int bytesWritten = writeToSerialPort(h,sendbuffer,strlen(sendbuffer));
printf("%d Bytes were written\n",bytesWritten);
//read something
int bytesRead = readFromSerialPort(h,readbuffer,99);
readbuffer[bytesRead]=0;
printf("%d Bytes were read:%s\n",bytesRead,readbuffer);
closeSerialPort(h);
return 0;
}
6. compile gcc example.c serialport.c -o example.exe
FAQ:
Comports with a bigger number (I believe bigger than 9) can be used by with their UNC Paths \\\\.\\COM11 (thanks to jaui)