1 //---------------------------------------------------------------------------
2 // Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
4 // Permission is hereby granted, free of charge, to any person obtaining a
5 // copy of this software and associated documentation files (the "Software"),
6 // to deal in the Software without restriction, including without limitation
7 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 // and/or sell copies of the Software, and to permit persons to whom the
9 // Software is furnished to do so, subject to the following conditions:
11 // The above copyright notice and this permission notice shall be included
12 // in all copies or substantial portions of the Software.
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 // IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
18 // OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 // OTHER DEALINGS IN THE SOFTWARE.
22 // Except as contained in this notice, the name of Dallas Semiconductor
23 // shall not be used except as stated in the Dallas Semiconductor
25 //---------------------------------------------------------------------------
27 // counter.c - Application to read the 1-Wire Net DS2423 - counter.
29 // This application uses the files from the 'Public Domain'
30 // 1-Wire Net libraries ('general' and 'userial').
44 void PrintSerialNum(uchar *SerialNum);
46 // local serial numbers
47 static uchar FamilySN[MAXDEVICES][8];
51 char *argv[]={__FILE__, "exow"};
53 //----------------------------------------------------------------------
54 // Main Test for the DS2423 - counter
56 int main() //short argc, char **argv)
65 //------------------------------------------------------
66 // Introduction header
67 printf("\n/---------------------------------------------\n");
68 printf(" Counter Application - V2.00\n"
69 " The following is a test to excersize a\n"
70 " DS2423 - counter \n\n");
72 printf(" Press any CTRL-C to stop this program.\n\n");
73 printf(" Output [Serial Number(s) ... Counter Value ... Counter Value ... "
74 "Counter Value ... Counter Value] \n\n");
76 // check for required port name
79 printf("1-Wire Net name required on command line!\n"
80 " (example: \"COM1\" (Win32 DS2480),\"/dev/cua0\" "
81 "(Linux DS2480),\"1\" (Win32 TMEX)\n");
85 // attempt to acquire the 1-Wire Net
86 if (!owAcquire(portnum, argv[1], return_msg))
88 printf("%s",return_msg);
93 printf("%s",return_msg);
96 NumDevices = FindDevices(portnum, &FamilySN[0], 0x1D, MAXDEVICES);
100 printf("Device(s) Found: \n");
101 for (i = 0; i < NumDevices; i++)
103 PrintSerialNum(FamilySN[i]);
111 // read the current counters
112 for (i = 0; i < NumDevices; i++)
115 PrintSerialNum(FamilySN[i]);
117 for (CounterPage = 12; CounterPage <= 15; CounterPage++)
119 if (ReadCounter(portnum, FamilySN[i], CounterPage, &Count))
121 printf(" %10ld ", Count);
124 printf("\nError reading counter, verify device present:%d\n",
125 owVerify(portnum,FALSE));
130 while (!key_abort());
133 printf("\n\n\n ERROR, device not found!\n");
135 // release the 1-Wire Net
136 owRelease(portnum,return_msg);
137 printf("%s",return_msg);
143 // -------------------------------------------------------------------------------
144 // Read and print the serial number
146 void PrintSerialNum(uchar *SerialNum)
150 for (i = 7; i>=0; i--)
151 printf("%02X", SerialNum[i]);