www.vtiinstruments.com
EX1629 Onboard Memory
337
int sendLen, recLen = 0;
int i = 0;
char byte[3];
if(strlen(data) != ((DS2431_SCRATCHPAD_LEN * 2 ) +
(DS2431_SCRATCHPAD_LEN-1)))
{
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
}
//The copy command:
// 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[+] = 5; // block length
SendPkt[+] = 4; // data length
// send the copy scratchpad command
SendPkt[+] = COPY_SCRATCHPAD;
// send the validation key
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;
SendPkt[+] = 0x07;
// delay for 128ms
SendPkt[+] = CMD_DELAY;
SendPkt[+] = 1;
SendPkt[+] = DELAY_128 | DELAY_MS;
Содержание EX1629
Страница 310: ...VTI Instruments Corp 310 EX1629 Command Set...
Страница 342: ...VTI Instruments Corp 342 EX1629 Onboard Memory...