sane_user实现获取自定义信息的接口
This commit is contained in:
parent
9fda967256
commit
88555e51eb
|
@ -25,7 +25,7 @@ typedef struct
|
|||
HGChar ip[32];
|
||||
HGChar mac[32];
|
||||
HGUInt rollerCount;
|
||||
HGUInt histroyCount;
|
||||
HGUInt totalCount;
|
||||
}HGSaneCustomInfo;
|
||||
|
||||
#pragma pack(pop)
|
||||
|
|
|
@ -643,7 +643,46 @@ HGResult HGSaneDeviceImpl::GetName(HGChar* name, HGUInt maxLen)
|
|||
|
||||
HGResult HGSaneDeviceImpl::GetCustomInfo(HGSaneCustomInfo *info)
|
||||
{
|
||||
return HGBASE_ERR_NOTIMPL;
|
||||
if (NULL == info)
|
||||
{
|
||||
return HGBASE_ERR_INVALIDARG;
|
||||
}
|
||||
|
||||
memset(info, 0, sizeof(HGSaneCustomInfo));
|
||||
|
||||
HGInt intValue = 0;
|
||||
GetValue("dev-vid", &intValue);
|
||||
info->vid = (HGUShort)intValue;
|
||||
intValue = 0;
|
||||
GetValue("dev-pid", &intValue);
|
||||
info->pid = (HGUShort)intValue;
|
||||
intValue = 0;
|
||||
GetValue("roll-cnt", &intValue);
|
||||
info->rollerCount = (HGUInt)intValue;
|
||||
intValue = 0;
|
||||
GetValue("total-cnt", &intValue);
|
||||
info->totalCount = (HGUInt)intValue;
|
||||
|
||||
HGChar strValue[256] = {0};
|
||||
GetValue("dev-model", strValue, 256);
|
||||
strcpy(info->model, strValue);
|
||||
strValue[0] = 0;
|
||||
GetValue("dev-type", strValue, 256);
|
||||
strcpy(info->type, strValue);
|
||||
strValue[0] = 0;
|
||||
GetValue("dev-sn", strValue, 256);
|
||||
strcpy(info->sn, strValue);
|
||||
strValue[0] = 0;
|
||||
GetValue("dev-ver", strValue, 256);
|
||||
strcpy(info->fwVer, strValue);
|
||||
strValue[0] = 0;
|
||||
GetValue("ip-addr", strValue, 256);
|
||||
strcpy(info->ip, strValue);
|
||||
strValue[0] = 0;
|
||||
GetValue("mac-addr", strValue, 256);
|
||||
strcpy(info->mac, strValue);
|
||||
|
||||
return HGBASE_ERR_OK;
|
||||
}
|
||||
|
||||
HGResult HGSaneDeviceImpl::ShowSettingDlg(HGWindow parent)
|
||||
|
@ -693,7 +732,7 @@ HGResult HGSaneDeviceImpl::Start(HGSane_DeviceEventFunc eventFunc, HGPointer eve
|
|||
return HGBASE_ERR_OUTOFMEMORY;
|
||||
}
|
||||
|
||||
m_dpi = GetDpi();
|
||||
GetValue("resolution", &m_dpi);
|
||||
stat = m_sourceImpl->m_saneApi.sane_start_api(m_devHandle);
|
||||
if (SANE_STATUS_GOOD != stat)
|
||||
{
|
||||
|
@ -752,7 +791,7 @@ HGResult HGSaneDeviceImpl::StartWithUI(HGWindow parent, HGSane_DeviceImageFunc i
|
|||
return HGBASE_ERR_FAIL;
|
||||
}
|
||||
|
||||
m_dpi = GetDpi();
|
||||
GetValue("resolution", &m_dpi);
|
||||
m_imageFunc = imageFunc;
|
||||
m_imageParam = imageParam;
|
||||
|
||||
|
@ -764,9 +803,12 @@ HGResult HGSaneDeviceImpl::StartWithUI(HGWindow parent, HGSane_DeviceImageFunc i
|
|||
return HGBASE_ERR_OK;
|
||||
}
|
||||
|
||||
HGUInt HGSaneDeviceImpl::GetDpi()
|
||||
HGResult HGSaneDeviceImpl::GetValue(const HGChar *name, HGInt *value)
|
||||
{
|
||||
HGUInt dpi = 0;
|
||||
assert(NULL != name && 0 != *name);
|
||||
assert(NULL != value);
|
||||
|
||||
HGResult ret = HGBASE_ERR_FAIL;
|
||||
SANE_Int num_dev_options = 0;
|
||||
m_sourceImpl->m_saneApi.sane_control_option_api(m_devHandle, 0, SANE_ACTION_GET_VALUE, &num_dev_options, NULL);
|
||||
for (int i = 1; i < num_dev_options; ++i)
|
||||
|
@ -777,17 +819,52 @@ HGUInt HGSaneDeviceImpl::GetDpi()
|
|||
|
||||
if (SANE_TYPE_INT == desp->type)
|
||||
{
|
||||
SANE_Int value = 0;
|
||||
m_sourceImpl->m_saneApi.sane_control_option_api(m_devHandle, i, SANE_ACTION_GET_VALUE, &value, NULL);
|
||||
if (0 == strcmp(desp->name, "resolution"))
|
||||
SANE_Int v = 0;
|
||||
m_sourceImpl->m_saneApi.sane_control_option_api(m_devHandle, i, SANE_ACTION_GET_VALUE, &v, NULL);
|
||||
if (0 == strcmp(desp->name, name))
|
||||
{
|
||||
dpi = (HGUInt)value;
|
||||
*value = (HGInt)v;
|
||||
ret = HGBASE_ERR_OK;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return dpi;
|
||||
return ret;
|
||||
}
|
||||
|
||||
HGResult HGSaneDeviceImpl::GetValue(const HGChar *name, HGChar *value, HGUInt maxLen)
|
||||
{
|
||||
assert(NULL != name && 0 != *name);
|
||||
assert(NULL != value);
|
||||
|
||||
HGResult ret = HGBASE_ERR_FAIL;
|
||||
SANE_Int num_dev_options = 0;
|
||||
m_sourceImpl->m_saneApi.sane_control_option_api(m_devHandle, 0, SANE_ACTION_GET_VALUE, &num_dev_options, NULL);
|
||||
for (int i = 1; i < num_dev_options; ++i)
|
||||
{
|
||||
const SANE_Option_Descriptor* desp = m_sourceImpl->m_saneApi.sane_get_option_descriptor_api(m_devHandle, i);
|
||||
if (nullptr == desp)
|
||||
continue;
|
||||
|
||||
if (SANE_TYPE_STRING == desp->type)
|
||||
{
|
||||
char v[256] = { 0 };
|
||||
m_sourceImpl->m_saneApi.sane_control_option_api(m_devHandle, i, SANE_ACTION_GET_VALUE, v, NULL);
|
||||
if (0 == strcmp(desp->name, name))
|
||||
{
|
||||
if (maxLen > strlen(v))
|
||||
{
|
||||
strcpy(value, v);
|
||||
ret = HGBASE_ERR_OK;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void HGAPI HGSaneDeviceImpl::ThreadFunc(HGThread thread, HGPointer param)
|
||||
|
|
|
@ -80,7 +80,8 @@ public:
|
|||
HGResult StartWithUI(HGWindow parent, HGSane_DeviceImageFunc imageFunc, HGPointer imageParam);
|
||||
|
||||
private:
|
||||
HGUInt GetDpi();
|
||||
HGResult GetValue(const HGChar *name, HGInt *value);
|
||||
HGResult GetValue(const HGChar *name, HGChar *value, HGUInt maxLen);
|
||||
static void HGAPI ThreadFunc(HGThread thread, HGPointer param);
|
||||
static void ShowScanImageCallback(const SANE_Parameters* imageFormat, const SANE_Byte* imageData, void* callbackParam);
|
||||
|
||||
|
@ -90,7 +91,7 @@ private:
|
|||
SANE_Handle m_devHandle;
|
||||
HGByte* m_buffer;
|
||||
HGInt m_bufferSize;
|
||||
HGUInt m_dpi;
|
||||
HGInt m_dpi;
|
||||
HGSane_DeviceEventFunc m_eventFunc;
|
||||
HGPointer m_eventParam;
|
||||
HGSane_DeviceImageFunc m_imageFunc;
|
||||
|
|
|
@ -21,7 +21,7 @@ typedef struct
|
|||
HGChar ip[32];
|
||||
HGChar mac[32];
|
||||
HGUInt rollerCount;
|
||||
HGUInt histroyCount;
|
||||
HGUInt totalCount;
|
||||
}HGTwainDeviceCustomInfo;
|
||||
|
||||
#pragma pack(pop)
|
||||
|
|
|
@ -405,15 +405,18 @@ HGResult HGTwainDSImpl::GetDeviceCustomInfo(HGTwainDeviceCustomInfo *info)
|
|||
return HGBASE_ERR_INVALIDARG;
|
||||
}
|
||||
|
||||
HGChar value[256] = {0};
|
||||
memset(info, 0, sizeof(HGTwainDeviceCustomInfo));
|
||||
|
||||
GetCap(CAP_SERIALNUMBER, value, 256);
|
||||
strcpy(info->sn, value);
|
||||
GetCap(0x8025, value, 256);
|
||||
strcpy(info->fwVer, value);
|
||||
GetCap(0x8200, value, 256);
|
||||
strcpy(info->ip, value);
|
||||
HGChar strValue[256] = {0};
|
||||
GetCap(CAP_SERIALNUMBER, strValue, 256);
|
||||
strcpy(info->sn, strValue);
|
||||
strValue[0] = 0;
|
||||
GetCap(0x8025, strValue, 256);
|
||||
strcpy(info->fwVer, strValue);
|
||||
strValue[0] = 0;
|
||||
GetCap(0x8200, strValue, 256);
|
||||
strcpy(info->ip, strValue);
|
||||
|
||||
return HGBASE_ERR_OK;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue