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 // tstow.C - Test application to test 1-Wire Net functions. No EPROM writes.
31 // History: 1.00 -> 1.01 Change to use msDelay instead of Sleep.
33 // 1.01 -> 1.02 Changed to generic OpenCOM/CloseCOM for easier
34 // use with other platforms.
35 // 1.02 -> 1.03 Removed caps in #includes for Linux capatibility
36 // Changed to use Acquire/Release 1-Wire Net functions
37 // 1.03 -> 2.00 Reorganization of Public Domain Kit
45 void PrintSerialNum(int portnum);
49 char *argv[]={__FILE__, "exow"};
51 //----------------------------------------------------------------------
54 int main() //short argc, char **argv)
56 int PortNum=1,rslt,i,j,testcnt=0,length;
57 uchar TempSerialNum[8];
58 uchar tran_buffer[2000], filename[10];
62 // check for required port name
65 printf("1-Wire Net name required on command line!\n"
66 " (example: \"COM1\" (Win32 DS2480),\"/dev/cua0\" "
67 "(Linux DS2480),\"1\" (Win32 TMEX)\n");
71 // attempt to acquire the 1-Wire Net
72 if (!owAcquire(portnum, argv[1], return_msg))
74 printf("%s",return_msg);
79 printf("%s",return_msg);
81 //----------------------------------------
83 printf("\n/---------------------------------------------\n");
84 printf(" The following is a test excersize of the\n"
85 " 1-Wire Net public domain library Version 2.00.\n\n"
86 " This test was run using with 2 DS1920's (DS1820),\n"
87 " 1 DS1971 (DS2430), and 1 DS1996.\n\n");
89 //----------------------------------------
90 // First the devices on the 1-Wire Net
91 printf("\n/---------------------------------------------\n");
92 printf("TEST%d: Searching for devices on 1-Wire Net\n",testcnt++);
94 // find the first device (all devices not just alarming)
95 rslt = owFirst(portnum,TRUE, FALSE);
98 // print the Serial Number of the device just found
99 PrintSerialNum(portnum);
101 // find the next device
102 rslt = owNext(portnum,TRUE, FALSE);
105 //----------------------------------------
106 // now search for the part with a 0x0C family code (DS1996)
107 printf("\n/---------------------------------------------\n");
108 printf("TEST%d: Set to find first device with 0x0C family code\n",testcnt++);
110 owFamilySearchSetup(portnum,0x0C);
112 // find the first 0x0c device
114 while (TempSerialNum[0]!=0x0c && owNext(portnum,TRUE,FALSE)) {
115 owSerialNum(portnum,TempSerialNum,TRUE);
117 printf("search result %d\n",TempSerialNum[0]==0x0c);
119 // print the Serial Number of the device just found
120 PrintSerialNum(portnum);
122 //----------------------------------------
123 // Access a device and read ram
124 printf("\n/---------------------------------------------\n");
125 printf("TEST%d: Access the current device and read ram\n",testcnt++);
127 printf("owAccess %d\n",owAccess(portnum));
129 printf("Read Ram 0xF0: %02X\n",owTouchByte(portnum,0xF0));
130 printf("Address0 0x00: %02X\n",owTouchByte(portnum,0x00));
131 printf("Address1 0x00: %02X\n",owTouchByte(portnum,0x00));
134 for (i = 0; i < 32; i++)
135 printf("%02X ",owTouchByte(portnum,0xFF));
138 //----------------------------------------
139 // Read ram with owBlock
140 printf("\n/---------------------------------------------\n");
141 printf("TEST%d: Read ram with owBlock\n",testcnt++);
142 for (i = 0; i < 32; i++)
143 tran_buffer[i] = 0xFF;
145 printf("owBlock %d\n",owBlock(portnum,FALSE,tran_buffer,32));
147 for (i = 0; i < 32; i++)
148 printf("%02X ",tran_buffer[i]);
151 //----------------------------------------
152 // Write a packet in each page of DS1996
153 printf("\n/---------------------------------------------\n");
154 printf("TEST%d: Place the DS1996 into overdrive\n",testcnt++);
155 printf("owOverdriveAccess %d\n",owOverdriveAccess(portnum));
157 //----------------------------------------
158 // Write 4 packets with owWritePacketStd
159 printf("\n/---------------------------------------------\n");
160 printf("TEST%d: Write 4 packets with owWritePacketStd\n",testcnt++);
162 for (j = 0; j < 4; j++)
164 for (i = 0; i < 29; i++)
165 tran_buffer[i] = (uchar)i + j;
167 printf("Write page %d: %d\n",j,owWritePacketStd(portnum,j,tran_buffer,29,FALSE,FALSE));
169 for (i = 0; i < 29; i++)
172 length = owReadPacketStd(portnum,TRUE,j,tran_buffer);
174 printf("Read page %d: %d\n",j,length);
176 for (i = 0; i < length; i++)
177 printf("%02X",tran_buffer[i]);
181 //----------------------------------------
182 // Write a file to DS1996
183 printf("\n/---------------------------------------------\n");
184 printf("TEST%d: Format and write a file (in overdrive)\n",testcnt++);
185 sprintf(filename,"DEMO");
186 // set the data to write
187 for (i = 0; i < 2000; i++)
188 tran_buffer[i] = i % 255;
189 printf("Format and write file DEMO.000 %d\n",
190 owFormatWriteFile(portnum,filename,2000,tran_buffer));
193 for (i = 0; i < 2000; i++)
194 tran_buffer[i] = 0x55;
196 printf("Read file DEMO.000 %d\n",owReadFile(portnum,filename,tran_buffer));
197 // print the data result
198 for (i = 0; i < 2000; i++)
202 printf("%02X",tran_buffer[i]);
206 //----------------------------------------
207 // Turn off overdrive
208 printf("\n/---------------------------------------------\n");
209 _asm ;johan 7 _endasm;
210 printf("TEST%d: Turn off overdrive\n",testcnt++);
211 printf("Set 1-Wire Net speed to normal %d\n",owSpeed(portnum,MODE_NORMAL));
213 //----------------------------------------
215 printf("\n/---------------------------------------------\n");
216 _asm ;johan 8 _endasm;
217 printf("TEST%d: Verify the current device\n",testcnt++);
219 printf("owVerify (normal) %d\n",owVerify(portnum,FALSE));
220 printf("owVerify (alarm) %d\n",owVerify(portnum,TRUE));
222 //----------------------------------------
223 // Skip the first family code found
224 printf("\n/---------------------------------------------\n");
225 _asm ;johan 9 _endasm;
226 printf("TEST%d: Skip the first family code found\n",testcnt++);
228 // find the next device
229 printf("search result of owFirst %d\n",owFirst(portnum,TRUE, FALSE));
231 // print the Serial Number of the device just found
232 PrintSerialNum(portnum);
234 // skip the first family type found
235 owSkipFamily(portnum);
236 printf("owSkipFamily called\n");
238 // find the next device
239 printf("search result of owNext %d\n",owNext(portnum,TRUE, FALSE));
241 // print the Serial Number of the device just found
242 PrintSerialNum(portnum);
244 //----------------------------------------
245 // Find first family code (DS1920) and read temperature
246 printf("\n/---------------------------------------------\n");
247 _asm ;johan 10 _endasm;
248 printf("TEST%d: Find first family code (DS1920) and read temperature\n",testcnt++);
250 // find the next device
251 printf("search result of owFirst %d\n",owFirst(portnum,TRUE, FALSE));
253 // print the Serial Number of the device just found
254 PrintSerialNum(portnum);
256 // send the convert temperature command
257 printf("Convert temperature command %02X\n",owTouchByte(portnum,0x44));
259 // set the 1-Wire Net to strong pull-up
260 printf("Set power delivery %d\n",owLevel(portnum,MODE_STRONG5));
262 // sleep for 1 second
265 // turn off the 1-Wire Net strong pull-up
266 printf("Disable power delivery %d\n",owLevel(portnum,MODE_NORMAL));
268 // read the DS1920 temperature value
269 printf("Access the DS1920 %d\n",owAccess(portnum));
270 tran_buffer[0] = 0xBE;
271 tran_buffer[1] = 0xFF;
272 tran_buffer[2] = 0xFF;
273 printf("Block to read temperature %d\n",owBlock(portnum,FALSE,tran_buffer,3));
274 // interpret the result
275 printf("result: DS1920 temperature read: %d C\n", (tran_buffer[1] |
276 ((int)tran_buffer[2] << 8)) / 2);
278 //----------------------------------------
279 // Verify the current device, could also be alarming
280 printf("\n/---------------------------------------------\n");
281 _asm ;johan 11 _endasm;
282 printf("TEST%d: Verify the current device, could also be alarming\n",testcnt++);
284 printf("owVerify (normal) %d\n",owVerify(portnum,FALSE));
285 printf("owVerify (alarm) %d\n",owVerify(portnum,TRUE));
287 //----------------------------------------
288 // Test setting the Serial Number with owSerialNum
289 printf("\n/---------------------------------------------\n");
290 _asm ;johan 12 _endasm;
291 printf("TEST%d: Test setting the Serial Number with owSerialNum\n",testcnt++);
293 // set the Serial Num to 0 to 7
294 for (i = 0; i < 8; i++)
295 TempSerialNum[i] = (uchar)i;
296 owSerialNum(portnum,TempSerialNum,FALSE);
298 // read back the Serial Number
299 PrintSerialNum(portnum);
301 //----------------------------------------
302 // Verify the current device (should fail, no such device)
303 printf("\n/---------------------------------------------\n");
304 _asm ;johan 13 _endasm;
305 printf("TEST%d: Verify the current device (should fail, no such device)\n",testcnt++);
307 printf("owVerify (normal) %d\n",owVerify(portnum,FALSE));
308 printf("owVerify (alarm) %d\n",owVerify(portnum,TRUE));
310 // release the 1-Wire Net
311 owRelease(portnum,return_msg);
312 printf("%s",return_msg);
318 //----------------------------------------------------------------------
319 // Read and print the Serial Number.
321 void PrintSerialNum(int portnum)
323 uchar TempSerialNumber[8];
326 owSerialNum(portnum,TempSerialNumber,TRUE);
327 for (i = 7; i >= 0; i--)
328 printf("%02X",TempSerialNumber[i]);