IcnReadPageRange
Purpose: Read consecutive pages (each 32 bytes) from button
Prototype: Handle IcnReadPageRange(CharPtr startPageID, CharPtr endPageID, Boolean CRC, Boolean OD, ULong keyCode,
Err * errP);
Parameters:
startpageID 2 character page address,
endPageID 2 character page address,
CRC if true, read using button-generated CRC,
if false read without CRC
OD if true, operating button at OverDrive speed,
if false, operate at regular speed
keyCode encryption key, keyCode=0 for no encryption
errP pointer to error code returned by function
Result: returns a handle to the data read from button
Error codes:
0 no error
icnErrIncomplete insufficient data received
icnErrTimeout no response from reader in prescribed time
icnErrBadPageNumber could not compute amount of memory to allocate
from page numbers provided.
serErrBadParm serial port invalid or missing parameter
serErrTimeout serial port interbyte timeout exceeded
serErrLineErr unrecoverable line error occured
memErrNotEnoughSpace memory manager error in allocation
Comment: This function is an effective way to read a large amount of data quickly. Function computes data size and allocates sufficient memory. If endPageID is not greater than or equal to startPageID, function returns icnErrBadPageNumber error, makes no attempt to read. Function issues read command, moves received data into the memory location and returns a handle to memory. If an error is detected, function moves error code to specified pointer. On return, check the error code and lock the handle to obtain a pointer to the data.
startPageID and endPageID each consist of two ascii characters, each character the equivalent of a hexidecimal digit, 0-9, a-f. This allows addressing 256 pages, 00 to ff. This nomenclature maintains consistency with Dallas Semiconductor documentation. Calling program is responsible for determining if attached button supports over drive, internally generates CRC data and page range is valid. For example, calling this function with CRC=true to read a button without CRC support will return an error.
Usage:
//allocation
Handle buttonDataH;
CharPtr buttonDataP;
VoidHand errH;
VoidPtr errP;
errH = MemHandleNew(sizeof(Err));
errP = MemHandleLock(errH);
//call function to read 256 pages, lock the returned handle and get a pointer to the data.
buttonDataH= IcnReadPageRange("00","ff", false, true, errP);
buttonDataP=MemHandleLock(buttonDataH);
if(!*errP)
{
// do something with the data, display it, check it, store it, etc
}
else
{
//handle or report the error
}
//release the memory
MemHandleFree(buttonDataH);
MemHandleFree(errH);
IcnWritePage
Purpose: Write one page (32 bytes) to the iButton with verification.
Prototype: Err IcnWritePage(CharPtr pageID,
Boolean OD,
Word keyCode,
CharPtr pageDataP);
Parameters:
pageID 2 character page number,
OD if true, operate button at OverDrive speed,
if false, operate at regular speed
keyCode encription key, keyCode=0 for no encription
pageDataP pointer to data to write
Result: returns an error code:
0 if no error
icnErrIncomplete insufficient data received
icnErrTimeout no response from reader in prescribed time
icnErrBadPageNumber could not compute amount of memory to allocate
from page numbers provided.
serErrBadParm serial port invalid or missing parameter
serErrTimeout serial port interbyte timeout exceeded
serErrLineErr unrecoverable line error occured
memErrNotEnoughSpace memory manager error in allocation
Comment: Transmits 32 bytes (encrypted by keyCode if non-zero) to iConnection to be written to iButton at the specified page. On return, check the error code to make sure the button has written the data correctly.
pageID consists of two characters, each character the equivalent of a hexidecimal digit, 0-9, a-f. This allows addressing 256 pages, 00 to ff. This nomenclature maintains consistency with Dallas Semiconductor documentation.
Calling program is responsible for determining if attached button supports overdrive and page ID is valid. For example, calling this function with pageID = ff on a button with only one page will return an error.
Note on verification: Data is transmitted from iConnection manager to iConnection via serial port without verification. IConnection writes data to iButton scratchpad, reads-back data from iButton scratchpad to verify that transmission on 1-wire between iConnection module and iButton occurred without error and if correct, commands iButton to write scratchpad to specified page. Comparision occurs in the iConnection module. Data is not returned to Palm for verification prior to issuing scratchpad write command to iButton. If your application requires verification all the way back to Palm, follow the IcnWritePage command with an IcnReadPage command to recover the data and make your comparison in Palm to verify. Additional time required for this step is longer than if a single transaction were implemented with verification by Palm, but does not impose the extra processing on all applications. Contact Scanning Devices Inc. if you need a special function in this area.
Usage:
//declaration and allocation
Handle buttonDataH;
CharPtr buttonDataP;
Handle pageH;
CharPtr pageP;
Err errorCode;
buttonDataH=MemHandleNew(50);
buttonDataP=MemHandleLock(buttonDataH);
StrCopy(buttonDataP,"Here is some data to store on page 10");
//notice that although string length is 37 characters, only the
//first 32 will be written to the button
pageH=MemHandleNew(10);
pageP=MemHandleLock(pageH);
StrCopy(pageP,"1A"); //page 10
//call function, check the returned errorcode.
errorCode=IcnWritePage(pageP,false,false,buttonDataP);
if(errorCode == 0)
{
StrCopy(buttonDataP,"Button saved OK");
// do something with the data, display it, check it, store it, etc
}
else
{
StrCopy(buttonDataP,"Button reported Error");
//handle or report the error
}
//release the memory
MemHandleFree(buttonDataH);
MemHandleFree(pageP);