Trust ID PBCEX logo 300x102

Conditionally expand the number of leading zeroes

7 years 7 months ago 7 years 7 months ago by Emiel.
Emiel
Senior Boarder
Senior Boarder
Posts: 78
More
Topic Author
Conditionally expand the number of leading zeroes #4026
Hi,

We have made a generic CE definition which prints Mifare cards with mixed 4-byte and 7-byte Mifare IDs. In CE you can specify per definition if you want to read a 7- or 4-byte UID for storage, but not both. Furthermore, you can fill in upto how many characters you want to have leading zeroes applied.

So, when you fill in 8, the id 123456 will become 00123456, when you fill in 14, ABCDE12345678 will become 0ABCDE12345678, but a 4-byte UID of 12345678 will then become 00000012345678 and that's not what we want, it should stay 12345678. On the other hand a long id should not be truncated.

Is there a solution for this?

Thanks in advance,

Emiel
7 years 7 months ago
Sergio Agostinho
Administrator
Administrator
Posts: 508
More
Conditionally expand the number of leading zeroes #4027
Hi Emiel,

Please define the uid to 7 bytes and don't use the leading zeros function, if i remember it well CardExchange will return 4 or 7 bytes depending on the type of card used.

Looking forward for your feed-back.

With best regards
Sergio Agostinho
7 years 7 months ago
Emiel
Senior Boarder
Senior Boarder
Posts: 78
More
Topic Author
Conditionally expand the number of leading zeroes #4028
Hi Sergio,

The problem is that if I turn off leading zeroes, there won't be any leading zeroes, which we do want to have. If I turn off the 7-byte uid option, and fill in 0 at "minimum number of digits" the number is truncated up until max. 8 characters.
If I turn on 7-byte option and fill in 0 at "minimum number of digits" the number 01234567ABCDEF gets truncated to 1234567ABCDEF, which should not happen.

So a 4-byte UID of 123546 should be stored as 00123546, a 7-byte UID of 1234567ABCDEF should be stored as 01234567ABCDEF.

I hope it's clear what I mean.

Regards,

Emiel
7 years 7 months ago 7 years 7 months ago by Sergio Agostinho.
Sergio Agostinho
Administrator
Administrator
Posts: 508
More
Conditionally expand the number of leading zeroes #4029
Hi Emiel,

CardExchange removes the leading zeros on the Mifare serial number except if you define a minimum number of digits, this is the same behavior as other windows application like the calculator for example. The only way to workaround the 4 bytes cards problem and remove the additional extra leading zeros when the minimum number of digits is 14 is to make a python script for that field to do it. Check the designer steps below for CardExchange 7 or higher and Ultimate version:
Define the
  • function below on the functions tab
    def formatSN(s):
      if s.startswith('000000'):
        return s.replace('0', '', 6)
      else:
        return s;
  • Add a text object to the card and map it as script like "formatSN(MifareSN)", this will call the function defined above and will create a variable named MifareSN which you need to map in the mappings window as Mifare serial number in hex format with a minimum number of 14 digits.

I think this will easily solve the issue.

With best regards
Sergio Agostinho
7 years 7 months ago
Emiel
Senior Boarder
Senior Boarder
Posts: 78
More
Topic Author
Conditionally expand the number of leading zeroes #4030
Okay, thanks for your clear answer. This means for us it's not possible to do, as we are currently using CE 6 Ultimate.

Now I'm thinking about invoking some custom execute script. If I'm correct, CE executes SQL INSERT statements to insert data in the database. If we could use a stored proc instead of that, I could write the INSERT in that stored proc and add additional SQL after that to fix the alignment.

Could this be possible?

Regards,

Emiel
7 years 7 months ago 7 years 7 months ago by Rutger Koperdraad. Reason: added info
Rutger Koperdraad
Platinum Boarder
Platinum Boarder
Posts: 1566
More
Conditionally expand the number of leading zeroes #4031
Hi Emiel,

You can also use a script in version 6 on a data-text object:
[IIf(Copy(<UID>,1,6)='000000',Copy(<UID>,7,8),<UID>)]


If you want to use stored procedures, you need a plug-in. You could use update triggers for when the UID is updated in the database, but using a script is probably easier to implement.

regards,
Rutger.

Rutger Koperdraad
Senior Software Engineer

"A reasonable man adapts himself to the world. The unreasonable man persists in trying to adapt the world to himself. All progress, therefore, depends on the unreasonable man." (Bernard Shaw)
Attachments:
7 years 7 months ago
Emiel
Senior Boarder
Senior Boarder
Posts: 78
More
Topic Author
Conditionally expand the number of leading zeroes #4035
Hi Rutger,

I'm able to prefix the id with leading zeroes, but only visually. How can I then store the result in the database?

Regards,

Emiel
7 years 7 months ago
Sergio Agostinho
Administrator
Administrator
Posts: 508
More
Conditionally expand the number of leading zeroes #4037
Hi Emiel,

If you use one of the scripts above into a database storage item it doesn't store the handled value instead of the original one?

With best regards
Sergio Agostinho
7 years 7 months ago
Emiel
Senior Boarder
Senior Boarder
Posts: 78
More
Topic Author
Conditionally expand the number of leading zeroes #4038
Hi Sergio,

I use mappings as variables for the data text object. Mappings can only be either visual items or storage items. If I use a script, the result (prefixed with zeroes) is only shown in the visual item and is not stored.

Maybe I'm missing some step I need to take in between to get the two linked together?

Regards,

Emiel
7 years 7 months ago
Sergio Agostinho
Administrator
Administrator
Posts: 508
More
Conditionally expand the number of leading zeroes #4041
Hi Emiel,

Indeed, on CardExchange 6 the designer doesn't allow storage items mappings using the scripting language, this is only possible on CardExchange 7 or higher because of the new designer available on the newer versions. Sorry but my brain was not in version 6 mode i my last answer.

With best regards
Sergio Agostinho