1WSEARCHNEXT

Top  Previous  Next

Action

This statement reads the next ID from the 1wire bus into a variable array.

 

 

Syntax

var2 = 1WSEARCHNEXT( )

 

 

Remarks

var2

A variable or array that should be at least 8 bytes long that will be assigned with the 8 byte ID from the next 1wire device on the bus.

 

The 1wireSearchFirst() function must be called once to initiate the ID retrieval process. After the 1wireSearchFirst() function is used you should use successive function calls to the 1wireSearchNext function to retrieve other ID's on the bus.

 

A string can not be assigned to get the values from the bus. This because a null may be returned as a value and the null is also used as a string terminator.

I would advice to use a byte array as shown in the example.

 

The ERR variable is set when there are no more devices found.

 

See also

1WIRE , 1WSEARCHFIRST, 1WIRECOUNT

 

 

Example

'---------------------------------------------------------------------------

'                       1wirecount.bas

'                   (c) 1995-2006 MCS Electronics

' demonstration of using multiple devices

'--------------------------------------------------------------------------

'chip we use

$regfile = "89s8252.dat"

'crystal attached

$crystal = 12000000

 

'baud rate

$baud = 4800

 

'wait for 500 mili secs

Waitms 500

 

'the pins we use

'connect a 4K7 resistor from the data pin to VCC

Config 1wire = P1.0

 

'we need an array of 8 bytes to hold the result

Dim Ar(8) As Byte

'we also need a counter variable and a word variable

Dim I As Byte , W As Word

 

'some ids of 1wire chips I tested

' 01 51 B5 8D 01 00 00 56

' 01 84 B3 8D 01 00 00 E5

 

Print "start"

'get the number of connected 1wire device

W = 1wirecount(ar(1))

'print if there was an error and how many sensors are available

Print "ERR " ; Err ; " count " ; W

 

'now get the data from the first 1wire device on the bus

 

Ar(1) = 1wsearchfirst()

'print the ID

For I = 1 To 8

Printhex Ar(i);

Next

Print

 

'I assume that there are more than 1 1wire devices

Do

'get the next device

Ar(1) = 1wsearchnext()

For I = 1 To 8

  Printhex Ar(i);

Next

Print

Loop Until Err = 1

'when ERR is 1 it means there are no more devices

' IMPORTANT : 1wsearchfirst and next functions do require that you use the SAME array

'In this example this is ar(1)

 

'once you know the ID, you can address a specific device

End