owiButtonWriteData (Function)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Device support:

All devices with 1-Wire

Firmware version:

1.50 / 1.00.00


owiButtonWriteData will write a block of data to a memory iButton for later to be read by owiButtonReadData.

 

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

 

When a write 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 writing, an "iButton not present" (-2) will be returned.

 

Input:

index : INT(1..Max)

Location number the data should be stored in.

 

data : ADR

Address of the memory block that holds the data to be stored.

 

size : INT(0..Max)

Maximum number of bytes to store from "ptr".

 

Returns: INT

0


Data written successful.

-1


General read error.

-2


iButton not present.

-3


Illegal index value.

-4


Illegal data size value.

 

Declaration:

FUNCTION owiButtonWriteData : 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;
     
    str := strFormat(format := "ID: " + id);
    // Copy contents of a string to memory
    strToMemory(dst := ADDR(data), str := str, len := strLen(str := str));
     
    rc := owiButtonWriteData(index := 1, data := ADDR(data), size := SIZEOF(data));
    IF rc <> 0 THEN
        // Write a string to the debug window
        DebugFmt(message := "Write to iButton failed error code \1", v1 := rc);
    ELSE
        DebugMsg(message := "Data written to index 1 on " + id);
        DebugMsg(message := "Content : " + str);
    END_IF;
  END_IF;
END;
 
END_PROGRAM;