Retrieve scanner serial number

Example requests & Code samples for GdPicture Toolkits.
Post Reply
chrisw
Posts: 4
Joined: Tue Oct 05, 2021 10:20 pm

Retrieve scanner serial number

Post by chrisw » Tue Oct 05, 2021 10:28 pm

Is there any code available to retrieve the serial number of the scanner currently being used?

User avatar
Fabio
Posts: 173
Joined: Thu Aug 27, 2020 9:57 am

Re: Retrieve scanner serial number

Post by Fabio » Wed Oct 06, 2021 1:47 pm

Hello Chris,

There is an enumeration in the TWAIN that is called CAP_SERIALNUMBER. But it is optional, you cannot assume that a scanner supports it.
-> https://www.gdpicture.com/guides/gdpict ... ities.html

At the moment, I didn't see any method in our SDK that can get the serial number. I'll check that with the devs and if we do not have it, I'll create a ticket to implement this feature.

I'll keep you posted about it!

With best,
Fabio

chrisw
Posts: 4
Joined: Tue Oct 05, 2021 10:20 pm

Re: Retrieve scanner serial number

Post by chrisw » Wed Oct 06, 2021 4:34 pm

Hello Fabio,

I know my scanner supports the serial number capability. I am using a fujitsu fi-7160 for my software and testing. I added code in the example demo code that was bundled with the sdk to get the serial number

Code: Select all

 MessageBox.Show(gdpictureImaging.TwainGetCapDefaultString(TwainCapabilities.CAP_SERIALNUMBER, ref strSerialNumber).ToString());
Which i am assuming would get me the serial number but it just returns true or false.
I will keep searching different settings to see if i can retrieve it, but i will also wait for a reply from you as well.

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Retrieve scanner serial number

Post by Loïc » Wed Oct 06, 2021 5:15 pm

Hi there,

You are displaying the retuned value of the method which is a status. Your value will be stored into the variable passed by reference, in your case: strSerialNumber

I hope this helps.

With best regards,

Loïc

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Retrieve scanner serial number

Post by Loïc » Wed Oct 06, 2021 5:18 pm

Also you probably want to use the TwainGetCapCurrentString() method instead.
https://www.gdpicture.com/guides/gdpict ... tring.html

so:

Code: Select all

If gdpictureImaging.TwainGetCapDefaultString(TwainCapabilities.CAP_SERIALNUMBER, ref strSerialNumber) = True Then
     MessageBox.Show(strSerialNumber);
Else
  MessageBox.Show("Failed to obtain the specified capability value"); ' ---> see Remark section of the mentioned link.
Else If

chrisw
Posts: 4
Joined: Tue Oct 05, 2021 10:20 pm

Re: Retrieve scanner serial number

Post by chrisw » Wed Oct 06, 2021 5:36 pm

Hello Loic,

I did try the TwainGetCapDefaultString method prior and still did not receive the correct result. i copied the code you provided and did some more testing, which i received the failed error message. I dont know why i was thinking of where i placed my previous code, but i moved the code you provided further up in the example where i set the other twain settings and i did not receive any error messages or the failed error message. I did receive the serial number of my scanner.

i believe if i would have placed my code in the different section, i would have received the serial number.

This is ok, because now i know how helpful this forum is. The responses were great.

I appreciate all the help. I will also continue to wait for Fabio's reply and update.

If i have any issues or questions i will definitely be posting to the forums.

User avatar
Fabio
Posts: 173
Joined: Thu Aug 27, 2020 9:57 am

Re: Retrieve scanner serial number

Post by Fabio » Tue Oct 12, 2021 4:25 pm

Hello Chris,

I'm sorry I'm not sure to understand. Loïc came back to you after seeing the ticket I created regarding your need.
Does the proposed solution isn't suitable on your side?

With best,
Fabio

chrisw
Posts: 4
Joined: Tue Oct 05, 2021 10:20 pm

Re: Retrieve scanner serial number

Post by chrisw » Tue Oct 12, 2021 4:33 pm

Yes, the proposed solution worked. i was just waiting on a response from the you, Fabio, if there was going to be some type of implementation for retrieving the serial number within the SDK. I am in early development stages of my software re-write and if i needed to possibly wait for a newer updated SDK, i would wait to release my software.

User avatar
Fabio
Posts: 173
Joined: Thu Aug 27, 2020 9:57 am

Re: Retrieve scanner serial number

Post by Fabio » Tue Oct 12, 2021 4:54 pm

Hi,

I'm sorry but since the TwainGetCapDefaultString does the job of getting the serial number, I do not think it will be relevant to implement such a feature.

With best,
Fabio

Dolphin1
Posts: 1
Joined: Thu May 11, 2023 3:51 am

Re: Retrieve scanner serial number

Post by Dolphin1 » Thu May 11, 2023 3:54 am

Yes, it is possible to retrieve the serial number of the scanner currently being used in a programmatic way. However, the exact code may vary depending on the type of scanner and the programming language being used. Here is an example: contexto

Code: Select all

using WIA;

// Create a new WIA device manager
var deviceManager = new DeviceManager();

// Get the collection of available devices
var devices = deviceManager.DeviceInfos;

// Iterate through the devices to find the scanner and retrieve its serial number
foreach (DeviceInfo deviceInfo in devices)
{
    // Check if the device is a scanner
    if (deviceInfo.Type == WiaDeviceType.ScannerDeviceType)
    {
        // Retrieve the scanner object
        var scanner = deviceInfo.Connect();

        // Retrieve the serial number of the scanner
        var serialNumber = (string)scanner.Properties["Serial Number"].get_Value();

        // Display the serial number
        Console.WriteLine($"Serial number of the scanner: {serialNumber}");
    }
}

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 1 guest