twain3.0/huagao/Device/GScan200.cpp

172 lines
3.8 KiB
C++

#include "stdafx.h"
#include "GScan200.h"
#include "GDeviceLists.h"
#include "IGDevice.h"
#include "opencv2/opencv.hpp"
#include "config_new.h"
#include "device_common.h"
#include "GDevice.h"
#include "ImageMatQueue.h"
GScan200::GScan200()
{
}
GScan200::~GScan200()
{
//if (!error_msg.IsShutDown())
// error_msg.ShutDown();
}
void GScan200::open(int vid, int pid)
{
auto devs = HGDeviceLists::FindAll();
if(!devs.empty()){
m_dev = *(devs.begin());
m_dev->open();
}
}
void GScan200::regist_deviceevent_callback(deviceevent_callback callback, void* usrdata)
{
}
int GScan200::aquire_bmpdata(std::vector<unsigned char>& bmpdata)
{
return 0;
}
BOOL GScan200::IsConnected()
{
return m_dev && m_dev->is_open();
}
std::string GScan200::GetFWVersion()
{
if (fwVersion.empty()) {
fwVersion.resize(8);
((GDevice*)(m_dev.get()))->read_flash(FWVERSION_ADDR, (void*)(fwVersion.data()), FLASH_FWVERSION_ADDR_SIZE);
}
return fwVersion;
}
std::string GScan200::GetSerialNum()
{
if (SerialNum.empty()) {
SerialNum.resize(12);
((GDevice*)(m_dev.get()))->read_flash(SERIAL_ADDR, (void*)(SerialNum.data()), FLASH_SERIAL_ADDR_SIZE);
}
return SerialNum;
}
bool GScan200::is_scan()
{
return m_dev && m_dev->is_run();
}
BOOL GScan200::Get_Scanner_PaperOn()
{
return m_dev->get_option(Cam_Options::scanner_paper_have);
}
void GScan200::config_params(GScanCap& params)
{
config_new cfn(params);
unsigned int cfg_value=cfn.GetData();
m_dev->set_option(Cam_Options::scanner_config, cfg_value);
m_pImages->setparam(params);
}
void GScan200::Scanner_StartScan(UINT16 count)
{
m_dev->start(image_call_s, this);
m_dev->set_event_call(event_call_g200, this);
}
void GScan200::Stop_scan()
{
m_dev->stop();
}
void GScan200::ResetScanner()
{
}
bool GScan200::Get_IsImageQueueEmpty()
{
return m_pImages->empty();
}
void GScan200::reset()
{
if (m_dev) {
m_dev->stop();
this_thread::sleep_for(chrono::milliseconds(200));
m_pImages->clear();
}
}
void GScan200::clear_hwerror()
{
}
void GScan200::setdecodepixtype(int twpixtype)
{
pixType = (twpixtype == 0) ? 1 : 0;
}
UINT32 GScan200::get_ErrorCode()
{
return UINT32();
}
void GScan200::Set_ErrorCode(UINT32 value)
{
//error_msg.Clear();
}
int GScan200::get_scanned_num()
{
int scanned_count = 0;
((GDevice*)(m_dev.get()))->read_flash(CONT_ADDR, &scanned_count, FLASH_CONT_ADDR_SIZE);
return scanned_count;
}
void GScan200::image_call_s(void* fdata, int fsize, void* bdata, int bsize, void* userdata)
{
GScan200* This = (GScan200*)userdata;
This->image_call(fdata, fsize, bdata, bsize);
}
void GScan200::event_call_g200(int error_value, void* userdata)
{
GScan200* This = (GScan200*)userdata;
//if (!This->error_msg.IsShutDown())
//{
// MotorStatus ms;
// ms.value = error_value;
// if (ms.double_paper == 1) { This->error_msg.Put(DETECT_DOUBLE_FEED); };//error_msg.Put(DETECT_DOUBLE_FEED);
// if (ms.open_machine == 1) { This->error_msg.Put(OPEN_COVER); };//error_msg.Put(OPEN_COVER);
// if (ms.m1_paper_sin == 1) { This->error_msg.Put(NO_FEED); };//error_msg.Put(NO_FEED);
// if (ms.pick_failed == 1) { This->error_msg.Put(FEED_IN_ERROR); };//error_msg.Put(FEED_IN_ERROR);
// if (ms.stop_jam == 1) { This->error_msg.Put(PAPER_JAM); };//error_msg.Put(PAPER_JAM);
// if (ms.staple == 1) { This->error_msg.Put(DETECT_STAPLE); };//error_msg.Put(DETECT_STAPLE);
// if (ms.scan_mode_change == 1) { This->error_msg.Put(DETECT_STAPLE); };//error_msg.Put(DETECT_STAPLE);
// if (ms.papertilted == 1) { This->error_msg.Put(PAPER_SKEW); };//error_msg.Put(PAPER_SKEW);
//}
}
void GScan200::image_call(void* fdata, int fsize, void* bdata, int bsize)
{
if (fdata && fsize && bdata && bsize)
{
cv::Mat fmat(1, fsize, CV_8UC1, fdata);
cv::Mat bmat(1, bsize, CV_8UC1, bdata);
std::vector<cv::Mat> mats;
mats.push_back(fmat.clone());
mats.push_back(bmat.clone());
// m_pImages.pushMat(JpegBuffer(mats, pixType, 0));
}
}