www.vtiinstruments.com
APPENDIX C
101
Here is some example output from READ_SCRATCHPAD using the example code:
sent packet without errors
Packet length: 8
07 82 0A 03 22 AA 00 85
got a packet without errors on receive
Packet length: 39
26 82 00 0A 22 AA 00 AA 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11
12 13 14
15 16 17 18 19 1A 1B 1C 1D 1F 20 21
This is identical to what was written with the WRITE_SCRATCHPAD command, so the data was
written properly. Again, recall that the non-atomic operations cannot be guaranteed, as the 1-wire
devices are powered down between MLAN commands, which erases the scratchpads.
COPY_SCRATCHPAD_2430
The COPY_SCRATCHPAD command is the only method for writing data to the memory of a
MLAN device; it copies the data in the scratchpad to the non-volatile memory. Like
READ_SCRATCHPAD, the command is fairly simple, as the data already exists and only needs to
be moved.
int
copy_scratchpad_2430(IVTEXDigitizerPtr digitizer)
{
int
recLen = 0;
CComSafeArray<
short
> WriteBuf;
WriteBuf.Create();
WriteBuf.Add((
short
)0);
// reserve first byte for length
// access the current device with address in DATA_ID
WriteBuf.Add(CMD_ML_ACCESS);
// construct a block of communication to MicroLAN
WriteBuf.Add(CMD_ML_DATA);
WriteBuf.Add(3);
// block length
WriteBuf.Add(2);
// data length
// send the copy scratchpad command
WriteBuf.Add(COPY_SCRATCHPAD);
// send the validation key
WriteBuf.Add(0xA5);
// delay for 128ms
WriteBuf.Add(CMD_DELAY);
WriteBuf.Add((
short
)0);
WriteBuf.Add(DELAY_128 | DELAY_MS);
// set the length
WriteBuf[0] = (
short
)WriteBuf.GetCount() - 1;
// send the commands
digitizer->Channels->Item[name]->TEDS-
>WriteTEDS(WriteBuf.GetSafeArrayPtr());
std::cout <<
"DS2430 Copy Scratchpad (WriteData)"
<<
std::endl;
PrintPacket(WriteBuf);
// retrieve the response
CComSafeArray<
short
> ReadBuf;
SAFEARRAY* psaReadBuf;
digitizer->Channels->Item[name]->TEDS->ReadTEDS(&psaReadBuf);
std::cout <<
"DS2430 Copy Scratchpad (ReadData)"
<<
std::endl;