www.vtiinstruments.com
APPENDIX C
103
// send the commands
digitizer->Channels->Item[name]->TEDS-
>WriteTEDS(WriteBuf.GetSafeArrayPtr());
std::cout <<
"DS2430 Read Memory (WriteData)"
<< std::endl;
PrintPacket(WriteBuf);
// retrieve the response
CComSafeArray<
short
> ReadBuf;
SAFEARRAY* psaReadBuf;
digitizer->Channels->Item[name]->TEDS->ReadTEDS(&psaReadBuf);
std::cout <<
"DS2430 Read Memory (ReadData)"
<< std::endl;
ReadBuf.Attach(psaReadBuf);
PrintPacket(ReadBuf);
recLen = (
int
)ReadBuf.GetCount();
return
recLen;
}
Again, the first three are the same as those seen in previous examples. The block length is the return
buffer size, the READ_MEMORY command, and the address offset. Since the whole address space
can be read at once on the DS2430, the address offset is always zero. This in not always the case for
the DS2431’s, as the DS2431 has a much larger memory space. See the
Error! Reference source
not found.
command for an example of this.
Note that the return buffer size does have to be big enough to hold the whole address space, so the
standard two bytes of MLAN data are added to the DS2430’s address space size.
Here is an example output from the READ_MEMORY command using the example code:
sent packet without errors
Packet length: 8
07 82 0A 03 22 F0 00 85
got a packet without errors on receive
Packet length: 39
26 82 00 0A 22 F0 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 the same string that was in the WRITE_SCRATCHPAD, now has been transferred into non-
volatile memory.
WRITE_AND_COPY_SCRATCHPAD_2430
As noted above, the scratchpad is a volatile memory location. Between MLAN commands, the 1-
wire devices are powered down, and, hence, will lose all their scratchpad (volatile) data. In example
code below, the commands occur fast enough that power is not lost to the 1-wire devices and no
data loss is experienced. This, however, is not recommended for a production environment.
As a consequence, the WRITE_AND_COPY command set is recommended. These commands are
atomic operations – they perform the write and the copy in a single MLAN command. Because the
read and write is accomplished in a single command, data integrity cannot be verified before it is
copied to memory (e.g. a READ_SCRATCHPAD command cannot be performed in the middle of
a WRITE_AND_COPY command set to verify the scratchpad write). However, the main memory
can still be checked after the write, in a separate series of MLAN operations to ensure that what was
written is correct.
int
write_and_copy_scratchpad_2430(IVTEXDigitizerPtr digitizer,
const
char
* data)
{