www.vtiinstruments.com
EX1629 Onboard Memory
325
First, an MLAN Bus Master Reset is performed. This allows ceases compunction with any other
MLAN devices that were previously addressed, and uses the new one. The CMD_ML_SEARCH
and DATA_ID commands tell the controller to find the next device and obtain its ID, respectively.
If multiple CMD_ML_SEARCH and DATA_ID pairs were sent, it would be possible to determine
how many devices were on this channel. CMD_ML_SEARCH returns 0x01 when no more
devices are found.
The GET_URN() function, above, is equivalent to the vtex1629_read_teds_URN() function of the
instrument driver. It is included for clarity and as one of the simpler examples of MLAN
programming.
NOTE
The EX1629 supports only one device per channel in 0.4.x and previous firmware revisions.
Here is an example output from the GET_URN function using the example code:
sent packet without errors
Packet length: 7
06 84 80 81 00 00 85
got a packet without errors on receive
Packet length: 17
10 84 00 80 00 81 00 00 08 14 29 70 D3 01 00 00 60
The “14” in the response denotes the “family code” of the device, in this case, indicating that it is
a DS2430. The “14” is the first byte of the unique serial number, and the “08” before it is the
length of that serial number. The DS2431’s family code is “2D”.
DS2430
C
OMMANDS
WRITE_SCRATCHPAD_2430
The function used in writing data to an MLAN device is the WRITE_SCRATCHPAD function. It
is important that the 1-Wire device be selected using the GET_URN function prior to using the
remaining functions. The CMD_ML_ACCESS command to the MLAN repeater uses the address
(URN) of the last selected device for all subsequent operations.
int write_scratchpad_2430(const char* data, int channel)
{
int sendLen, recLen = 0;
int i = 0;
char byte[2];
if(strlen(data) != ((DS2430_SCRATCHPAD_LEN * 2 ) +
(DS2430_SCRATCHPAD_LEN-1)))
{
printf("Data was not the right length (wanted 95, got %i)\n",
strlen(data)); //(SCRATCHPAD_LEN*2)+(SCRATCHPAD_LEN-1) = 95
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[+] = 3+DS2430_SCRATCHPAD_LEN; // block length
SendPkt[+] = 2+DS2430_SCRATCHPAD_LEN; // data length
// send the write scratchpad command
SendPkt[+] = WRITE_SCRATCHPAD;
// send the address byte
SendPkt[+] = 0;
// the bytes of data to write