circuitcellar.com
Magazine Support   Digital Library   Products & Services   Suppliers Directory 
 
 





 

March 2004, Issue 164

BasicCard 101(Part 1):
Program Your First Smartcard


PICK YOUR API

ZeitControl provides a number of application programming interfaces (API) to the commonly used high-level languages. They can be found on the development kit’s CD-ROM (in the API folder), but I chose to download them from ZeitControl’s web site, figuring I’d get the newest versions. There are libraries for Visual Basic, C, and Delphi. Although I’ve heard good things about Delphi, I must admit that I haven’t tried it, nor am I proficient in C. I’ve used Visual Basic for years, so that’s the BasicCard API that I picked for my application. Incidentally, the API routines need Visual Basic version 6 to operate.

In addition to the API and documentation, there are sample programs that allow you to become familiar with the API itself. Basically, the same examples that are provided using the ZCMBASIC compiler, which produces DOS programs, are duplicated in Visual Basic. If you are producing a commercial application, it’s helpful to know that the necessary runtime files from ZeitControl’s API library can be distributed with your application without any licensing fees. This includes the basic encryption routines. I’m not sure if the more esoteric encryption routines supported by the Professional BasicCards are included in this API.

I got off to a bad start with this aspect of the software. For some unknown reason, I decided to try out a different application than the ones I already had tested out using ZCMBASIC running in DOS. Basically, that meant compiling and downloading a new program into the BasicCard itself. Within the API folder, for each Visual Basic sample application, in addition to the Visual Basic files, there are compile.bat, download.bat, and source code files intended to produce the proper image file for the BasicCard. I already mentioned the tweaking I had to do to make those batch files work with the BasicCards provided in the development kit.

In this case, however, these batch files were completely wrong in that they refer to the compiler by the name it had in an earlier version. I did not expect to have outdated files because I had passed over my development kit’s CD-ROM and downloaded the API files directly from the web site. To get around this problem, I ignored the API folder’s files pertaining to the code meant to be downloaded to the BasicCard. This code, written for ZCMBASIC, is also contained in the BasicCardPro/Examples folder. But, in the latter case, the batch files are the correct version to match the current development software. 

After that shaky start, getting the terminal part of the application to run under Visual Basic was not difficult. Although my earlier BasicCard sample programs ran easily from DOS with the CyberMouse card reader connected to COM1, it was a bit different in Visual Basic. Because Windows can support many different card readers on different types of ports, you must first run an application called “API Select Card Reader” in order to inform Windows which port your reader is connected to. This application can be found on the Start Programs taskbar within the BasicCardPro group. To ZeitControl’s credit, its example code contains a routine that checks to see what the default reader is, and it generates a user-friendly error message, informing you to run this utility program if no default reader is found.

It’s a good thing that several sample Visual Basic applications are included. I have used Visual Basic for many years, but I’m not as familiar with the newer OCX Class libraries as I am with the earlier VBX controls. I don’t mean to get off on a rant here, but a BasicCard sample program in ZCMBASIC, under DOS, is pretty easy to follow. In contrast, a functionally similar program written in Visual Basic would be extremely difficult for a newcomer to write from scratch without first studying some of the Visual Basic sample code. Of course, the same could be said for all modern Windows-based software.

So far, I haven’t mentioned any of the debugging facilities contained in the development software suite. ZeitControl provides various Windows simulator programs for both the Terminal and matching BasicCard parts of an application. You can have a window open running a terminal program as well as another window that is simulating a virtual card in a virtual card reader. I have to admit that I did not make use of these simulators because I prefer to work with real devices running in real time. My application was not complex; but, if it were, the simulators would have probably come in handy.

BASICCARD PROJECT

In the second part of this series, I’ll describe a small project that I designed using an Enhanced BasicCard. The project consists of a board containing a BasicCard socket, an Atmel AVR MCU, and a keypad/LCD user interface. It controls the dispensing of liquid nitrogen (LN2) from a liquid nitrogen generator at Dalhousie University, where I work.