mirror of http://192.168.1.51:8099/lmh188/twain3.0
3399图像数据传递改为同步处理
This commit is contained in:
parent
72f7212930
commit
df8bb0c795
|
@ -62,15 +62,8 @@ GScanO1003399::~GScanO1003399()
|
|||
|
||||
void GScanO1003399::open(int vid, int pid)
|
||||
{
|
||||
//auto lsusb=CyUsbList::find_vid_pid(vid, pid);
|
||||
//if (!lsusb.empty())
|
||||
//{
|
||||
// m_usb = *lsusb.begin();
|
||||
// m_usb->open();
|
||||
//}
|
||||
if (m_usb.get()&&m_usb->is_connected())
|
||||
if (m_usb.get() && m_usb->is_connected())
|
||||
return;
|
||||
//auto lsusb = CyUsbList::find_all();
|
||||
auto lsusb = UsbScan_List::find_vid_pid(vid, pid);
|
||||
if (!lsusb.empty())
|
||||
{
|
||||
|
@ -540,9 +533,9 @@ bool GScanO1003399::is_dev_tx()
|
|||
void GScanO1003399::im_rx()
|
||||
{
|
||||
|
||||
fu_rx = m_imgthread.enqueue([this] {
|
||||
//m_imgthread.enqueue([this] {
|
||||
StopWatch sw;
|
||||
while (im_dev_count()){
|
||||
/* code */
|
||||
if (is_dev_tx())
|
||||
{
|
||||
this_thread::sleep_for(chrono::microseconds(20));
|
||||
|
@ -550,6 +543,8 @@ void GScanO1003399::im_rx()
|
|||
}
|
||||
if (keeplastimg)
|
||||
{
|
||||
if(sw.elapsed_ms()>300)
|
||||
break;
|
||||
this_thread::sleep_for(chrono::microseconds(10));
|
||||
if (m_param.is_duplex) {
|
||||
if(im_dev_count()<3)
|
||||
|
@ -558,13 +553,12 @@ void GScanO1003399::im_rx()
|
|||
if(im_dev_count()<2)
|
||||
continue;
|
||||
}
|
||||
//auto &buffi = im_data;
|
||||
std::shared_ptr<std::vector<char>> buffi(new std::vector<char>);
|
||||
int count = front_datasize();
|
||||
buffi->resize(count);
|
||||
rx_cmd();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
count = read_data(buffi->data(), count, count / (0.01 * 1024 * 1024));
|
||||
count = read_data(buffi->data(), count, count / (0.005 * 1024 * 1024)); //
|
||||
pop_dev_im();
|
||||
vector<cv::Mat> mats;
|
||||
if (m_param.multi_output_red)
|
||||
|
@ -582,22 +576,35 @@ void GScanO1003399::im_rx()
|
|||
fu_imgpro.pop();
|
||||
}
|
||||
}
|
||||
});
|
||||
//});
|
||||
}
|
||||
|
||||
int GScanO1003399::read_data(void* data, int length, int timeout)
|
||||
{
|
||||
if (!m_usb.get() && !m_usb->is_connected())
|
||||
{
|
||||
FileTools::writelog(log_INFO, "if (!m_usb.get() && !m_usb->is_connected())");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int readed = 0;
|
||||
int reading = 0;
|
||||
const int buffer_size = 2 * 1024 * 1024;
|
||||
StopWatch sw;
|
||||
while (readed < length && sw.elapsed_ms() < timeout) {
|
||||
reading = std::max(0, std::min(length - readed, buffer_size));
|
||||
reading = m_usb->read_bulk((unsigned char*)data + readed, reading);
|
||||
if (reading > 0) {
|
||||
readed += reading;
|
||||
FileTools::writelog(log_INFO, "read_data timeout =" + to_string(timeout));
|
||||
while (readed < length) {
|
||||
if (sw.elapsed_ms() < timeout)
|
||||
{
|
||||
reading = std::max(0, std::min(length - readed, buffer_size));
|
||||
reading = m_usb->read_bulk((unsigned char*)data + readed, reading);
|
||||
if (reading > 0) {
|
||||
readed += reading;
|
||||
sw.reset();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
FileTools::writelog(log_INFO, "read usb image data time out ,time = "+std::to_string(sw.elapsed_ms()));
|
||||
}
|
||||
}
|
||||
return readed;
|
||||
|
|
|
@ -79,7 +79,7 @@ private:
|
|||
std::shared_ptr<IUsb> m_usb;
|
||||
volatile bool b_usbthread;
|
||||
BlockingQueue<std::shared_ptr<std::vector<char>>> imgs;
|
||||
std::future<void> fu_rx;
|
||||
//std::future<void> fu_rx;
|
||||
std::queue<std::future<void>> fu_imgpro;
|
||||
ThreadPool m_imgthread;
|
||||
ThreadPool m_imgprocthread;
|
||||
|
|
|
@ -803,6 +803,8 @@ Result HuagaoDs::identityOpenDs(const Identity&) {
|
|||
return { ReturnCode::Failure, ConditionCode::CapBadOperation };
|
||||
}
|
||||
|
||||
|
||||
|
||||
auto usblist = UsbScan_List::find_all_usb();
|
||||
if (!usblist.empty())
|
||||
{
|
||||
|
@ -2469,14 +2471,15 @@ void HuagaoDs::updataGscanCap()
|
|||
Twpp::Result HuagaoDs::startScan()
|
||||
{
|
||||
xtfer = 0;
|
||||
if (!scanner->IsConnected())
|
||||
{
|
||||
scanner->open(vid, pid);
|
||||
if (!scanner->IsConnected())
|
||||
return checkDeviceOnline();
|
||||
}
|
||||
//if (!scanner->IsConnected())
|
||||
//{
|
||||
// scanner->open(vid, pid);
|
||||
// if (!scanner->IsConnected())
|
||||
// return checkDeviceOnline();
|
||||
//}
|
||||
|
||||
scanner->ResetScanner();
|
||||
scanner->reset();
|
||||
//std::string info = "开始扫描 ===> 扫描配置参数为:\n\t m_scanparam->is_autocrop :" + to_string(m_scanparam->is_autocrop);
|
||||
//info += "\n\t m_scanparam->colorenable :" + to_string(m_scanparam->automaticcolor);
|
||||
//info += "\n\t m_scanparam->colorenabletype :" + to_string(m_scanparam->automaticcolortype);
|
||||
|
|
Loading…
Reference in New Issue