-
Notifications
You must be signed in to change notification settings - Fork 2
/
EX2.C
239 lines (187 loc) · 4.68 KB
/
EX2.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/****************************************************************************/
/* */
/* PROGRAM: Example.c */
/* */
/* PURPOSE: Demonstrates how to use MOXA serial I/O cards under MS Windows */
/* Written by Microsoft C 6.0 */
/****************************************************************************/
#include <windows.h>
#include "ex1.h"
#include "../driver/msa.h"
void test1(HWND hWnd);
void test2();
HANDLE hInst;
int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
BOOL bMsgAvail;
if (!hPrevInstance)
if (!InitApplication(hInstance))
return (FALSE);
if (!InitInstance(hInstance, nCmdShow))
return (FALSE);
while (GetMessage(&msg, NULL, NULL, NULL)) {
TranslateMessage((LPMSG)&msg);
DispatchMessage((LPMSG)&msg);
}
return (msg.wParam);
//if (MSAIFrame() > 0 )
}
BOOL InitApplication(HANDLE hInstance)
{
WNDCLASS wc;
wc.style = NULL;
wc.lpfnWndProc = MainWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = "SDLC";
wc.lpszClassName = "SDLCClass";
return (RegisterClass(&wc));
}
BOOL InitInstance(HANDLE hInstance, int nCmdShow)
{
HWND hWnd;
int i;
char tmp[100];
hInst = hInstance;
hWnd = CreateWindow(
"SDLCClass",
"Gateway from SDLC to Serial Port",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL
);
if (!hWnd)
return (FALSE);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
if ((i = MSAInit()) <= 0) { //**
wsprintf(tmp, "MOXA INIT error %d", i); //**
MessageBox(hWnd, tmp, NULL, MB_OK | MB_ICONHAND); //**
return(FALSE); //**
} //**
return (TRUE);
}
long FAR PASCAL MainWndProc(HWND hWnd, unsigned message,
WORD wParam, LONG lParam)
{
FARPROC lpProcAbout;
HMENU hMenu;
PAINTSTRUCT ps;
switch (message) {
case WM_COMMAND:
switch (wParam) {
case IDM_T1: test1(hWnd); break;
default: /* Lets Windows process it */
return (DefWindowProc(hWnd, message, wParam, lParam));
}
break;
case WM_DESTROY:
PostQuitMessage(0);
MSAEnd();
break;
default:
return (DefWindowProc(hWnd, message, wParam, lParam));
}
return (NULL);
}
#define MAX_TEST_PORTS 50
int total_port;
int irq_count;
int port_no[MAX_TEST_PORTS];
/***************************************************************************/
/* */
/* FUNCTION: test1(HWND) */
/* */
/* PURPOSE: get card info */
/* */
/***************************************************************************/
void test1(HWND hWnd)
{
HDC hDC;
NPTTYINFO npTTYInfo ;
DCB dcb;
int err;
char szTemp[ TXQUEUE ] ;
if ((COMDEV( npTTYInfo ) = OpenComm( "COM5", RXQUEUE, TXQUEUE )) < 0)
{
MessageBox(hWnd,"Error:OpenComm","",MB_OK);
return ( FALSE ) ;
}
err = BuildCommDCB("COM5:9600,n,8,1", &dcb);
if (err < 0) {
MessageBox(hWnd, "Ok", "BuildCommDCB", MB_OK);
return 0;
}
memset( szTemp, 0, TXQUEUE) ;
strcpy(szTemp, "Hola");
//SendMessage( hWnd, WM_COMMAND, (WPARAM) IDM_T1, NULL ) ;
WriteComm(COMDEV( npTTYInfo ), (LPSTR) szTemp, strlen(szTemp));
CloseComm( COMDEV( npTTYInfo ) ) ;
/*
int i, j = 1000, j1 = 1000;
char buf[1024], tmp[1024];
long total = 0;
unsigned long t1, t2;
ScrollWindow(hWnd, 0, -300, NULL, NULL);
UpdateWindow(hWnd);
hDC = GetDC(hWnd);
buf[0] = j;
MSAWrite(buf, j--);
buf[0] = j;
MSAWrite(buf, j--);
while (j1 > 100) {
t1 = GetCurrentTime();
while ((i = MSARead(buf, 1024)) == 0)
if (((t2 = GetCurrentTime()) - t1) > 2000)
break;
buf[1] = j1;
if (i != j1 || buf[0] != buf[1])
break;
j1--;
buf[0] = j;
MSAWrite(buf, j--);
}
t1 = MSAIsUnderRun(); */
ReleaseDC(hWnd, hDC);
}
void test2(HWND hWnd)
{
HDC hDC;
int i, j = 1000, j1 = 1000;
char buf[1024], tmp[1024];
long total = 0;
unsigned long t1, t2;
ScrollWindow(hWnd, 0, -300, NULL, NULL);
UpdateWindow(hWnd);
hDC = GetDC(hWnd);
buf[0] = j;
MSAWrite(buf, j--);
buf[0] = j;
MSAWrite(buf, j--);
while (j1 > 100) {
t1 = GetCurrentTime();
while ((i = MSARead(buf, 1024)) == 0)
if (((t2 = GetCurrentTime()) - t1) > 2000)
break;
buf[1] = j1;
if (i != j1 || buf[0] != buf[1])
break;
j1--;
buf[0] = j;
MSAWrite(buf, j--);
}
t1 = MSAIsUnderRun();
ReleaseDC(hWnd, hDC);
}