| 149 | } |
| 150 | |
| 151 | static SERIAL_CONFIG ReadSerialConfig() |
| 152 | { |
| 153 | HKEY hKey; |
| 154 | SERIAL_CONFIG cfg; |
| 155 | cfg.Serial = 0; |
| 156 | cfg.BaudRate = 9600; |
| 157 | cfg.WordLength = 8; |
| 158 | cfg.StopBit = ONESTOPBIT; |
| 159 | cfg.Parity = NOPARITY; |
| 160 | cfg.FlowControl = 0; |
| 161 | cfg.EncodingFormat = 0; // 默认使用UTF-8编码 |
| 162 | cfg.EchoMode = 0; // 默认关闭回显模式(字符模式) |
| 163 | if (ERROR_SUCCESS == ::RegOpenKeyEx(HKEY_CURRENT_USER, L"SOFTWARE\\SerialForWindowsTerminal", 0, KEY_READ, &hKey)) |
| 164 | { |
| 165 | DWORD dwSize = sizeof(DWORD); |
| 166 | DWORD dwType = REG_DWORD; |
| 167 | |
| 168 | ::RegQueryValueEx(hKey, L"Serial", 0, &dwType, (LPBYTE)&cfg.Serial, &dwSize); |
| 169 | ::RegQueryValueEx(hKey, L"BaudRate", 0, &dwType, (LPBYTE)&cfg.BaudRate, &dwSize); |
| 170 | ::RegQueryValueEx(hKey, L"WordLength", 0, &dwType, (LPBYTE)&cfg.WordLength, &dwSize); |
| 171 | ::RegQueryValueEx(hKey, L"StopBit", 0, &dwType, (LPBYTE)&cfg.StopBit, &dwSize); |
| 172 | ::RegQueryValueEx(hKey, L"Parity", 0, &dwType, (LPBYTE)&cfg.Parity, &dwSize); |
| 173 | ::RegQueryValueEx(hKey, L"FlowControl", 0, &dwType, (LPBYTE)&cfg.FlowControl, &dwSize); |
| 174 | ::RegQueryValueEx(hKey, L"EncodingFormat", 0, &dwType, (LPBYTE)&cfg.EncodingFormat, &dwSize); |
| 175 | ::RegQueryValueEx(hKey, L"EchoMode", 0, &dwType, (LPBYTE)&cfg.EchoMode, &dwSize); // 读取回显模式 |
| 176 | ::RegCloseKey(hKey); |
| 177 | } |
| 178 | return cfg; |
| 179 | } |
| 180 | |
| 181 | static void ToggleEchoMode(SERIAL_CONFIG& cfg) |
| 182 | { |
no outgoing calls
no test coverage detected