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 // swtoper.C - Menu-driven test of DS2406(DS2407) 1-Wire switch
38 // Constant definition
43 char *argv[]={__FILE__, "exow"};
44 #define getkeystroke getchar
46 //---------------------------------------------------------------------------
47 // The main program that performs the operations on switches
49 int main() //short argc, char **argv)
51 char return_msg[128]; //returned message from 1-wire operations
52 short test; //info byte data
53 short clear=0; //used to clear the button
54 short done; //to tell when the user is done
55 SwitchProps sw; //used to set Channel A and B
56 uchar SwitchSN[MAXDEVICES][8]; //the serial number for the devices
57 int num; //for the number of devices present
58 int ch; //inputed character from user
59 int i,j,n; //loop counters and indexes
60 char out[140]; //used for output of the info byte data
61 int count; //the number of characters in the info byte data
64 //----------------------------------------
65 // Introduction header
66 printf("\n/---------------------------------------------\n");
67 printf(" Switch - V2.00\n"
68 " The following is a test to excersize the \n"
69 " setting of the state in a DS2406.\n");
71 printf(" Press any CTRL-C to stop this program.\n\n");
73 // check for required port name
76 printf("1-Wire Net name required on command line!\n"
77 " (example: \"COM1\" (Win32 DS2480),\"/dev/cua0\" "
78 "(Linux DS2480),\"1\" (Win32 TMEX)\n");
82 // attempt to acquire the 1-Wire Net
83 if (!owAcquire(portnum, argv[1], return_msg))
85 printf("%s",return_msg);
90 printf("%s",return_msg);
92 // this is to get the number of the devices and the serial numbers
93 num = FindDevices(portnum, &SwitchSN[0], SWITCH_FAMILY, MAXDEVICES);
95 // setting up the first print out for the frist device
96 owSerialNum(portnum, SwitchSN[0], FALSE);
100 if(owAccess(portnum))
102 // loop while not done
105 test = ReadSwitch12(portnum, clear);
108 printf("%02X", SwitchSN[n][i]);
112 count = SwitchStateToString12(test, out);
116 printf("\n\n(1) Display the switch Info\n"
117 "(2) Clear activity Latches\n"
118 "(3) Set Flip Flop(s) on switch\n"
119 "(4) Select different device\n"
125 // do something from the menu selection
129 case '1': // Display the switch Info
132 case '2': // Clear activity Latches
136 case '3': // Set Flip Flop(s) on switch
137 printf("Channel %c Flip Flop (1 set, 0 clear):",'A');
147 printf("Channel %c Flip Flop (1 set, 0 clear):",'B');
162 if(!SetSwitch12(portnum, SwitchSN[n], &sw))
165 if(SetSwitch12(portnum, SwitchSN[n], &sw))
168 printf("Switch not set\n");
172 case '4': // Switch Devices
173 for(j=0; j < num; j++)
178 printf("%02X", SwitchSN[j][i]);
186 printf("Pick a device\n");
189 n = (10*n + (ch - '0')) - 1;
192 while((!isalnum(ch)) || (n>num-1));
196 n = (10*n + (ch - '0')) - 1;
198 owSerialNum(portnum, SwitchSN[n], FALSE);
203 case '5': case 'q': case 'Q': // Done
213 owRelease(portnum,return_msg);
214 printf("%s",return_msg);