www.vtiinstruments.com
EX1629 Onboard Memory
327
The last command tells the controller to read back the result of the previous command. This is
invaluable, as it allows error codes to be viewed, if errors are returned. The last steps are to send
the completed packet and retrieve the response.
Here is how the output for a WRITE_SCRATCHPAD for the DS2430 looks when using the
example code:
sent packet without errors
Packet length: 40
27 82 0A 23 22 0F 00 AA 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10
11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1F 20 21 85
got a packet without errors on receive
Packet length: 39
26 82 00 0A 22 0F 00 AA 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10
11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1F 20 21
As can be seen, WRITE_SCRATCHPAD echoes the data written to it as well, which is why space
was allocated for it.
READ_SCRATCHPAD_2430
The READ_SCRATCHPAD command is nearly identical between the DS2430 and DS2431, but
some differences exist. The DS2430 will be covered first.
int read_scratchpad_2430(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[+] = 2+DS2430_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);
return recLen;
}
The first three commands are the same as the WRITE_SCRATCHPAD command. The device
must still be accessed and the controller must be put into data access mode. The block length, this
time, is only 3, because the expected buffer size, the READ_SCRATCHPAD command, and the
address to read from (always “0” for this example, but if less than the scratchpad length is read,
this could be incremented and read multiple times) is all that must be sent.
The expected data length is
2+SCRATCHPAD_LEN
. See WRITE_SCRATCHPAD_2430 for why
this length is used.
Содержание EX1629
Страница 310: ...VTI Instruments Corp 310 EX1629 Command Set...
Страница 342: ...VTI Instruments Corp 342 EX1629 Onboard Memory...