Home › Forums › TWAIN Classic › Issue with CAP_DEVICEONLINE
- This topic has 1 reply, 2 voices, and was last updated 9 years, 11 months ago by MarkM.
- AuthorPosts
Hi,
I want to know whether device is connected or not. I opened the DS using MSG_OPENDS and then called CAP_DEVICEONLINE. Sample code is here….
bNewReturn = m_DSMEntry(pOrigin,NULL,DG,DAT,MSG_OPENDS,pData);
if(bNewReturn == TWRC_SUCCESS)
{
TW_CAPABILITY twCap;
twCap.Cap = CAP_DEVICEONLINE;
pTW_ONEVALUE pVal;
TW_UINT32 value;
TW_BOOL twReturn = DSM_Entry(pOrigin,(pTW_IDENTITY)pData,DG_CONTROL,DAT_CAPABILITY,MSG_GETCURRENT,(TW_MEMREF)&twCap);pVal = (pTW_ONEVALUE )GlobalLock(twCap.hContainer);
if(pVal)
{
value = pVal->Item;
GlobalUnlock(pVal);
GlobalFree(twCap.hContainer);
}
}the pVal->item is coming 0 for not connected device and coming 1 for connected device. but twReturn value is 0 in both the case. is this behaviour is correct?
Putting twCap.Cap = CAP_DEVICEONLINE; other two parameter twCap.Container and type I have not filled. is that oK?
If i use the above code I get crash while opening DSM. but If i wont use CAP_DEVICEONLINE I wont get any crash.Please suggest how to use CAP_DEVICEONLINE correctly. Is there any other way to know whether device is online or not?
Best Regards,
SharadTWAIN is ambiguous about how a driver is required to respond to MSG_OPENDS, when the device is not online.
Some vendors return a failure and refused to open. Some may open anyways. So it’s always advisable for an application to confirm that the device is present with CAP_DEVICEONLINE, but this can only happen after a successful call to MSG_OPENDS.
The return value for a check of CAP_DEVICEONLINE should always be TWRC_SUCCESS. It only indicates that the call was successfully processed. The contents of the capability container must be examined to check for TRUE or FALSE.
If an application wants to know about the availability of a device *before* opening it with TWAIN, it has to perform checks using tools provided by the operating system. In the case of Windows this can be done using by registering for WIA events (http://msdn.microsoft.com/en-us/library/windows/desktop/ms629856(v=vs.85).aspx). In the case of Linux it can be done using a popen to the command line “lsusb” (among other ways). In the case of Mac OS X it can be done using a popen to the command line “system_profiler SPUSBDataType” (among other ways).
- AuthorPosts