//---------------------------------------------------------------------- // Family 0x10 Demo // void main(void) { int temp; int sign; BYTE i; //---------------------------------------- ADCON1 = 0x07; // PortB digital bTRD6 = 1; // RD6 = Serial Input bTRD7 = 0; // RD7 = Serial Output bLD7 = 1; printf("\nFamily 0x10 Demo\n%"); //////////////////////////////////////////////////////////// // Initialise the OneWire network (bus) // attempt to acquire the 1-Wire Nets if (!owAcquire(0, NULL)) { printf("Acquire failed.\n%"); while(1) ; } //////////////////////////////////////////////////////////// // Let's set the alarmtemps of all devices on the bus. // To demonstrate this, we write a low alarmtemp of 19 // and a high alarmtemp of 21 to all devices. // Finally we copy the alarmtemps to non-volatile EEPROM. printf("\nStart - Set AlarmTemperatures.\n%"); // Reset the devices owTouchReset(0); // Address all devices on the net owWriteByte(0, OW_SKIPROM); // Use the WriteScratchpad command to set AlarmTemps owWriteByte(0, OW_WRITESCRATCHPAD); owWriteByte(0, 19); // Valid RoomTemperature owWriteByte(0, 21); // 19 <= Temp < 21 printf("End - Set AlarmTemperatures.\n%"); // Set alarmtemps done // Copy the temps to EEPROM printf("\nStart - Write AlarmTemperatures to EEPROM.\n%"); // Reset the devices owTouchReset(0); // Address all devices on the net owWriteByte(0, OW_SKIPROM); // send the CopyScratchpad command to copy the AlarmTemps to EEPROM // If the bus supports Strong PullUp, we use it (because // there might be parasite powered devices on this bus). if(owHasPowerDelivery(0)) { printf("The bus has a Strong PullUp\n%"); owWriteBytePower(0, OW_COPYSCRATCHPAD); // Eeprom update takes 10 milliseconds max. 11ms is safer Wait(11); // turn off the strong pull-up owLevel(0, MODE_NORMAL); } else { printf("The bus has NO Strong PullUp\n%"); owWriteByte(0, OW_COPYSCRATCHPAD); // Eeprom update takes 10 milliseconds max. 11ms is safer Wait(11); } printf("End - Write AlarmTemperatures to EEPROM.\n%"); // Copy the temps to EEPROM done while(1) { //////////////////////////////////////////////////////////// // We do a temp conversion on all DS18S20's printf("\nStart - TemperatureConversions\n%"); // Reset the devices owTouchReset(0); // Address all devices on this net owWriteByte(0, OW_SKIPROM); // Send the convert command and start power delivery if available. // Note that we use a different way here to determine // Strong PullUp capability. if(owWriteBytePower(0, OW_CONVERTT)) { printf("We are using a Strong PullUp.\n%"); } else { printf("No Strong PullUp configured.\n%"); owWriteByte(0, OW_CONVERTT); } // Coversion takes 750 milliseconds max. 751ms is safer Wait(751); // turn off the 1-Wire Net strong pull-up owLevel(0, MODE_NORMAL); printf("End - TemperatureConversions\n%"); //////////////////////////////////////////////////////////// // We will now demonstrate an alarmsearch printf("\nStart - Find devices in alarmstate\n%"); // Find the devices with temp < 19 or temp >= 21 if(!owFirst(0, TRUE, TRUE)) { printf("No devices in AlarmState found.\n%"); } else { do { printf("Device in AlarmState found: 0x%02X%02X%02X%02X%02X%02X%02X%02X\n%", owNetCurrent.SerialNum[7], owNetCurrent.SerialNum[6], owNetCurrent.SerialNum[5], owNetCurrent.SerialNum[4], owNetCurrent.SerialNum[3], owNetCurrent.SerialNum[2], owNetCurrent.SerialNum[1], owNetCurrent.SerialNum[0]); } while(owNext(0, TRUE, TRUE)); } printf("End - Find devices in alarmstate\n%"); //////////////////////////////////////////////////////////// // We will now demonstrate a normal search. For // every device found, it's temperature is retrieved. printf("\nStart - Find devices and get their temperatures.\n%"); if(!owFirst(0, TRUE, FALSE)) { printf("No devices found.\n%"); } else { do { printf("Device found: 0x%02X%02X%02X%02X%02X%02X%02X%02X%", owNetCurrent.SerialNum[7], owNetCurrent.SerialNum[6], owNetCurrent.SerialNum[5], owNetCurrent.SerialNum[4], owNetCurrent.SerialNum[3], owNetCurrent.SerialNum[2], owNetCurrent.SerialNum[1], owNetCurrent.SerialNum[0]); // Init the crc setcrc8(0, 0); // Read the device's memory owWriteByte(0, OW_READSCRATCHPAD); for(i = 0; i < SCRATCHPAD_SIZE; i++) { ScratchPad[i] = owReadByte(0); docrc8(0, ScratchPad[i]); } // Check the CRC if(owNetCurrent.utilcrc8 != 0) { printf(", crc is NOT OK.\n%"); } else { // We don't want to use float's temp = ((int)ScratchPad[SCRATCHPAD_TEMPERATUREMSB] << 8) | (int)ScratchPad[SCRATCHPAD_TEMPERATURELSB]; if(temp < 0) { temp = -temp; sign = '-'; } else if(temp == 0) { sign = ' '; } else { sign = '+'; } printf(", Temperature is %c%d.%d degrees\n%", sign, (temp >> 1), (temp & 0x01) ? 5 : 0); } } while(owNext(0, TRUE, FALSE)); } printf("End - Find devices and get their temperatures.\n%"); //////////////////////////////////////////////////////////// Wait(1); // Just a convenient way to set a breakpoint } }
//-------------------------------------------------------------------------- // This is the begining of the program that tests the different Channels int main() //short argc, char **argv) { char return_msg[128]; //returned message from 1-wire operations int i,j,k,n; //loop counters short test=0; //info byte data short clear=0; //used to clear the button SwitchProps sw; //used to set Channel A and B uchar SwitchSN[MAXDEVICES][8]; //the serial numbers for the devices int num; //for the number of devices present int ch; //inputed character from user char out[140]; //used for output of the info byte data int portnum=0; //---------------------------------------- // Introduction header printf("\n/---------------------------------------------\n"); printf(" swtest - V2.00\n" " The following is a test to excersize the\n" " different channels on the DS2406.\n"); printf(" Press any CTRL-C to stop this program.\n\n"); // check for required port name if (argc != 2) { printf("1-Wire Net name required on command line!\n" " (example: \"COM1\" (Win32 DS2480),\"/dev/cua0\" " "(Linux DS2480),\"1\" (Win32 TMEX)\n"); exit(1); } // attempt to acquire the 1-Wire Net if (!owAcquire(portnum, argv[1], return_msg)) { printf("%s",return_msg); exit(1); } // success printf("%s",return_msg); // this is to get the number of the devices and the serial numbers num = FindDevices(portnum, &SwitchSN[0], SWITCH_FAMILY, MAXDEVICES); // setting up the first print out for the frist device owSerialNum(portnum, SwitchSN[0], FALSE); j=1; n=0; do { // This is for after the different combinations of channels // have been tested to reset to a different device to be tested. if( ((test & 0x40) && (j==5)) || ((!(test & 0x40)) && (j==3)) ) { printf("\n\n"); for(k=0; k < num; k++) { printf("%d ", k+1); for(i=7; i>=0; i--) { printf("%02X", SwitchSN[k][i]); } printf("\n"); } printf("%d To quit or any other key.\n", k+1); printf("\n"); printf("Pick a device\n"); ch = getkeystroke(); n = 0; n = (10*n + (ch - '0')) - 1; if( (n>num-1) || (n<0) ) { n = 0; //used to finish off the loop break; } owSerialNum(portnum, SwitchSN[n], FALSE); j = 1; } printf("\n"); test = ReadSwitch12(portnum,clear); // This looks at the info byte to determine if it is a // two or one channel device. if(test & 0x40) { switch(j) { case 1: sw.Chan_A = 0; sw.Chan_B = 0; break; case 2: sw.Chan_A = 0; sw.Chan_B = 1; break; case 3: sw.Chan_A = 1; sw.Chan_B = 0; break; case 4: sw.Chan_A = 1; sw.Chan_B = 1; break; default: sw.Chan_A = 1; sw.Chan_B = 1; j=0; break; } } else { switch(j) { case 1: sw.Chan_B = 0; sw.Chan_A = 0; break; case 2: sw.Chan_B = 0; sw.Chan_A = 1; break; default: sw.Chan_B = 0; sw.Chan_A = 1; j = 0; break; } } if(!SetSwitch12(portnum, SwitchSN[n], &sw)) { msDelay(50); if(SetSwitch12(portnum, SwitchSN[n], &sw)) msDelay(50); else printf("Switch not set\n"); } test = ReadSwitch12(portnum,clear); printf("\n"); for(i=7; i>=0; i--) { printf("%02X", SwitchSN[n][i]); } printf("\n"); SwitchStateToString12(test, out); printf("%s", out); j++; } while(1); // release the 1-Wire Net owRelease(portnum,return_msg); printf("%s",return_msg); exit(0); return 0; }
//---------------------------------------------------------------------- // Main Test // int main() //short argc, char **argv) { int PortNum=1,rslt,i,j,testcnt=0,length; uchar TempSerialNum[8]; uchar tran_buffer[2000], filename[10]; char return_msg[128]; int portnum=0; // check for required port name if (argc != 2) { printf("1-Wire Net name required on command line!\n" " (example: \"COM1\" (Win32 DS2480),\"/dev/cua0\" " "(Linux DS2480),\"1\" (Win32 TMEX)\n"); exit(1); } // attempt to acquire the 1-Wire Net if (!owAcquire(portnum, argv[1], return_msg)) { printf("%s",return_msg); exit(1); } // success printf("%s",return_msg); //---------------------------------------- // Introduction printf("\n/---------------------------------------------\n"); printf(" The following is a test excersize of the\n" " 1-Wire Net public domain library Version 2.00.\n\n" " This test was run using with 2 DS1920's (DS1820),\n" " 1 DS1971 (DS2430), and 1 DS1996.\n\n"); //---------------------------------------- // First the devices on the 1-Wire Net printf("\n/---------------------------------------------\n"); printf("TEST%d: Searching for devices on 1-Wire Net\n",testcnt++); // find the first device (all devices not just alarming) rslt = owFirst(portnum,TRUE, FALSE); while (rslt) { // print the Serial Number of the device just found PrintSerialNum(portnum); // find the next device rslt = owNext(portnum,TRUE, FALSE); } //---------------------------------------- // now search for the part with a 0x0C family code (DS1996) printf("\n/---------------------------------------------\n"); printf("TEST%d: Set to find first device with 0x0C family code\n",testcnt++); owFamilySearchSetup(portnum,0x0C); // find the first 0x0c device TempSerialNum[0]=0; while (TempSerialNum[0]!=0x0c && owNext(portnum,TRUE,FALSE)) { owSerialNum(portnum,TempSerialNum,TRUE); } printf("search result %d\n",TempSerialNum[0]==0x0c); // print the Serial Number of the device just found PrintSerialNum(portnum); //---------------------------------------- // Access a device and read ram printf("\n/---------------------------------------------\n"); printf("TEST%d: Access the current device and read ram\n",testcnt++); printf("owAccess %d\n",owAccess(portnum)); printf("Read Ram 0xF0: %02X\n",owTouchByte(portnum,0xF0)); printf("Address0 0x00: %02X\n",owTouchByte(portnum,0x00)); printf("Address1 0x00: %02X\n",owTouchByte(portnum,0x00)); printf("Page 0: "); for (i = 0; i < 32; i++) printf("%02X ",owTouchByte(portnum,0xFF)); printf("\n"); //---------------------------------------- // Read ram with owBlock printf("\n/---------------------------------------------\n"); printf("TEST%d: Read ram with owBlock\n",testcnt++); for (i = 0; i < 32; i++) tran_buffer[i] = 0xFF; printf("owBlock %d\n",owBlock(portnum,FALSE,tran_buffer,32)); printf("Page 1: "); for (i = 0; i < 32; i++) printf("%02X ",tran_buffer[i]); printf("\n"); //---------------------------------------- // Write a packet in each page of DS1996 printf("\n/---------------------------------------------\n"); printf("TEST%d: Place the DS1996 into overdrive\n",testcnt++); printf("owOverdriveAccess %d\n",owOverdriveAccess(portnum)); //---------------------------------------- // Write 4 packets with owWritePacketStd printf("\n/---------------------------------------------\n"); printf("TEST%d: Write 4 packets with owWritePacketStd\n",testcnt++); for (j = 0; j < 4; j++) { for (i = 0; i < 29; i++) tran_buffer[i] = (uchar)i + j; printf("Write page %d: %d\n",j,owWritePacketStd(portnum,j,tran_buffer,29,FALSE,FALSE)); for (i = 0; i < 29; i++) tran_buffer[i] = 0; length = owReadPacketStd(portnum,TRUE,j,tran_buffer); printf("Read page %d: %d\n",j,length); for (i = 0; i < length; i++) printf("%02X",tran_buffer[i]); printf("\n"); } //---------------------------------------- // Write a file to DS1996 printf("\n/---------------------------------------------\n"); printf("TEST%d: Format and write a file (in overdrive)\n",testcnt++); sprintf(filename,"DEMO"); // set the data to write for (i = 0; i < 2000; i++) tran_buffer[i] = i % 255; printf("Format and write file DEMO.000 %d\n", owFormatWriteFile(portnum,filename,2000,tran_buffer)); // clear the buffer for (i = 0; i < 2000; i++) tran_buffer[i] = 0x55; printf("Read file DEMO.000 %d\n",owReadFile(portnum,filename,tran_buffer)); // print the data result for (i = 0; i < 2000; i++) { if ((i % 0x20) == 0) printf("\n%03X ",i); printf("%02X",tran_buffer[i]); } printf("\n"); //---------------------------------------- // Turn off overdrive printf("\n/---------------------------------------------\n"); printf("TEST%d: Turn off overdrive\n",testcnt++); printf("Set 1-Wire Net speed to normal %d\n",owSpeed(portnum,MODE_NORMAL)); //---------------------------------------- // Verify a device printf("\n/---------------------------------------------\n"); printf("TEST%d: Verify the current device\n",testcnt++); printf("owVerify (normal) %d\n",owVerify(portnum,FALSE)); printf("owVerify (alarm) %d\n",owVerify(portnum,TRUE)); //---------------------------------------- // Skip the first family code found printf("\n/---------------------------------------------\n"); printf("TEST%d: Skip the first family code found\n",testcnt++); // find the next device printf("search result of owFirst %d\n",owFirst(portnum,TRUE, FALSE)); // print the Serial Number of the device just found PrintSerialNum(portnum); // skip the first family type found owSkipFamily(portnum); printf("owSkipFamily called\n"); // find the next device printf("search result of owNext %d\n",owNext(portnum,TRUE, FALSE)); // print the Serial Number of the device just found PrintSerialNum(portnum); //---------------------------------------- // Find first family code (DS1920) and read temperature printf("\n/---------------------------------------------\n"); printf("TEST%d: Find first family code (DS1920) and read temperature\n",testcnt++); // find the next device printf("search result of owFirst %d\n",owFirst(portnum,TRUE, FALSE)); // print the Serial Number of the device just found PrintSerialNum(portnum); // send the convert temperature command printf("Convert temperature command %02X\n",owTouchByte(portnum,0x44)); // set the 1-Wire Net to strong pull-up printf("Set power delivery %d\n",owLevel(portnum,MODE_STRONG5)); // sleep for 1 second msDelay(1000); // turn off the 1-Wire Net strong pull-up printf("Disable power delivery %d\n",owLevel(portnum,MODE_NORMAL)); // read the DS1920 temperature value printf("Access the DS1920 %d\n",owAccess(portnum)); tran_buffer[0] = 0xBE; tran_buffer[1] = 0xFF; tran_buffer[2] = 0xFF; printf("Block to read temperature %d\n",owBlock(portnum,FALSE,tran_buffer,3)); // interpret the result printf("result: DS1920 temperature read: %d C\n", (tran_buffer[1] | ((int)tran_buffer[2] << 8)) / 2); //---------------------------------------- // Verify the current device, could also be alarming printf("\n/---------------------------------------------\n"); printf("TEST%d: Verify the current device, could also be alarming\n",testcnt++); printf("owVerify (normal) %d\n",owVerify(portnum,FALSE)); printf("owVerify (alarm) %d\n",owVerify(portnum,TRUE)); //---------------------------------------- // Test setting the Serial Number with owSerialNum printf("\n/---------------------------------------------\n"); printf("TEST%d: Test setting the Serial Number with owSerialNum\n",testcnt++); // set the Serial Num to 0 to 7 for (i = 0; i < 8; i++) TempSerialNum[i] = (uchar)i; owSerialNum(portnum,TempSerialNum,FALSE); // read back the Serial Number PrintSerialNum(portnum); //---------------------------------------- // Verify the current device (should fail, no such device) printf("\n/---------------------------------------------\n"); printf("TEST%d: Verify the current device (should fail, no such device)\n",testcnt++); printf("owVerify (normal) %d\n",owVerify(portnum,FALSE)); printf("owVerify (alarm) %d\n",owVerify(portnum,TRUE)); // release the 1-Wire Net owRelease(portnum,return_msg); printf("%s",return_msg); exit(0); return 0; }
//---------------------------------------------------------------------- // Main Test for DS1920/DS1820 temperature measurement // int main() //short argc, char **argv) { float current_temp; char return_msg[128]; int i = 0; int j = 0; int NumDevices=0; int portnum = 0; //---------------------------------------- // Introduction header printf("\n/---------------------------------------------\n"); printf(" Temperature application DS1920/DS1820 - Version 1.00 \n" " The following is a test to excersize a DS1920/DS1820.\n" " Temperature Find and Read from a: \n" " DS1920/DS1820 (at least 1)\n\n"); printf(" Press any CTRL-C to stop this program.\n\n"); printf(" Output [Serial Number(s) ........ Temp1(C)] \n\n"); // check for required port name if (argc != 2) { printf("1-Wire Net name required on command line!\n" " (example: \"COM1\" (Win32 DS2480),\"/dev/cua0\" " "(Linux DS2480),\"1\" (Win32 TMEX)\n"); exit(1); } // attempt to acquire the 1-Wire Net if (!owAcquire(portnum, argv[1], return_msg)) { printf("%s",return_msg); exit(1); } // success printf("%s",return_msg); // Find the device(s) NumDevices = FindDevices(portnum, &FamilySN[0], 0x10, MAXDEVICES); if (NumDevices>0) { printf("\n"); printf("Device(s) Found: \n"); for (i = 0; i < NumDevices; i++) { PrintSerialNum(FamilySN[i]); printf("\n"); } printf("\n\n"); // (stops on CTRL-C) do { // read the temperature and print serial number and temperature for (i = 0; i < NumDevices; i++) { if (ReadTemperature(portnum, FamilySN[i],¤t_temp)) { PrintSerialNum(FamilySN[i]); printf(" %5.2f \n", current_temp); } else printf(" Error reading temperature, verify device present:%d\n", owVerify(portnum, FALSE)); } printf("\n"); } while (!key_abort()); } else printf("\n\n\nERROR, device DS1920/DS1820 not found!\n"); // release the 1-Wire Net owRelease(portnum, return_msg); printf("%s",return_msg); exit(0); return 0; }
//---------------------------------------------------------------------- // Main for tstfind // void main(void) { uchar rslt; int cnt; //use port for 1-wire uchar portnum = ONEWIRE_P; //initialize I/O port #if STDOUT_P==0 serial0_init(BAUD9600_TIMER_RELOAD_VALUE); #else serial1_init(BAUD9600_TIMER_RELOAD_VALUE); #endif printf("Beginning tstfindm\r\n"); // attempt to acquire the 1-Wire Net if (!owAcquire(portnum,NULL)) { printf("owAcquire failed\r\n"); while(owHasErrors()) printf(" - Error %d\r\n", owGetErrorNum()); return; } //---------------------------------------- // Introduction printf("\r\n/----------------\r\n"); printf(" All iButtons.\r\n\r\n"); do { printf("-- Start\r\n"); cnt = 0; // find the first device (all devices not just alarming) rslt = owFirst(portnum, TRUE, FALSE); while (rslt) { // print the device number cnt++; printf("(%d) ",cnt); // get and print the Serial Number of the device just found DisplaySerialNum(portnum); // find the next device rslt = owNext(portnum, TRUE, FALSE); } printf("-- End\r\n\r\nPress any key to continue searching\r\n"); rslt = getchar(); //printf("key pressed: %c\r\n",rslt); } while (rslt!='q'); // release the 1-Wire Net owRelease(portnum); return; }
//---------------------------------------------------------------------- // Main AlarmSearch Test // void main(void) { BYTE portnum; //---------------------------------------- ADCON1 = 0x07; // PortB digital bTRD6 = 1; // RD6 = Serial Input bTRD7 = 0; // RD7 = Serial Output bLD7 = 1; printf("\nEnumeration (AlarmSearch) test\n%"); // Initialise the OneWire nets and the temperature devices for(portnum = 0; portnum < MAX_PORTNUM; portnum++) { // attempt to acquire the 1-Wire Nets if (!owAcquire(portnum,NULL)) { printf("Acquire failed for OneWire net %d.\n%", portnum); } else { // Reset the devices owTouchReset(portnum); // Address all devices on this net owWriteByte(portnum, OW_SKIPROM); // send the WriteScratchpad command to set AlarmTemps owWriteByte(portnum, OW_WRITESCRATCHPAD); owWriteByte(portnum, 19); // Valid RoomTemperature owWriteByte(portnum, 21); // 19 <= Temp < 21 } } while(1) { // Do a temp conversion on all DS18S20's on all nets simultanously for(portnum = 0; portnum < MAX_PORTNUM; portnum++) { // Reset the devices owTouchReset(portnum); // Address all devices on this net owWriteByte(portnum, OW_SKIPROM); // send the convert command and start power delivery if(!owWriteBytePower(portnum, OW_CONVERTT)) { printf("\nNo Strong PullUp on net %d. Trying without SPU.\n%", portnum); owWriteByte(portnum, OW_CONVERTT); } } // Conversion takes 750 milliseconds max. Safer is 751ms Wait(751); // turn off the 1-Wire Net strong pull-up for(portnum = 0; portnum < MAX_PORTNUM; portnum++) { owLevel(portnum, MODE_NORMAL); } for(portnum = 0; portnum < MAX_PORTNUM; portnum++) { // Find the device(s) in AlarmState printf("\nEnumeration for net %d.\n%", portnum); if(!owFirst(portnum, TRUE, TRUE)) { printf("No devices in AlarmState found on this net.\n%"); } else { do { printf("Device in AlarmState found: 0x%02X%02X%02X%02X%02X%02X%02X%02X\n%", owNetCurrent.SerialNum[7], owNetCurrent.SerialNum[6], owNetCurrent.SerialNum[5], owNetCurrent.SerialNum[4], owNetCurrent.SerialNum[3], owNetCurrent.SerialNum[2], owNetCurrent.SerialNum[1], owNetCurrent.SerialNum[0]); } while(owNext(portnum, TRUE, TRUE)); } } Wait(10); // Just a convenient way to set a breakpoint } }
//---------------------------------------------------------------------- // This is the Main routine for thermodl. // int main() //short argc, char **argv) { int Fahrenheit=FALSE,filenum,num,i,j; char return_msg[128]; FILE *fp; ThermoStateType ThermoState; uchar ThermoSN[MAXDEVICES][8]; //the serial numbers for the devices int portnum=0; // check arguments to see if request instruction with '?' or too many if ((argc < 2) || (argc > 4) || ((argc > 1) && (argv[1][0] == '?' || argv[1][1] == '?'))) ExitProg("\nusage: thermodl 1wire_net_name <output_filename> </Fahrenheit>\n" " - Thermochron download on the 1-Wire Net port\n" " - 1wire_net_port required port name\n" " example: \"COM1\" (Win32 DS2480),\"/dev/cua0\" \n" " (Linux DS2480),\"1\" (Win32 TMEX)\n" " - <output_filename> optional output filename\n" " - </Fahrenheit> optional Fahrenheit mode (default Celsius)\n" " - version 2.00\n",1); // attempt to acquire the 1-Wire Net if (!owAcquire(portnum,argv[1],return_msg)) ExitProg(return_msg,1); // success printf("%s",return_msg); //---------------------------------------- // Introduction printf("\n/----------------------------------------------\n"); printf(" Find and download DS1921 Thermochron iButton(s)\n" " Version 2.00\n\n"); // check arguments for temperature conversion and filename Fahrenheit = FALSE; filenum = 0; if (argc >= 3) { if (argv[2][0] != '/') filenum = 2; else if ((argv[2][1] == 'F') || (argv[2][1] == 'f')) Fahrenheit = TRUE; if (argc == 4) { if (argv[3][0] != '/') filenum = 3; else if ((argv[3][1] == 'F') || (argv[3][1] == 'f')) Fahrenheit = TRUE; } } // open the output file fp = NULL; if (filenum > 0) { fp = fopen(argv[filenum],"w+"); if(fp == NULL) { printf("ERROR, Could not open output file!\n"); exit(1); } else printf("File '%s' opened to write mission results.\n", argv[filenum]); } // get list of Thermochron's num = FindDevices(portnum, &ThermoSN[0],THERMO_FAM, MAXDEVICES); // check if not present or more then 1 present if (num == 0) ExitProg("Thermochron not present on 1-Wire\n",1); // loop to download each Thermochron for (i = 0; i < num; i++) { // set the serial number portion in the thermo state printf("\nDownloading: "); for (j = 7; j >= 0; j--) { ThermoState.MissStat.serial_num[j] = ThermoSN[i][j]; printf("%02X",ThermoSN[i][j]); } printf("\n"); // download the Thermochron found if (DownloadThermo(portnum,&ThermoSN[i][0],&ThermoState,stdout)) { // interpret the results of the download InterpretStatus(&ThermoState.MissStat); InterpretAlarms(&ThermoState.AlarmData, &ThermoState.MissStat); InterpretHistogram(&ThermoState.HistData); InterpretLog(&ThermoState.LogData, &ThermoState.MissStat); // print the output PrintResults(&ThermoState,fp,Fahrenheit); } else { fprintf(fp,"\nError downloading device: "); for (j = 0; j < 8; j++) fprintf(fp,"%02X",ThermoSN[i][j]); fprintf(fp,"\n"); } } // close opened file if (fp != NULL) { printf("File '%s' closed.\n", argv[filenum]); fclose(fp); } // release the 1-Wire Net //owRelease(portnum,return_msg); printf("\n%s",return_msg); ExitProg("End program normally\n",0); return 0; }