www.vtiinstruments.com
EX1629 Onboard Memory
333
write to any address between the bytes 0
h
an 136e. From the 136
th
byte, users can write all the way
to the end of the memory.
The data length is also different. We add several bytes to the DS2430’s command length, and two
of these are the CRC16 value that the DS2431 device returns to us. The CRC uses the entire
command, from WRITE_SCRATCHPAD all the way to the end of the data buffer, to generate its
CRC. Notice, too, that a CRC is run on the packet, passing in the offset of the
WRITE_SCRATCHPAD command in the packet and the length of the command plus the data.
This function is explained in the
NOTE
If the CRC returned is not the same as the calculated CRC given by this program, the data write
was corrupted in transmission. Re-access the device and try the write again.
The same code is used as with the DS2430 to turn the data string into hexadecimal and to tell the
controller to send the response back with the CMD_GETBUF command.
The example output for the WRITE_SCRATCHPAD command for the DS2431 is very similar to
the WRITE_SCRATCHPAD for the DS2430, with the exception that the data is shorter:
sent packet without errors
Packet length: 17
10 82 0A 0C 0D 0F 00 00 AA 02 03 04 05 06 07 08 85
CRC16: 74E4
got a packet without errors on receive
Packet length: 18
11 82 00 0A 0D 0F 00 00 AA 02 03 04 05 06 07 08 74 E4
This indicates that this write was successful, as the last two bytes returned are the same as the
calculated CRC.
READ_SCRATCHPAD_2431
int read_scratchpad_2431(int channel)
{
int sendLen, recLen = 0;
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[+] = 3; // block length
SendPkt[+] = 6+DS2431_SCRATCHPAD_LEN; // data length of
read
// send the read scratchpad command
SendPkt[+] = READ_SCRATCHPAD;
// send the address byte
SendPkt[+] = 0;
// 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);
recLen = MLanHostPacketReceive(RecPkt, channel, MLAN_PACKET_SIZE);
CRCcalc(RecPkt, 6, 12);
return recLen;
}
Содержание EX1629
Страница 310: ...VTI Instruments Corp 310 EX1629 Command Set...
Страница 342: ...VTI Instruments Corp 342 EX1629 Onboard Memory...