OneWire
 

Library

#include <ONEWIRE.bas> 

 
O

     

     
    Interface
     
    SUB OWIN (pin, OUTcnt, BYREF OUTlist as string, INcnt, BYREF INlist as string)
     
    FUNCTION OWOUT (pin, OUTcnt, BYREF OUTlist as string)

    Description
     
    OWIN begins with a RESET/Presence sequence on the designated pin.

    Then OUTcnt bytes from OUTlist will be transferred to the device to select the command. OUTcnt may be -1 and OUTlist empty. If OUTcnt is 0, then OUTlist bytes will be sent until a value of 0 is found (the 0 will not be sent).  An empty OUTlist can be represented by "".

    Following that the INcnt bytes will be read back from the device and saved in INlist .

    If INcnt is 0, then the string will be filled with bytes until a 0, CR or LF character is received.  Note that no bounds checking is performed on the input, and if a 0, CR, or LF is never received then this routine will hang.    As there is no bounds checking its possible to overwrite other variables, if less than 256 bytes have been allocated for the InputList string.

    OWOUT begins with a RESET/Presence sequence on the designated Pin.

    If a one-wire device responds OWOUT will return 1, else 0.

    Following that the OUTcnt bytes from OUTlist will be sent to the device. OUTlist can be a constant string.

    The bit order for the 1-Wire device is assumed to be LSB (bit 0) first. The REV function can be used to change the bit order. 

    Example

    #include <ONEWIRE.bas>
     '...

    DIM message(20) as string
    DIM response(20) as string


    message = chr(&Hcc)+chr(&Hf)+chr(6)+chr(&Haa)+chr(&H55)

                     ' write to the scratch pad of a DS2430
    present = owout (7,5,message)
    print present

    message = chr(&Hcc)+chr(&Hf)+chr(6)
     
    print present
    owin (7, 3, message, 2, response)
    print hex(response(0)),hex(response(1))