User | Revision | Line number | New contents of line |
svlach |
0:70c3bea805ee
|
1
|
//---------------------------------------------------------------------------
|
svlach |
0:70c3bea805ee
|
2
|
// Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
|
svlach |
0:70c3bea805ee
|
3
|
//
|
svlach |
0:70c3bea805ee
|
4
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
svlach |
0:70c3bea805ee
|
5
|
// copy of this software and associated documentation files (the "Software"),
|
svlach |
0:70c3bea805ee
|
6
|
// to deal in the Software without restriction, including without limitation
|
svlach |
0:70c3bea805ee
|
7
|
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
svlach |
0:70c3bea805ee
|
8
|
// and/or sell copies of the Software, and to permit persons to whom the
|
svlach |
0:70c3bea805ee
|
9
|
// Software is furnished to do so, subject to the following conditions:
|
svlach |
0:70c3bea805ee
|
10
|
//
|
svlach |
0:70c3bea805ee
|
11
|
// The above copyright notice and this permission notice shall be included
|
svlach |
0:70c3bea805ee
|
12
|
// in all copies or substantial portions of the Software.
|
svlach |
0:70c3bea805ee
|
13
|
//
|
svlach |
0:70c3bea805ee
|
14
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
svlach |
0:70c3bea805ee
|
15
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
svlach |
0:70c3bea805ee
|
16
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
svlach |
0:70c3bea805ee
|
17
|
// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
|
svlach |
0:70c3bea805ee
|
18
|
// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
svlach |
0:70c3bea805ee
|
19
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
svlach |
0:70c3bea805ee
|
20
|
// OTHER DEALINGS IN THE SOFTWARE.
|
svlach |
0:70c3bea805ee
|
21
|
//
|
svlach |
0:70c3bea805ee
|
22
|
// Except as contained in this notice, the name of Dallas Semiconductor
|
svlach |
0:70c3bea805ee
|
23
|
// shall not be used except as stated in the Dallas Semiconductor
|
svlach |
0:70c3bea805ee
|
24
|
// Branding Policy.
|
svlach |
0:70c3bea805ee
|
25
|
//---------------------------------------------------------------------------
|
svlach |
0:70c3bea805ee
|
26
|
//
|
svlach |
0:70c3bea805ee
|
27
|
// findtype.c - Test module to find all devices of one type.
|
svlach |
0:70c3bea805ee
|
28
|
//
|
svlach |
0:70c3bea805ee
|
29
|
// Version: 2.00
|
svlach |
0:70c3bea805ee
|
30
|
//
|
svlach |
0:70c3bea805ee
|
31
|
//----------------------------------------------------------------------
|
svlach |
0:70c3bea805ee
|
32
|
//
|
svlach |
0:70c3bea805ee
|
33
|
//
|
svlach |
0:70c3bea805ee
|
34
|
#include "./Headers/ownet.h"
|
svlach |
0:70c3bea805ee
|
35
|
#include "./Headers/findtype.h"
|
svlach |
0:70c3bea805ee
|
36
|
|
svlach |
0:70c3bea805ee
|
37
|
//----------------------------------------------------------------------
|
svlach |
0:70c3bea805ee
|
38
|
// Search for devices
|
svlach |
0:70c3bea805ee
|
39
|
//
|
svlach |
0:70c3bea805ee
|
40
|
// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
|
svlach |
0:70c3bea805ee
|
41
|
// indicate the symbolic port number.
|
svlach |
0:70c3bea805ee
|
42
|
// 'FamilySN' - an array of all the serial numbers with the matching
|
svlach |
0:70c3bea805ee
|
43
|
// family code
|
svlach |
0:70c3bea805ee
|
44
|
// 'family_code' - the family code of the devices to search for on the
|
svlach |
0:70c3bea805ee
|
45
|
// 1-Wire Net
|
svlach |
0:70c3bea805ee
|
46
|
// 'MAXDEVICES' - the maximum number of devices to look for with the
|
svlach |
0:70c3bea805ee
|
47
|
// family code passed.
|
svlach |
0:70c3bea805ee
|
48
|
//
|
svlach |
0:70c3bea805ee
|
49
|
// Returns: TRUE(1) success, device type found
|
svlach |
0:70c3bea805ee
|
50
|
// FALSE(0) device not found
|
svlach |
0:70c3bea805ee
|
51
|
//
|
svlach |
0:70c3bea805ee
|
52
|
SMALLINT FindDevices(int portnum, uchar FamilySN[][8], SMALLINT family_code, int MAXDEVICES)
|
svlach |
0:70c3bea805ee
|
53
|
{
|
svlach |
0:70c3bea805ee
|
54
|
int NumDevices=0;
|
svlach |
0:70c3bea805ee
|
55
|
|
svlach |
0:70c3bea805ee
|
56
|
// find the devices
|
svlach |
0:70c3bea805ee
|
57
|
// set the search to first find that family code
|
svlach |
0:70c3bea805ee
|
58
|
owFamilySearchSetup(portnum,family_code);
|
svlach |
0:70c3bea805ee
|
59
|
|
svlach |
0:70c3bea805ee
|
60
|
// loop to find all of the devices up to MAXDEVICES
|
svlach |
0:70c3bea805ee
|
61
|
NumDevices = 0;
|
svlach |
0:70c3bea805ee
|
62
|
do
|
svlach |
0:70c3bea805ee
|
63
|
{
|
svlach |
0:70c3bea805ee
|
64
|
// perform the search
|
svlach |
0:70c3bea805ee
|
65
|
if (!owNext(portnum,TRUE, FALSE))
|
svlach |
0:70c3bea805ee
|
66
|
break;
|
svlach |
0:70c3bea805ee
|
67
|
|
svlach |
0:70c3bea805ee
|
68
|
owSerialNum(portnum,FamilySN[NumDevices], TRUE);
|
svlach |
0:70c3bea805ee
|
69
|
if ((FamilySN[NumDevices][0] & 0x7F) == (family_code & 0x7F))
|
svlach |
0:70c3bea805ee
|
70
|
{
|
svlach |
0:70c3bea805ee
|
71
|
NumDevices++;
|
svlach |
0:70c3bea805ee
|
72
|
}
|
svlach |
0:70c3bea805ee
|
73
|
}
|
svlach |
0:70c3bea805ee
|
74
|
while (NumDevices < (MAXDEVICES - 1));
|
svlach |
0:70c3bea805ee
|
75
|
|
svlach |
0:70c3bea805ee
|
76
|
// check if not at least 1 device
|
svlach |
0:70c3bea805ee
|
77
|
return NumDevices;
|
svlach |
0:70c3bea805ee
|
78
|
}
|