Macro Scheduler Floating Point DTWAIN Examples
Here are some examples of usage of Macro Scheduler and handling of floating point in DTWAIN:
Example 1: Set the current resolution value:
LibLoad> DTWAIN32.DLL,hLib If> hLib <> 0 // check if TWAIN is available LibFunc> hLib,DTWAIN_IsTwainAvailable,avail
If> avail<> 0 // Initialize the library LibFunc> hLib,DTWAIN_SysInitialize,ret
// Select the source LibFunc> hLib,DTWAIN_SelectSource,TwainSource
If> TwainSource <> 0 LibFunc> hLib,DTWAIN_SetResolutionString,bOk,TwainSource,300.0 If> bOk <> 0 // create a buffer that is 255 in length Let> buffer_SIZE=255 LibFunc> hLib,DTWAIN_GetResolutionString,bOk,TwainSource,buffer MessageModal>Window Text: %bOk_2% EndIf EndIf
// Close Source and shutdown DTWAIN LibFunc> hLib,DTWAIN_SysDestroy,ret2 EndIf
// Unload the DLL LibFree> hLib Endif
In Example 1, the function DTWAIN_SetResolutionString and DTWAIN_GetResolutionString act exactly the same as DTWAIN_SetResolution and DTWAIN_GetResolution, with the lone exception being that the last parameter of the DTWAIN_xxxString() function is a string value instead of a DTWAIN_FLOAT. This allows Macro Scheduler programmers to use string values instead of floating point variables. Note that for DTWAIN_GetResolutionString, the buffer must be sized before sending it to the DTWAIN function that gets the data.
In addition, the Macro Scheduler paradigm of returning values based on position (the bOk_2) is done to retrieve the resolution value. Please consult the Macro Scheduler documentation on retrieving values from a DLL function.
Example 2: Get all of the resolution values. This example shows conversion of an array of floating point values to fixed point values.
Let> fixedPtArray = 0 Let> whole=0 Let> frac=0 Let> floatArrayRef=0 LibLoad> DTWAIN32.DLL,hLib If> hLib <> 0 // check if TWAIN is available LibFunc> hLib,DTWAIN_IsTwainAvailable,avail
If> avail<> 0 // Initialize the library LibFunc> hLib,DTWAIN_SysInitialize,ret
// Select the source LibFunc> hLib,DTWAIN_SelectSource,TwainSource
If> TwainSource <> 0 // get the resolution values LibFunc> hLib,DTWAIN_EnumResolutionValues,floatArray,TwainSource,ref:floatArrayRef,1
// get the number of resolution values LibFunc> hLib,DTWAIN_ArrayGetCount,numValues,floatArray_2 If> numValues <> 0
// convert to fixed point array LibFunc> hLib,DTWAIN_ArrayConvertFloatToFix32,fixedPtArray,floatArray_2
// output the values Let> i=0 Let> strValue= While> i < numValues // whole and frac contain the values in the array LibFunc> hLib,DTWAIN_ArrayFix32GetAt,numParts,fixedPtArray,i,ref:whole,ref:frac LTrim> numParts_3,numParts_3 LTrim> numParts_4,numParts_4 ConCat> strValue,numParts_3 ConCat> strValue,. ConCat> strValue,numParts_4 ConCat> strValue,CRLF Add> i,1 EndWhile MessageModal>Resolution Values: %CRLF% %strValue% EndIf Endif // Close Source and shutdown DTWAIN LibFunc> hLib,DTWAIN_SysDestroy,ret2 EndIf Endif
Note that the call to DTWAIN_ArrayConvertFloatToFix32 converts the array of 64-bit floating point values to an array of fixed point values (The device resolution values are potentially floating point value, thus the need to use floating point types to store this information). Once that's done, to get the whole number and fractional portion of the fixed point number, the DTWAIN_ArrayFix32GetAt function returns the whole number and fractional portion of the desired number.
|