|
|
@@ -44,17 +44,20 @@ bool CPosPrinter::InitShouyin()
|
|
|
{
|
|
|
Port = szDevicePath[i++];
|
|
|
//LOG_INFO("device.Port = " << Port);
|
|
|
- }
|
|
|
|
|
|
- m_hPort = CreateFile(Port, GENERIC_READ | GENERIC_WRITE,
|
|
|
- 0, NULL,
|
|
|
- OPEN_EXISTING,
|
|
|
- FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
+ HANDLE hPort = CreateFile(Port, GENERIC_READ | GENERIC_WRITE,
|
|
|
+ 0, NULL,
|
|
|
+ OPEN_EXISTING,
|
|
|
+ FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
|
|
- if(m_hPort == INVALID_HANDLE_VALUE)
|
|
|
- {
|
|
|
- // 打开端口失败
|
|
|
- return false;
|
|
|
+ if (hPort == INVALID_HANDLE_VALUE)
|
|
|
+ {
|
|
|
+ // 打开端口失败
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ //把当前发现的保存下来
|
|
|
+ m_hPorts.push_back(hPort);
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
@@ -779,7 +782,13 @@ int CPosPrinter::WriteData(string msg)
|
|
|
if(m_type == 1)
|
|
|
{
|
|
|
DWORD dwWrite;
|
|
|
- return WriteFile(m_hPort, msg.c_str(), (DWORD)msg.length(), &dwWrite, NULL);
|
|
|
+
|
|
|
+ for (std::vector<HANDLE>::iterator it = m_hPorts.begin(); it != m_hPorts.end(); it++)
|
|
|
+ {
|
|
|
+ WriteFile(*it, msg.c_str(), (DWORD)msg.length(), &dwWrite, NULL);
|
|
|
+ }
|
|
|
+
|
|
|
+ return 1;
|
|
|
}
|
|
|
|
|
|
else
|
|
|
@@ -803,7 +812,12 @@ int CPosPrinter::WriteBuf(char* buf, int len)
|
|
|
if(m_type == 1)
|
|
|
{
|
|
|
DWORD dwWrite;
|
|
|
- return WriteFile(m_hPort, buf, len, &dwWrite, NULL);
|
|
|
+
|
|
|
+ for (std::vector<HANDLE>::iterator it = m_hPorts.begin(); it != m_hPorts.end(); it++)
|
|
|
+ {
|
|
|
+ WriteFile(*it, buf, len, &dwWrite, NULL);
|
|
|
+ }
|
|
|
+ return 1;
|
|
|
}
|
|
|
|
|
|
else
|