Case 9 is executed two times

Questions, comments and suggestions concerning VintaSoft Twain .NET SDK.

Moderator: Alex

Post Reply
mywebforall
Posts: 15
Joined: Wed Mar 01, 2023 2:35 pm

Case 9 is executed two times

Post by mywebforall »

Hi Alex,

here is the code :

Code: Select all

try {
            // open TWAIN device manager
            self.twainDeviceManager.open(self.twainDeviceManagerInitSettingsJS);

            // // get the default TWAIN device
            // twainDevice = twainDeviceManager.get_DefaultDevice();

            // open TWAIN device (display device UI and display dialog with image scanning progress)
            twainDevice.open(false, true);

            // specify that grayscale images must be acquired from TWAIN scanner
            twainDevice.set_PixelType(new Vintasoft.Twain.WebPixelTypeEnumJS("Gray"));

            // create collection for images acquired from TWAIN scanner
            var acquiredImages = new Vintasoft.Twain.WebAcquiredImageCollectionJS(self.twainDeviceManager);

            var acquireModalState;
            //var savedImageCount = 0;
            do {
                // do one step of modal image acquisition process
                var acquireModalResult = twainDevice.acquireModalSync();
                // get state of image acquisition
                acquireModalState = acquireModalResult.get_AcquireModalState().valueOf();
                l('acquiremodalstate');
                l(acquireModalState);

                switch (acquireModalState) {
                    case 2:   // image is acquired
                        // get acquired image
                        var acquiredImage = acquireModalResult.get_AcquiredImage();
                        // add acquired image to the collection of acquired images
                        acquiredImages.add(acquiredImage);
                        // save acquired image to "result.pdf" file
                        console.log(acquiredImages);
                        //acquiredImages.saveImages("C:\\Users\\luigi\\Desktop\\PDF\\"+nome_file+".pdf", false, [ acquiredImage.get_Id() ]);
                        //savedImageCount = savedImageCount + 1;
                        break;
                    case 4:   // scan is failed
                        alert(acquireModalResult.get_ErrorMessage());
                        break;
                    case 9:   // scan is finished
                        let params = {};
                        var imageIds = []
                        // for each acquired image
                        for (var i = 0; i < acquiredImages.get_Count(); i++) {
                            // add image identifier to array of image identifiers
                            imageIds.push(acquiredImages.getItem(i).get_Id());
                        }
                        // save images to an image file and return file data as a Base64 string
                        var imageFileAsBase64String = acquiredImages.getAsBase64String(nome_file + '.pdf', imageIds);
                        // l(imageFileAsBase64String);
                        params.fileToUpload = imageFileAsBase64String;
                        params.nomeFile = nome_file;
                        let connection = new Connection('scansioni/pdfupload', params, true);
                        connection.go().then(function (response) {
                            if (response.result == "success") {
                                alert("Scansione caricata con successo");
                                self.initLoadListaPdfUtente();
                            }
                            else {
                                console.log(response);
                            }



                        });
                        break;
                }
            }
            while (acquireModalState !== 0);
        
I cannot understand why everytime a click the scan button , the case 9 is executed two times.
The only thing that comes to my mind is something related to the time needed to reach this statement "while (acquireModalState !==0);".
Could you help me to figure it out?

Thank you in advance.

Luigi
Alex
Site Admin
Posts: 2305
Joined: Thu Jul 10, 2008 2:21 pm

Re: Case 9 is executed two times

Post by Alex »

Hi Luigi,

Thank you for information. For understanding the problem we need to analyze log-file, which contains information about TWAIN scanner work.

Please do the following steps:
  • Open file "C:\Program Files (x86)\VintaSoft\Web TWAIN Service 14.0\VintasoftWebTwainService.ini" and change parameter "TWAINLOGGING" from 0 to 1.
  • Restart VintaSoft Web TWAIN service.
  • Open your web application in web browser and acquire images from TWAIN scanner.
  • Send log-file "C:\Users\%USERNAME%\AppData\Local\Temp\VSWebTwainService32-debug.log" to our support (support@vintasoft.com) for analysis.
Best regards, Alexander
Post Reply