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 // swtloop.C - Goes through the testing of the DS2406(DS2407) switch
37 // Constant definition
42 char *argv[]={__FILE__, "exow"};
43 #define getkeystroke getchar
45 //--------------------------------------------------------------------------
46 // This is the begining of the program that tests the different Channels
47 int main() //short argc, char **argv)
49 char return_msg[128]; //returned message from 1-wire operations
50 int i,j,k,n; //loop counters
51 short test=0; //info byte data
52 short clear=0; //used to clear the button
53 SwitchProps sw; //used to set Channel A and B
54 uchar SwitchSN[MAXDEVICES][8]; //the serial numbers for the devices
55 int num; //for the number of devices present
56 int ch; //inputed character from user
57 char out[140]; //used for output of the info byte data
60 //----------------------------------------
61 // Introduction header
62 printf("\n/---------------------------------------------\n");
63 printf(" swtest - V2.00\n"
64 " The following is a test to excersize the\n"
65 " different channels on the DS2406.\n");
66 printf(" Press any CTRL-C to stop this program.\n\n");
68 // check for required port name
71 printf("1-Wire Net name required on command line!\n"
72 " (example: \"COM1\" (Win32 DS2480),\"/dev/cua0\" "
73 "(Linux DS2480),\"1\" (Win32 TMEX)\n");
77 // attempt to acquire the 1-Wire Net
78 if (!owAcquire(portnum, argv[1], return_msg))
80 printf("%s",return_msg);
85 printf("%s",return_msg);
87 // this is to get the number of the devices and the serial numbers
88 num = FindDevices(portnum, &SwitchSN[0], SWITCH_FAMILY, MAXDEVICES);
90 // setting up the first print out for the frist device
91 owSerialNum(portnum, SwitchSN[0], FALSE);
97 // This is for after the different combinations of channels
98 // have been tested to reset to a different device to be tested.
99 if( ((test & 0x40) && (j==5)) ||
100 ((!(test & 0x40)) && (j==3)) )
103 for(k=0; k < num; k++)
108 printf("%02X", SwitchSN[k][i]);
112 printf("%d To quit or any other key.\n", k+1);
115 printf("Pick a device\n");
119 n = (10*n + (ch - '0')) - 1;
121 if( (n>num-1) || (n<0) )
123 n = 0; //used to finish off the loop
127 owSerialNum(portnum, SwitchSN[n], FALSE);
132 test = ReadSwitch12(portnum,clear);
134 // This looks at the info byte to determine if it is a
135 // two or one channel device.
184 if(!SetSwitch12(portnum, SwitchSN[n], &sw))
187 if(SetSwitch12(portnum, SwitchSN[n], &sw))
190 printf("Switch not set\n");
193 test = ReadSwitch12(portnum,clear);
199 printf("%02X", SwitchSN[n][i]);
203 SwitchStateToString12(test, out);
211 // release the 1-Wire Net
212 owRelease(portnum,return_msg);
213 printf("%s",return_msg);