ASIGetSerialNumber(camID)

any question related to our SDK and driver

Moderators: yang, chad, ray

Post Reply
grayarea56@gmail.com
Posts: 2
Joined: Thu Aug 29, 2019 4:56 pm

ASIGetSerialNumber(camID)

Post by grayarea56@gmail.com » Tue Sep 10, 2019 5:35 pm

Hi All,
I'm new to the forum, this is my first post.
I'm trying to connect to multiple camera's, and sometimes they come up with different camera ID numbers, based on the order of plugging in the USB ports.
I need to read the serial numbers.
I see a post that references ASIGetSerialNumber
I'm using C#, and importing the DLL(s), either the 32 bit or the 64 bit.
Everything has been working fine.
I upgraded to the very latest development, but the documentation says nothing about ASIGetSerialNumber.
Also, when I call the dll with entry point as ASIGetSerialNumber, it completely restarts my application, not even an exception.
I'm using the very latest devopment dll's version:
ASI_Windows_SDK_V1.14.0715
Dan Gray
siderealtechnology.com

User avatar
chad
Posts: 611
Joined: Thu Feb 09, 2017 4:58 am

Re: ASIGetSerialNumber(camID)

Post by chad » Mon Sep 16, 2019 1:15 am

Hi Dan,
Can you show me the codes which calls GetSerialNumber?
Usually, we used the following code to call it (it is a C++ code):

ASI_SN ASI_sn = {0};
ASIGetSerialNumber(iSelectedID, &ASI_sn);
sn_temp.Format(" SN:%02x%02x %02x%02x %02x%02x %02x%02x", ASI_sn.id[0], ASI_sn.id[1], ASI_sn.id[2], ASI_sn.id[3], ASI_sn.id[4], ASI_sn.id[5], ASI_sn.id[6], ASI_sn.id[7]);

Thanks
Chad
ZWO Driver Engineer
Location:lon=120.6 lat=31.3
SuZhou China

grayarea56@gmail.com
Posts: 2
Joined: Thu Aug 29, 2019 4:56 pm

Re: ASIGetSerialNumber(camID)

Post by grayarea56@gmail.com » Mon Sep 30, 2019 8:37 pm

Thanks for your reply, looking at your code snippet, I think I need the definition of the ASI_SN structure.
It's not in the document I have.

Can you post the ASI_SN structure definition for me? Thanks.
Dan.

P.S.
For your information, here's my code snippets as trying now, after seeing your example, I see why it crashes.

here's my DLL import Section, one for 32 bit, and the other for 64 bit:

[DllImport("ASICamera2.dll", EntryPoint = "ASIGetSerialNumber", CallingConvention = CallingConvention.Cdecl)]
private static extern string ASIGetSerialNumber32(int iCameraID);

[DllImport("ASICamera2_x64.dll", EntryPoint = "ASIGetSerialNumber", CallingConvention = CallingConvention.Cdecl)]
private static extern string ASIGetSerialNumber64(int iCameraID);

Here' the calling code:
internal static string ASIGetSerialNumber(int iCameraID)
{
if (IntPtr.Size == 8) //If 32 bit
return ASIGetSerialNumber64(iCameraID);
return ASIGetSerialNumber32(iCameraID);
}

And finally, here's how I call it in the main program.
string camSerNum = ASICameraDll2.ASIGetSerialNumber(camID);

Dan Gray

User avatar
chad
Posts: 611
Joined: Thu Feb 09, 2017 4:58 am

Re: ASIGetSerialNumber(camID)

Post by chad » Tue Oct 08, 2019 2:54 am

Hi Dan,
you can find it in the header file.
typedef struct _ASI_ID{
unsigned char id[8];
}ASI_ID;

typedef ASI_ID ASI_SN;

And it is defined as this.
Thanks
Chad
ZWO Driver Engineer
Location:lon=120.6 lat=31.3
SuZhou China

ahorton
Posts: 2
Joined: Mon Oct 14, 2019 4:55 am

Re: ASIGetSerialNumber(camID)

Post by ahorton » Tue Oct 15, 2019 6:34 am

I got caught out trying to use the ASIGetSerialNumber() function too. The header file tells you the data structure (array of 8 unsigned char's) but it doesn't tell you how to interpret the values.

I assumed it was like the user set camera ID (as returned by ASIGetID()) because they use the same data structure, and tried to decode it as an 8 character ASCII (or UTF-8) string. That works for camera ID, but not for serial number. I had to look at how the serial number gets displayed in ASICAP to work it out, the serial number is actually a 64 bit integer in disguise...

The serial number is shown as a 16 digit hexadecimal number, and by checking the values of the bytes in the array returned by ASIGetSerialNumber() I worked out that serial number is a 64 bit integer with big-endian byte order.

It probably is time to update the SDK documentation. There are now a number of newer functions missing, and others (like ASIGetID()) would benefit from more explanation of what the parameters and return values actually are. Sometimes the data type + variable name are not enough by themselves to work it out.

User avatar
chad
Posts: 611
Joined: Thu Feb 09, 2017 4:58 am

Re: ASIGetSerialNumber(camID)

Post by chad » Tue Oct 15, 2019 10:23 am

Hi,
Sorry for the trouble.
This SN is read from the Main Chip. It is not created by us. So it is a series of ASCII characters。
You need to display it in hexadecimal.

C++:
CString sn_temp;
ASIGetSerialNumber(iSelectedID, &ASI_sn);
sn_temp.Format(" SN:%02x%02x %02x%02x %02x%02x %02x%02x", ASI_sn.id[0], ASI_sn.id[1], ASI_sn.id[2], ASI_sn.id[3], ASI_sn.id[4], ASI_sn.id[5], ASI_sn.id[6], ASI_sn.id[7]);

Thanks
Chad
ZWO Driver Engineer
Location:lon=120.6 lat=31.3
SuZhou China

Post Reply