www.vtiinstruments.com
APPENDIX C
97
// send the commands
digitizer->Channels->Item[name]->TEDS-
>WriteTEDS(WriteBuf.GetSafeArrayPtr());
std::wcout <<
"Read URN (WriteData)"
<< std::endl;
PrintPacket(WriteBuf);
// retrieve the response for each command
CComSafeArray<
short
> ReadBuf;
SAFEARRAY* psaReadBuf;
digitizer->Channels->Item[name]->TEDS-
>ReadTEDS(&psaReadBuf);
std::wcout <<
"Read URN (ReadData)"
<< std::endl;
ReadBuf.Attach(psaReadBuf);
PrintPacket(ReadBuf);
}
As in the pervious example, the first byte is reserved for length and increments our index as
commands are inserted into the packet.
First, an MLAN Bus Master Reset is performed. This allows ceases compunction with any other
MLAN devices that were previously addressed, and uses the new one. The CMD_ML_SEARCH
and DATA_ID commands tell the controller to find the next device and obtain its ID, respectively.
If multiple CMD_ML_SEARCH and DATA_ID pairs were sent, it would be possible to determine
how many devices were on this channel. CMD_ML_SEARCH returns 0x01 when no more devices
are found.
The get_urn() function, above, is equivalent to the
ReadURN
method
of the Digitizer driver. It is
included for clarity and as one of the simpler examples of MLAN programming.
Here is an example output from the get_urn() function using the example code:
sent packet without errors
Packet length: 7
06 84 80 81 00 00 85
got a packet without errors on receive
Packet length: 17
10 84 00 80 00 81 00 00 08 14 29 70 D3 01 00 00 60
The “14” in the response denotes the “family code” of the device, in this case, indicating that it is a
DS2430. The “14” is the first byte of the unique serial number, and the “08” before it is the length
of that serial number. The DS2431’s family code is “2D”.
DS2430
C
OMMANDS
WRITE_SCRATCHPAD_2430
The function used in writing data to an MLAN device is the WRITE_SCRATCHPAD function. It
is important that the 1-wire device be selected using the GET_URN function prior to using the
remaining functions. The CMD_ML_ACCESS command to the MLAN repeater uses the address
(URN) of the last selected device for all subsequent operations.
int
write_scratchpad_2430(IVTEXDigitizerPtr digitizer,
const
char
* data)
{
int
recLen = 0;
CComSafeArray<
short
> WriteBuf;
WriteBuf.Create();