Op het moment ben ik bezig om een dll te schrijven voor m'n Pinnacle Remote Control die aan te sluiten is op een seriele/com poort. Ik wil deze uitlezen door gebruik te maken van api calls. Daarvoor heb ik de volgende code van msdn gehaald en hier en daar nog wat aangepast:
Het probleem is dus dat ik niks kan uitlezen. Zelfs wanneer ik een DCB instel lukt het nog niet. De instelling die ik gebruik zijn: 1200 baud, 8 databits, no parity bits, en 1 stopbit. Ook met ReadFile(); lukt het niet om iets uit te lezen. Ik draai WinXP Professional SP2. Ik hoop dat jullie nog wat ideeen hebben wat er mis kan zijn?
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
| #include <windows.h> #include <assert.h> #include <stdio.h> void main( ) { HANDLE hCom; OVERLAPPED o; BOOL fSuccess; DWORD dwEvtMask; hCom = CreateFile( "COM1", GENERIC_READ | GENERIC_WRITE, 0, // exclusive access NULL, // default security attributes OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL ); if (hCom == INVALID_HANDLE_VALUE) { // Handle the error. printf("CreateFile failed with error %d.\n", GetLastError()); return; } // Set the event mask. fSuccess = SetCommMask(hCom, EV_CTS | EV_DSR); //in mijn code veranderd naar EV_RXCHAR if (!fSuccess) { // Handle the error. printf("SetCommMask failed with error %d.\n", GetLastError()); return; } // Create an event object for use by WaitCommEvent. o.hEvent = CreateEvent( NULL, // default security attributes FALSE, // auto reset event FALSE, // not signaled NULL // no name ); // Intialize the rest of the OVERLAPPED structure to zero. o.Internal = 0; o.InternalHigh = 0; o.Offset = 0; o.OffsetHigh = 0; assert(o.hEvent); if (WaitCommEvent(hCom, &dwEvtMask, &o)) { //hier staat in mijn code een printf om te kijken of er data binnenkomt if (dwEvtMask & EV_DSR) { // To do. } if (dwEvtMask & EV_CTS) { // To do. } } else { DWORD dwRet = GetLastError(); if( ERROR_IO_PENDING == dwRet) { printf("I/O is pending...\n"); // To do. } else printf("WaitCommEvent failed with error %d.\n", GetLastError()); } } |
Het probleem is dus dat ik niks kan uitlezen. Zelfs wanneer ik een DCB instel lukt het nog niet. De instelling die ik gebruik zijn: 1200 baud, 8 databits, no parity bits, en 1 stopbit. Ook met ReadFile(); lukt het niet om iets uit te lezen. Ik draai WinXP Professional SP2. Ik hoop dat jullie nog wat ideeen hebben wat er mis kan zijn?
Pwnd