Browse Source

优化打印端口的开启,避免卡住

张洋 1 week ago
parent
commit
67597c6293
1 changed files with 6 additions and 2 deletions
  1. 6 2
      zhipuzi_pos_windows/worker/CPosPrinterWorker.cpp

+ 6 - 2
zhipuzi_pos_windows/worker/CPosPrinterWorker.cpp

@@ -137,8 +137,6 @@ void CPosPrinterWorker::StartShouyinChannels()
 		ch->portPath = it->first;
 		ch->portPath = it->first;
 		ch->portKind = it->second;
 		ch->portKind = it->second;
 
 
-		OpenChannelHandle(ch);
-
 		ch->worker = std::thread(&CPosPrinterWorker::ChannelWorker, this, ch);
 		ch->worker = std::thread(&CPosPrinterWorker::ChannelWorker, this, ch);
 		new_channels.push_back(ch);
 		new_channels.push_back(ch);
 	}
 	}
@@ -190,6 +188,12 @@ void CPosPrinterWorker::StopShouyinChannels()
 
 
 void CPosPrinterWorker::ChannelWorker(std::shared_ptr<CPortSendChannel> ch)
 void CPosPrinterWorker::ChannelWorker(std::shared_ptr<CPortSendChannel> ch)
 {
 {
+	//在通道线程中打开端口,避免驱动响应慢时阻塞 Start 或设置刷新调用
+	if (ch->hPort == NULL)
+	{
+		OpenChannelHandle(ch);
+	}
+
 	while (true)
 	while (true)
 	{
 	{
 		std::string data;
 		std::string data;