mirror of http://192.168.1.51:8099/lmh188/twain3.0
USB读图算法调整
This commit is contained in:
parent
a4ad46d42e
commit
d04656ae74
|
@ -156,7 +156,7 @@ GScanO200::~GScanO200()
|
|||
m_threadUsb->join();
|
||||
m_threadUsb.reset();
|
||||
}
|
||||
if(m_usb.get())
|
||||
if (m_usb.get())
|
||||
m_usb.reset();
|
||||
|
||||
}
|
||||
|
@ -299,7 +299,7 @@ std::string GScanO200::GetSerialNum()
|
|||
if (m_usb.get() && m_usb->is_connected())
|
||||
{
|
||||
std::lock_guard<std::mutex> lck(m_imgLocker);
|
||||
//if (SerialNum.empty()) {
|
||||
if (SerialNum.empty()) {
|
||||
#ifndef G200
|
||||
SerialNum.resize(14);
|
||||
#else // !G200
|
||||
|
@ -309,7 +309,7 @@ std::string GScanO200::GetSerialNum()
|
|||
m_usb->write_bulk(&usbcb, sizeof(usbcb));
|
||||
m_usb->read_bulk(&SerialNum[0], SerialNum.size());
|
||||
|
||||
//}
|
||||
}
|
||||
return SerialNum;
|
||||
}
|
||||
return "";
|
||||
|
@ -387,7 +387,7 @@ void GScanO200::Scanner_StartScan(UINT16 count)
|
|||
break;
|
||||
}
|
||||
|
||||
//#ifndef G200
|
||||
#ifndef G200
|
||||
USBCB paperstatus = { GET_PAPER_STATUS ,0,0 };
|
||||
if (m_usb.get() && m_usb->is_connected())
|
||||
m_usb->write_bulk(&paperstatus, sizeof(paperstatus));
|
||||
|
@ -401,7 +401,7 @@ void GScanO200::Scanner_StartScan(UINT16 count)
|
|||
dev_callback(NO_FEED, huagods);
|
||||
return;
|
||||
}
|
||||
//#endif // !G200
|
||||
#endif // !G200
|
||||
|
||||
if (gcap.is_duplex)
|
||||
count = count == 65535 ? 65535 : count / 2;
|
||||
|
@ -425,6 +425,7 @@ void GScanO200::Stop_scan()
|
|||
m_usb->write_bulk(&usbcb, sizeof(usbcb));
|
||||
}
|
||||
|
||||
|
||||
void GScanO200::ResetScanner()
|
||||
{
|
||||
if (m_usb.get() && !m_usb->is_connected())
|
||||
|
@ -432,7 +433,7 @@ void GScanO200::ResetScanner()
|
|||
|
||||
std::lock_guard<std::mutex> lck(m_imgLocker);
|
||||
USBCB usbcb = { INIT_HARDWARE_SYS ,0,0 };
|
||||
if(m_usb.get() && m_usb->is_connected())
|
||||
if (m_usb.get() && m_usb->is_connected())
|
||||
m_usb->write_bulk(&usbcb, sizeof(usbcb));
|
||||
}
|
||||
|
||||
|
@ -556,7 +557,15 @@ void GScanO200::usbmain()
|
|||
return;
|
||||
}
|
||||
|
||||
if (gcap.resolution_dst >= 300.0f)
|
||||
if (gcap.resolution_dst == 200.0f)
|
||||
{
|
||||
if (m_pImages->orginimgcount() > 5)
|
||||
{
|
||||
this_thread::sleep_for(chrono::milliseconds(10));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if(gcap.resolution_dst>200.0f)
|
||||
{
|
||||
if (m_pImages->orginimgcount() > 2)
|
||||
{
|
||||
|
@ -578,6 +587,7 @@ void GScanO200::usbmain()
|
|||
writelog("imgData->size() error");
|
||||
break;
|
||||
}
|
||||
|
||||
m_pImages->pushMat(std::shared_ptr<IDecode>(new G200Decode(imgData)));
|
||||
//static int rawdataindex = 0;
|
||||
//writelog("origin rawbuffer index " + std::to_string(++rawdataindex));
|
||||
|
@ -665,16 +675,29 @@ std::shared_ptr<std::vector<char>> GScanO200::Get_Img_Data(int bufferSize)
|
|||
std::shared_ptr<std::vector<char>> imData(new std::vector<char>(bufferSize));
|
||||
StopWatch sw;
|
||||
int readed = 0;
|
||||
while (readed < bufferSize && sw.elapsed_ms() < 5000) {
|
||||
USBCB usbcb = { GET_IMAGE,0,(UINT32)bufferSize };
|
||||
USBCB usbcb = { GET_IMAGE,0,bufferSize };
|
||||
m_usb->write_bulk(&usbcb, sizeof(usbcb));
|
||||
readed = m_usb->read_bulk(imData->data(), bufferSize);
|
||||
int totalength = bufferSize;
|
||||
int startindex = 0;
|
||||
while (totalength > 0)
|
||||
{
|
||||
int dstlength = 1024 * 1024;
|
||||
if (totalength <= dstlength)
|
||||
{
|
||||
dstlength = totalength;
|
||||
totalength = 0;
|
||||
}
|
||||
else
|
||||
totalength -= dstlength;
|
||||
|
||||
int tt = m_usb->read_bulk(imData->data() + startindex, dstlength);
|
||||
startindex += dstlength;
|
||||
}
|
||||
|
||||
if (sw.elapsed_ms() > 3000) {
|
||||
if (sw.elapsed_ms() > 5000)
|
||||
{
|
||||
writelog("Usb read data timeout\n");
|
||||
}
|
||||
|
||||
return imData;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue