owiButtonReadData (Function)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Device support:

All devices with 1-Wire

Firmware version:

1.50 / 1.00.00


owiButtonReadData will read a block of data from a memory iButton previously written by the owiButtonWriteData function.

 

Before a read can be done, an owiButtonGetID must be completed.

 

When a read request is executed, the index and data size is verified against the following possible values:

1-Wire family

Type (Dallas/Maxim)

Memory

Max index

Max data size

08

DS1992

1024 bits

4

29 Bytes

06

DS1993

4096 bits

16

29 Bytes

 

If the iButton found by owiButtonGetID is not present at the time of reading, an "iButton not present" (-2) will be returned.

 

On a successful read operation, the number of bytes actually read from the iButton will be returned, which may be less than the requested size.

 

A "no data" (-5) will be returned if there is no data or the data found was not previously written by owiButtonWriteData function.

 

Note: partial data may be read in case of an unsuccessful read operation.

 

Input:

index : INT(1..Max)

Location number the data should be loaded from.

 

data : ADR

Address of the memory block that receives the loaded data.

 

size : INT(0..Max)

Maximum number of bytes to load into "ptr".

 

Returns: INT

>=0


Number of bytes read.

-1


General read error.

-2


iButton not present.

-3


Illegal index value.

-4


Illegal data size value.

-5


No data.

 

Declaration:

FUNCTION owiButtonReadData : INT;
VAR_INPUT
  index   : INT;
  data     : PTR;
  size     : INT;
END_VAR;

 

Example:

INCLUDE rtcu.inc
 
PROGRAM example;
VAR
  id   : STRING;
data  : ARRAY[1..29] OF SINT;
  rc    : INT;
  str   : STRING;
  i     : INT;
END_VAR;
BEGIN
  // Retrieve ID of I-Button
  id := owiButtonGetID();
 
  // iButton detected.
  IF strLen(str := id) <> 0 THEN
    // clear data area
    FOR i := 1 TO SIZEOF(data) DO
        data[i] := 0;
    END_FOR;
 
     rc := owiButtonReadData(index := 1, data := ADDR(data), size := SIZEOF(data));
    IF rc < 0 THEN
        // Write a string to the debug window
        DebugFmt(message := "Failed to read iButton error code \1", v1 := rc);
    ELSE
        DebugFmt(message := "Read \1 bytes from index 1 on " + id + ".", v1 := rc);
        // Copy contents from memory into a string
        str := strFromMemory(src := ADDR(data), len := SIZEOF(data));
        DebugMsg(message := "Content : " + str);
    END_IF;
  END_IF;
END;
 
END_PROGRAM;