std::string_view 的使用
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#ifdef WIN32
|
||||
#include "../Base/global_include.h"
|
||||
#include "Serial_p.h"
|
||||
#include <string_view>
|
||||
namespace Psc::serial {
|
||||
|
||||
void reset(Serial_Settings &serial_info) {
|
||||
@@ -46,16 +47,18 @@ void set_binary_mode(Serial_Settings &serial_info) {
|
||||
// windows下默认就是
|
||||
}
|
||||
|
||||
HANDLE open(const std::string &port_name) {
|
||||
HANDLE open(std::string_view port_name) {
|
||||
auto port_path = "\\\\.\\" + std::string(port_name);
|
||||
HANDLE hSerial =
|
||||
CreateFile(("\\\\.\\" + port_name).c_str(), GENERIC_READ | GENERIC_WRITE,
|
||||
CreateFile(port_path.c_str(), GENERIC_READ | GENERIC_WRITE,
|
||||
0, // No sharing
|
||||
NULL, // Default security attributes
|
||||
OPEN_EXISTING, // Open the existing port
|
||||
0, // 0 : No overlapped I/O FILE_FLAG_OVERLAPPED是异步
|
||||
NULL); // No template file
|
||||
if (hSerial == INVALID_HANDLE_VALUE) {
|
||||
LOG_ERROR(VAR_STR_1(port_name))
|
||||
auto port_name_string = std::string(port_name);
|
||||
LOG_ERROR(VAR_STR_1(port_name_string))
|
||||
Psc::fail_fast();
|
||||
return INVALID_HANDLE_VALUE;
|
||||
}
|
||||
@@ -541,4 +544,4 @@ FlowControl get_flow_control(DCB &serial_info) {
|
||||
// CloseHandle(overlapped.hEvent);
|
||||
// return -1;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user