-
Notifications
You must be signed in to change notification settings - Fork 1
/
HT.c
84 lines (76 loc) · 1.36 KB
/
HT.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
#include"Kuroko.h"
#include"App.h"
#include<windows.h>
#include<process.h>
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
static unsigned int WINAPI ReadInfo(PVOID Hcom)
{
char Buf;
while (!fExit)
{
if (ReMessege(Hcom, &Buf))
{
printf("%c", Buf);
}
else
{
if (Err == Err_PullOut)
{
return EXIT_SUCCESS;
}
}
}
return EXIT_SUCCESS;
}
static unsigned int WINAPI WriteInfo(PVOID Hcom)
{
char Buf;
while (1)
{
Buf = _getch();
if (Buf == 27)
{
fExit = 1;
break;
}
if (!SeMessege(Hcom, &Buf))
{
return EXIT_SUCCESS;
}
}
return EXIT_SUCCESS;
}
static void HyperTerminal(SerialPort SP)
{
SP.Hcom = SerialPortInit(SP);
CheckComHandle(SP.Hcom);
HANDLE Wait[2];
Wait[0] = (HANDLE)_beginthreadex(NULL, 0, WriteInfo, SP.Hcom, 0, NULL);
Wait[1] = (HANDLE)_beginthreadex(NULL, 0, ReadInfo, SP.Hcom, 0, NULL);
WaitForMultipleObjects(2, Wait, TRUE, INFINITE);
CloseHandle(SP.Hcom);
CloseHandle(Wait[0]);
CloseHandle(Wait[1]);
fExit = 0;
}
void HTforCMD(int argc, char **argv)
{
if (argc < 4)
{
AErr = FewParameter;
return;
}
SerialPort SP = {
.ComName = { 'C', 'O', 'M' }
};
if (strlen(argv[2])>3)
{
AErr = SerialPortNameErr;
return;
}
sprintf(&SP.ComName[3], argv[2]);
DealStdStr(argv[3], &SP);
HyperTerminal(SP);
}