Skip to content

Commit

Permalink
added the rollback command to help when errors occur in scripts (like…
Browse files Browse the repository at this point in the history
… paper jams); fixed 110 - basic printing badge so that it's complete, at this point feedback will be needed to make more fixes to it...
  • Loading branch information
mlmcl62 committed Jul 30, 2021
1 parent 0c9e99a commit eb6e805
Show file tree
Hide file tree
Showing 10 changed files with 259 additions and 240 deletions.
90 changes: 47 additions & 43 deletions twaincs/source/TWAIN.cs
Original file line number Diff line number Diff line change
Expand Up @@ -801,9 +801,10 @@ IntPtr a_intptrLparam
/// automatic resync if it detects a sequence error...
/// </summary>
/// <param name="a_stateTarget">The TWAIN state that we want to end up at</param>
/// <param name="a_blUseThread">Use the thread (most cases)</param>
static int s_iCloseDsmDelay = 0;
[SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
public TWAIN.STATE Rollback(STATE a_stateTarget)
public TWAIN.STATE Rollback(STATE a_stateTarget, bool a_blUseThread = true)
{
int iRetry;
STS sts;
Expand All @@ -816,61 +817,64 @@ public TWAIN.STATE Rollback(STATE a_stateTarget)
}

// Submit the work to the TWAIN thread...
if (m_runinuithreaddelegate != null)
if (a_blUseThread)
{
lock (m_lockTwain)
if (m_runinuithreaddelegate != null)
{
// No point in continuing...
if (m_twaincommand == null)
lock (m_lockTwain)
{
return (m_state);
}
// No point in continuing...
if (m_twaincommand == null)
{
return (m_state);
}

// Set the command variables...
ThreadData threaddata = default(ThreadData);
threaddata.blExitThread = true;
long lIndex = m_twaincommand.Submit(threaddata);
// Set the command variables...
ThreadData threaddata = default(ThreadData);
threaddata.blExitThread = true;
long lIndex = m_twaincommand.Submit(threaddata);

// Submit the command and wait for the reply, the delay
// is needed because Mac OS X doesn't gracefully handle
// the loss of a mutex...
s_iCloseDsmDelay = 0;
CallerToThreadSet();
ThreadToRollbackWaitOne();
Thread.Sleep(s_iCloseDsmDelay);
// Submit the command and wait for the reply, the delay
// is needed because Mac OS X doesn't gracefully handle
// the loss of a mutex...
s_iCloseDsmDelay = 0;
CallerToThreadSet();
ThreadToRollbackWaitOne();
Thread.Sleep(s_iCloseDsmDelay);

// Clear the command variables...
m_twaincommand.Delete(lIndex);
// Clear the command variables...
m_twaincommand.Delete(lIndex);
}
}
}
else if ((m_threadTwain != null) && (m_threadTwain.ManagedThreadId != Thread.CurrentThread.ManagedThreadId))
{
lock (m_lockTwain)
else if ((m_threadTwain != null) && (m_threadTwain.ManagedThreadId != Thread.CurrentThread.ManagedThreadId))
{
// No point in continuing...
if (m_twaincommand == null)
lock (m_lockTwain)
{
return (m_state);
}
// No point in continuing...
if (m_twaincommand == null)
{
return (m_state);
}

// Set the command variables...
ThreadData threaddata = default(ThreadData);
threaddata.stateRollback = a_stateTarget;
threaddata.blRollback = true;
long lIndex = m_twaincommand.Submit(threaddata);
// Set the command variables...
ThreadData threaddata = default(ThreadData);
threaddata.stateRollback = a_stateTarget;
threaddata.blRollback = true;
long lIndex = m_twaincommand.Submit(threaddata);

// Submit the command and wait for the reply, the delay
// is needed because Mac OS X doesn't gracefully handle
// the loss of a mutex...
s_iCloseDsmDelay = 0;
CallerToThreadSet();
ThreadToRollbackWaitOne();
Thread.Sleep(s_iCloseDsmDelay);
// Submit the command and wait for the reply, the delay
// is needed because Mac OS X doesn't gracefully handle
// the loss of a mutex...
s_iCloseDsmDelay = 0;
CallerToThreadSet();
ThreadToRollbackWaitOne();
Thread.Sleep(s_iCloseDsmDelay);

// Clear the command variables...
m_twaincommand.Delete(lIndex);
// Clear the command variables...
m_twaincommand.Delete(lIndex);
}
return (m_state);
}
return (m_state);
}

// If we get a sequence error, then we'll repeat the loop from
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,23 @@ setlocal certifyresult 'fail'



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ICAP_XFERMECH: get the xfermech so we know which tests to run
;
setlocal name 'ICAP_XFERMECH MSG_GET'
dsmentry src ds dg_control dat_capability msg_get 'ICAP_XFERMECH,0,0,0'
if '${sts:}' != 'SUCCESS' goto MAIN.ICAP_XFERMECH.FAIL
echo.passfail '${get:name}' 'pass'
setglobal g_xfermech '${ret:}
goto MAIN.ICAP_XFERMECH.DONE
;
:MAIN.ICAP_XFERMECH.FAIL
echo.passfail '${get:name}' 'fail - ${sts:} ${ret:}'
setlocal certifyresult 'fail'
:MAIN.ICAP_XFERMECH.DONE



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; All done...
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Initialize stuff, load tables if not already done for us...
;
echo.titlesuite 'Basic Printing Badge v1.0 13-Jul-2021'
echo.titlesuite 'Basic Printing Badge v1.0 30-Jul-2021'
echo.yellow '*************************************************************************************'
echo.yellow '*** This test is for the Basic Printing Badge. Failing means the driver does not ***'
echo.yellow '*** support this functionality. It does not prevent it from being certified. ***'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,12 @@ echo.passfail '${get:indent}${get:name}' 'pass'
; The printer text is behind a handle...
setlocal handle ${getindex:printerdata:${get:twinfo.item.index}}
setlocal printertext '${gethandle:${get:handle}:TWTY_STR255:0}'
echo 'mlm>>> <${get:printertext}>'
;
setlocal name 'TW_INFO[1].Item contains "TWAIN"'
setlocal name 'TW_INFO[1].Item contains "TWAIN" (${get:printertext})'
if '${get:printertext}' !contains 'TWAIN' goto MAIN.ERROR.ECHOPASSFAIL
echo.passfail '${get:indent}${get:name}' 'pass'
;
setlocal name 'TW_INFO[1].Item contains "TEST"'
setlocal name 'TW_INFO[1].Item contains "TEST" (${get:printertext})'
if '${get:printertext}' !contains 'TEST' goto MAIN.ERROR.ECHOPASSFAIL
echo.passfail '${get:indent}${get:name}' 'pass'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,16 @@
; arg:4 - test name for the image folder
; arg:5 - expected value for TWEI_PRINTER
;
; Globals
; g_capprinter - value of CAP_PRINTER, used to check TWEI_PRINTER
;
; Locals
; name - current test being done
; indent - indent the passfail text
; twimageinfo.compression - compression for current image
; showui - value of showui
;
; image.count - count of images from 1
; image.folder - folder to put the images in
;
; feederenabled.list - scanner's feederenabled values
; feederenabled.index - index of feederenabled values
; feederenabled.value - current feederenabled value
;
; pixeltype.list - scanner's pixeltype values for this feederenabled
; pixeltype.index - index of pixeltype values
; pixeltype.value - current pixeltype value
;
; Returns
; pass or fail
;
Expand All @@ -62,18 +55,31 @@ return 'pass'
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Initialize...
;
echo.titletest 'DAT_IMAGEFILEXFER v1.0 28-Jun-2021'
echo.titletest 'DAT_IMAGEFILEXFER v1.0 30-Jul-2021'
;
setlocal indent ''
setlocal image.count '0'
setlocal image.folder '${folder:certimages}/${arg:4}/DAT_IMAGEFILEXFER'
setlocal image.showname ''
setlocal showui '${arg:3}'
;
setglobal g_barcodemaxsearchpriorities.max '0'
setglobal g_barcodecount.none '0'
setglobal g_barcodecount.one '0'
setglobal g_barcodecount.many '0'
setglobal g_capprinter ''



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Prompt the user...
;
echo.prompt
echo.prompt "Scanning will take place during this test. There will be no"
echo.prompt "need to press any button on the TWAIN user interface to start"
echo.prompt "the scanner. A progress indicator may appear during scanning."
echo.prompt
echo.prompt "Place 1 sheet in the scanner's feeder. The scanner will print"
echo.prompt "text on this sheet."
echo.prompt
pause '(press the ENTER key when ready to continue)'
echo.prompt



Expand All @@ -89,31 +95,27 @@ image cleanfolderandmeta '${get:image.folder}'
; This resets the driver and sets all the capabilities we need for the test.
; If its return code is not 'pass', end with an error
;
run SetCapabilities 'TWSX_FILE' '${get:indent}'
run SetCapabilities 'TWSX_FILE' '${get:indent}' g_capprinter
if '${ret:}' != 'pass' goto MAIN.ERROR.FAIL



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Prompt the user...
; Check for paper in the feeder, prompt the user if we don't find any...
;
dsmentry src ds dg_control dat_capability msg_getcurrent 'CAP_FEEDERLOADED,0,0,0'
if '${sts:}' != 'SUCCESS' goto MAIN.FEEDERLOADED.DONE
if '${ret:${get:TW_ONEVALUE.Item}}' ~~ 'TRUE' goto MAIN.FEEDERLOADED.DONE
echo.prompt
echo.prompt "Scanning will take place during this test. There will be no"
echo.prompt "need to press any button on the TWAIN user interface to start"
echo.prompt "the scanner. A progress indicator may appear during scanning."
echo.prompt
echo.prompt "Place 1 sheet in the scanner's feeder. The scanner will print"
echo.prompt "text on this sheet."
echo.prompt
echo.prompt "Place paper in the scanner's feeder."
pause '(press the ENTER key when ready to continue)'
echo.prompt
:MAIN.FEEDERLOADED.DONE



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Start scanning...
;
:MAIN.USERINTERFACE
setlocal name 'dg_control/dat_userinterface/msg_enableds'
wait reset
dsmentry src null dg_control dat_userinterface msg_enableds '${get:showui},0'
Expand Down Expand Up @@ -178,9 +180,9 @@ echo.passfail '${get:indent}image <${get:image.showname}>' 'pass'

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; DAT_EXTIMAGEINFO
; Check the barcode metadata...
; Check the printer metadata...
;
run DAT_EXTIMAGEINFO '${get:indent}' '${get:image.folder}/adf${format:D6|${get:image.count}}' '${get:g_printer}'
run DAT_EXTIMAGEINFO '${get:indent}' '${get:image.folder}/adf${format:D6|${get:image.count}}' ${get:g_capprinter}
if '${ret:}' != 'pass' goto MAIN.ERROR.FAIL


Expand All @@ -206,36 +208,6 @@ echo.passfail '${get:indent}${get:name}' 'pass'



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Check to see if we passed. We need one sheet of paper with no barcodes. Two or more sheets
; with one barcode, and no sheets with multiple barecodes if the maximum value of
; ICAP_BARCODEMAXSEARCHPRIORITIES is 1. And one or more sheets with one barcode, and one or
; more sheets with multiple barcodes of ICAP_BARCODEMAXSEARCHPRIORITIES is greater than 1.
;
setlocal name 'Final Check: detected a sheet with 0 barcodes
if '${get:g_barcodecount.none}' < '1' goto MAIN.ERROR.ECHOPASSFAIL
echo.passfail '${get:indent}${get:name}' 'pass'
;
if '${get:g_barcodemaxsearchpriorities.max}' >= '2' goto MAIN.FINALCHECK.MANYBARCODES
setlocal name 'Final Check: detected multiple sheets with 1 barcode'
if '${get:g_barcodecount.one}' < '1' goto MAIN.ERROR.ECHOPASSFAIL
echo.passfail '${get:indent}${get:name}' 'pass'
setlocal name 'Final Check: detected 0 sheets with many barcodes (not supported)'
if '${get:g_barcodecount.many}' > '0' goto MAIN.ERROR.ECHOPASSFAIL
echo.passfail '${get:indent}${get:name}' 'pass'
goto MAIN.FINALCHECK.DONE
;
:MAIN.FINALCHECK.MANYBARCODES
setlocal name 'Final Check: detected a sheet with 1 barcode'
if '${get:g_barcodecount.one}' < '1' goto MAIN.ERROR.ECHOPASSFAIL
echo.passfail '${get:indent}${get:name}' 'pass'
setlocal name 'Final Check: detected a sheet with many barcodes'
if '${get:g_barcodecount.many}' < '1' goto MAIN.ERROR.ECHOPASSFAIL
echo.passfail '${get:indent}${get:name}' 'pass'
:MAIN.FINALCHECK.DONE



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Summary and cleanup...
;
Expand All @@ -248,9 +220,11 @@ return 'pass'
:MAIN.ERROR.ECHOPASSFAIL
echo.passfail '${get:indent}${get:name}' 'fail - ${sts:} ${ret:}'
echo.passfail 'SUMMARY' 'fail'
rollback state4
return 'fail'
;
; Ruh-roh...
:MAIN.ERROR.FAIL
echo.passfail 'SUMMARY' 'fail'
rollback state4
return 'fail'
Loading

0 comments on commit eb6e805

Please sign in to comment.