Skip to content

Commit bf0d348

Browse files
committed
Refine
1 parent 905f02d commit bf0d348

File tree

4 files changed

+18
-27
lines changed

4 files changed

+18
-27
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Please see [Applications installed from the web](https://docs.microsoft.com/ja-j
7171
# Notes
7272

7373
* SimpleCom sends / receives VT100 escape sequences. So the serial device to connect via SimpleCom needs to support VT100 or compatible shell.
74-
* F1 key is hooked by SimpleCom (in interactive mode (default)), so escase sequence of F1 (`ESC O P`) would not be propagated.
74+
* F1 key is hooked by SimpleCom (in interactive mode (default)), so escape sequence of F1 (`ESC O P`) would not be propagated.
7575
* In batch mode, F1 would propergate to peripheral.
7676
* SimpleCom supports ANSI chars only, so it would not work if multibyte chars (e.g. CJK chars) are given.
7777
* Run [resize](https://linux.die.net/man/1/resize) provided by xterm if you want to align VT size of Linux box with your console window.

SimpleCom/BatchRedirector.cpp

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@
2121

2222
static constexpr int buf_sz = 256;
2323

24+
static void RedirectHandle(HANDLE hSource, HANDLE hDest) {
25+
char buf[buf_sz];
26+
DWORD nBytesRead;
27+
while (ReadFile(hSource, buf, sizeof(buf), &nBytesRead, NULL)) {
28+
DWORD nBytesWritten;
29+
DWORD nBytesRemain = nBytesRead;
30+
while (nBytesRemain > 0) {
31+
if (WriteFile(hDest, &buf[nBytesRead - nBytesRemain], nBytesRemain, &nBytesWritten, nullptr)) {
32+
nBytesRemain -= nBytesWritten;
33+
}
34+
}
35+
}
36+
}
37+
2438
DWORD WINAPI BatchStdInRedirector(_In_ LPVOID lpParameter) {
2539
HANDLE hStdIn = GetStdHandle(STD_INPUT_HANDLE);
2640
if (hStdIn == INVALID_HANDLE_VALUE) {
@@ -35,18 +49,7 @@ DWORD WINAPI BatchStdInRedirector(_In_ LPVOID lpParameter) {
3549
SetConsoleMode(hStdIn, mode);
3650

3751
HANDLE hSerial = reinterpret_cast<HANDLE>(lpParameter);
38-
char buf[buf_sz];
39-
DWORD nBytesRead;
40-
while(ReadFile(hStdIn, buf, sizeof(buf), &nBytesRead, NULL)) {
41-
DWORD nBytesWritten;
42-
DWORD nBytesRemain = nBytesRead;
43-
while (nBytesRemain > 0) {
44-
if (WriteFile(hSerial, &buf[nBytesRead - nBytesRemain], nBytesRemain, &nBytesWritten, nullptr)) {
45-
nBytesRemain -= nBytesWritten;
46-
}
47-
}
48-
}
49-
52+
RedirectHandle(hStdIn, hSerial);
5053
return 0;
5154
}
5255

@@ -58,18 +61,7 @@ DWORD WINAPI BatchStdOutRedirector(_In_ LPVOID lpParameter) {
5861
}
5962

6063
HANDLE hSerial = reinterpret_cast<HANDLE>(lpParameter);
61-
char buf[buf_sz];
62-
DWORD nBytesRead;
63-
while (ReadFile(hSerial, buf, sizeof(buf), &nBytesRead, NULL)) {
64-
DWORD nBytesWritten;
65-
DWORD nBytesRemain = nBytesRead;
66-
while (nBytesRemain > 0) {
67-
if (WriteFile(hStdOut, &buf[nBytesRead - nBytesRemain], nBytesRemain, &nBytesWritten, nullptr)) {
68-
nBytesRemain -= nBytesWritten;
69-
}
70-
}
71-
}
72-
64+
RedirectHandle(hSerial, hStdOut);
7365
return 0;
7466
}
7567

SimpleCom/BatchRedirector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace SimpleCom {
3131

3232
public:
3333
BatchRedirector(HANDLE hSerial) : TerminalRedirectorBase(hSerial) {};
34-
virtual ~BatchRedirector() {};
34+
virtual ~BatchRedirector() {};
3535
};
3636

3737
}

SimpleCom/SimpleCom.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ int _tmain(int argc, LPCTSTR argv[])
140140
}
141141
catch(std::invalid_argument& e) {
142142
// Only ASCII chars should be converted to wchar, so we can ignore deprecation since C++17.
143-
// "/D _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING" has been added to command line option in project properties.
144143
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> conv;
145144
MessageBox(parent_hwnd, conv.from_bytes(e.what()).c_str(), _T("Invalid argument"), MB_OK | MB_ICONERROR);
146145
return -4;

0 commit comments

Comments
 (0)