VTI Instruments Corp.
332
EX1629 Onboard Memory
{
printf("Data was not the right length (wanted 23, got %i)\n",
strlen(data));
return -1;
}
sendLen = 1; // reserve first byte for length
// access the current device with address in DATA_ID
SendPkt[+] = CMD_ML_ACCESS;
// construct a block of communication to MicroLAN
SendPkt[+] = CMD_ML_DATA;
SendPkt[+] = 4+DS2431_SCRATCHPAD_LEN; // block length
SendPkt[+] = 5+DS2431_SCRATCHPAD_LEN; // data length
// send the write scratchpad command
SendPkt[+] = WRITE_SCRATCHPAD;
// send the address byte
if (address > (DS2431_MEMORY_LEN-DS2431_SCRATCHPAD_LEN) || address
< 0)
{
printf("Invalid scratchpad address, must be between 0 and 88
hex\n");
return -1;
}
SendPkt[+] = address;
SendPkt[+] = 0;
// the 5 bytes of data to write
for (i = 0; i < ((2*DS2431_SCRATCHPAD_LEN) +
(DS2431_SCRATCHPAD_LEN-1)); i+=3)
{
strncpy(byte, &data[i],2);
byte[2]='\0';
SendPkt[+] = (uint8_t)strtoul(byte, NULL, 16); //convert
to hex
}
// request the result buffer as the last command
SendPkt[+] = CMD_GETBUF;
// set the length
SendPkt[0] = sendLen - 1;
// send and receive the frame
MLanHostPacketSend(SendPkt, channel);
CRCcalc(SendPkt, 6, 11);
recLen = MLanHostPacketReceive(RecPkt, channel, MLAN_PACKET_SIZE);
return recLen;
}
Notice first that, in comparison to the DS2430 scratchpad write, the length of the data string that is
checked is much smaller, although it uses the same formula,. This is because the DS2431 has only
an 8-byte scratchpad, whereas the DS2430 has 32 bytes. The same format of data string is used to
submit data, however. Here is an example of a data string for the DS2431:
"01 02 03 04 05 06 07 08"
Even on a different device, however, the basic format remains unchanged. The first byte received
is for length and the next two are CMD_ML_ACCESS and CMD_ML_DATA, just like in the
DS2430’s command.
The block size is our first indicator that the DS2430 and DS2431, although similar, have slightly
different programming requirements. This block size is one byte larger than the DS2430’s block
size, and the reason is readily apparent three commands down: there are two address registers
instead of one. The first address register, T1, is the beginning offset, and T2 is the address. As can
be seen in the example, T1 is used to offset the data within the main memory, allowing users to
Содержание EX1629
Страница 310: ...VTI Instruments Corp 310 EX1629 Command Set...
Страница 342: ...VTI Instruments Corp 342 EX1629 Onboard Memory...