VTI Instruments Corp.
APPENDIX C
98
if
(strlen(data) != ((DS2430_SCRATCHPAD_LEN * 2) +
(DS2430_SCRATCHPAD_LEN-1)))
{
//(SCRATCHPAD_LEN*2)+(SCRATCHPAD_LEN-1) = 95
printf(
"Data was not the right length (wanted 95, got
%i)\n"
, (
int
)strlen(data));
return
-1;
}
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+DS2430_SCRATCHPAD_LEN);
// block length
WriteBuf.Add(2+DS2430_SCRATCHPAD_LEN);
// data length
// send the write scratchpad command
WriteBuf.Add(WRITE_SCRATCHPAD);
// send the address byte
WriteBuf.Add((
short
)0);
// the bytes of data to write
char
byte[3];
for
(
int
i = 0; i < ((2*DS2430_SCRATCHPAD_LEN) +
(DS2430_SCRATCHPAD_LEN-1)); i+=3)
{
strncpy_s(byte, 3, &data[i], 2);
byte[2]=
'\0'
;
WriteBuf.Add((
unsigned
char
)strtoul(byte, NULL, 16));
//convert to hex
}
// request the result buffer as the last command
WriteBuf.Add(CMD_GETBUF);
// set the length
WriteBuf[0] = (
short
)WriteBuf.GetCount() - 1;
// send the commands
digitizer->Channels->Item[name]->TEDS-
>WriteTEDS(WriteBuf.GetSafeArrayPtr());
std::cout <<
"DS2430 Write Scratchpad (WriteData)"
<<
std::endl;
PrintPacket(WriteBuf);
// retrieve the response
CComSafeArray<
short
> ReadBuf;
SAFEARRAY* psaReadBuf;
digitizer->Channels->Item[name]->TEDS->ReadTEDS(&psaReadBuf);
std::cout <<
"DS2430 Write Scratchpad (ReadData)"
<<
std::endl;
ReadBuf.Attach(psaReadBuf);
PrintPacket(ReadBuf);
recLen = (
int
)ReadBuf.GetCount();
return
recLen;
}