Register

Serial Number

Discuss issues related to the fx-9860G Software Development Kit
Senior Member
User avatar
Posts: 605
Joined: Sat Sep 15, 2012 6:59 am
Location: Krautland ****
Calculators: Casio fx-7400GII, Casio fx-7400GII (SH4), Casio fx-9750GII, Casio fx-9750GII (SH4), Casio fx-9860G, Casio fx-9860G SD, Casio fx-9860G Slim, Casio fx-9860GII SD, Casio fx-9860GII SD Power Graphic 2, Casio Classpad 330 plus, Casio fx-CG20, Casio fx-CG50, Casio Classpad fx-CP400

Re: Serial Number

Postby SimonLothar » Thu Jun 20, 2013 9:28 pm

Put the call of memcpy inside of the addin_main body.
The variable declarations should be placed there, too. Global variables are stored in static RAM, which is a short supply.
It is not necessary to convert the calculator ID. It is already a string.


Code: Select all
#include "fxlib.h"
#include "stdlib.h"


int AddIn_main(int isAppli, unsigned short OptionNum)
{
unsigned int key;
char workbuffer[9];

   memcpy( (void*)0x8000FFD0, (void*)workbuffer, 8 );
   workbuffer[8] = 0;
   locate(1,4);
   Print((unsigned char*)workbuffer);

    while(1){
        GetKey(&key);
    }

    return 1;
}
I'll be back!

Junior Member
Posts: 17
Joined: Sun May 27, 2012 4:38 pm
Location: Germany
Calculators: Casio fx-9860GII

Re: Serial Number

Postby Canta » Fri Jun 21, 2013 6:59 pm

Thanks for the correction. I tried the new code but the emulator (SDK) says:
Execution has stopped due an error. Nonexisting data by write access at 8000FFD0

I've tried it also on the calculator, there was no error but he doesn't locate the ID.

Senior Member
User avatar
Posts: 605
Joined: Sat Sep 15, 2012 6:59 am
Location: Krautland ****
Calculators: Casio fx-7400GII, Casio fx-7400GII (SH4), Casio fx-9750GII, Casio fx-9750GII (SH4), Casio fx-9860G, Casio fx-9860G SD, Casio fx-9860G Slim, Casio fx-9860GII SD, Casio fx-9860GII SD Power Graphic 2, Casio Classpad 330 plus, Casio fx-CG20, Casio fx-CG50, Casio Classpad fx-CP400

Re: Serial Number

Postby SimonLothar » Fri Jun 21, 2013 7:27 pm

Holy smoke! I'm getting old.

This should do:

memcpy( (void*)workbuffer, (void*)0x8000FFD0, 8 );

Sorry
I'll be back!

Junior Member
Posts: 17
Joined: Sun May 27, 2012 4:38 pm
Location: Germany
Calculators: Casio fx-9860GII

Re: Serial Number

Postby Canta » Fri Jun 21, 2013 11:16 pm

Yeah, now it works. Thanks!

Junior Member
Posts: 9
Joined: Wed Feb 14, 2018 2:18 pm
Calculators: Casio fx-9860GII SD Power Graphic 2

Re: Serial Number

Postby qferqo » Fri Mar 23, 2018 10:39 am

A memcpy isn't necessary, the following suffices:
Code: Select all
//8-byte unique ID
const unsigned char * deviceId = (unsigned char *) 0xA000FFD0;


Then you can use deviceId the same way as you'd use workbuffer, except for writing of course.

Senior Member
User avatar
Posts: 605
Joined: Sat Sep 15, 2012 6:59 am
Location: Krautland ****
Calculators: Casio fx-7400GII, Casio fx-7400GII (SH4), Casio fx-9750GII, Casio fx-9750GII (SH4), Casio fx-9860G, Casio fx-9860G SD, Casio fx-9860G Slim, Casio fx-9860GII SD, Casio fx-9860GII SD Power Graphic 2, Casio Classpad 330 plus, Casio fx-CG20, Casio fx-CG50, Casio Classpad fx-CP400

Re: Serial Number

Postby SimonLothar » Fri Apr 06, 2018 4:59 pm

qferqo wrote:A memcpy isn't necessary, the following suffices:
Code: Select all
//8-byte unique ID
const unsigned char * deviceId = (unsigned char *) 0xA000FFD0;


Then you can use deviceId the same way as you'd use workbuffer, except for writing of course.

The problem with the serial number is, that it is not terminated by a zero. Usually it is followed by a series of 0xFF.
Functions, which rely on the terminating zero, would give unexpected results.
I'll be back!

Junior Member
Posts: 9
Joined: Wed Feb 14, 2018 2:18 pm
Calculators: Casio fx-9860GII SD Power Graphic 2

Re: Serial Number

Postby qferqo » Fri Apr 06, 2018 7:48 pm

SimonLothar wrote:
qferqo wrote:A memcpy isn't necessary, the following suffices:
Code: Select all
//8-byte unique ID
const unsigned char * deviceId = (unsigned char *) 0xA000FFD0;


Then you can use deviceId the same way as you'd use workbuffer, except for writing of course.

The problem with the serial number is, that it is not terminated by a zero. Usually it is followed by a series of 0xFF.
Functions, which rely on the terminating zero, would give unexpected results.


I think one really shouldn't rely on a zero terminator when working with serial numbers, as they might contain zeroes, which would cause weird behaviour anyway. Also, since the serial numbers have a fixed length (8 bytes) a zero terminator isn't necessary at all. E.g., for comparing serial numbers, one could use 'memcmp(id1, id2, idLength)' instead of 'strcmp(id1, id2).'

EDIT:

Casting the address to an array of integers, which are 4 bytes on the calculators, would only require two int compares instead of eight byte compares and thus fewer instructions have to be executed. I haven't tested if this is actually any faster than doing a memcmp, because the compiler might do some optimisations, and I doubt that there is a big difference in speed, but it's just something I wanted to note.

Member
User avatar
Posts: 39
Joined: Fri Aug 21, 2015 11:54 am
Location: France
Calculators: Casio fx-9750GII, Casio fx-9750GII (SH4), Casio fx-9860GII, Casio fx-CG50

Re: Serial Number

Postby lephe » Fri Apr 06, 2018 8:37 pm

As a quick note: any decent compiler (and there I mean GCC) would optimize this out. It would also notice the 4-byte alignment and you'd end up with two memory accesses per region for a comparison (assuming you convince it of expanding the call, which is admittedly not that easy).

Anyway, we're talking about 8 bytes here, so it's not even significant.

Senior Member
User avatar
Posts: 605
Joined: Sat Sep 15, 2012 6:59 am
Location: Krautland ****
Calculators: Casio fx-7400GII, Casio fx-7400GII (SH4), Casio fx-9750GII, Casio fx-9750GII (SH4), Casio fx-9860G, Casio fx-9860G SD, Casio fx-9860G Slim, Casio fx-9860GII SD, Casio fx-9860GII SD Power Graphic 2, Casio Classpad 330 plus, Casio fx-CG20, Casio fx-CG50, Casio Classpad fx-CP400

Re: Serial Number

Postby SimonLothar » Sat Apr 07, 2018 5:56 pm

qferqo wrote:I think one really shouldn't rely on a zero terminator when working with serial numbers, as they might contain zeroes, which would cause weird behaviour anyway.
Just to ensure that people, who use the serial number in their programs, are not concerned: The serial number of the casio fx-9860 calculators (prizm as well) is a 8 character alphanumeric ASCII string. It cannot contain binary zeros. Using workbuffer with ASCIIZ-functions f. i. strcmp would be still safe.
I'll be back!

Junior Member
Posts: 9
Joined: Wed Feb 14, 2018 2:18 pm
Calculators: Casio fx-9860GII SD Power Graphic 2

Re: Serial Number

Postby qferqo » Sun Apr 08, 2018 6:24 pm

Thanks for the clarification! I wasn't aware of that fact.

PreviousNext

Return to Casio fx-9860 SDK

Who is online

Users browsing this forum: No registered users and 23 guests