// From the dev kit titled uWin32VC300 //--------------------------------------------------------------------------- // Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved. // // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included // in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. // IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES // OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // OTHER DEALINGS IN THE SOFTWARE. // // Except as contained in this notice, the name of Dallas Semiconductor // shall not be used except as stated in the Dallas Semiconductor // Branding Policy. //--------------------------------------------------------------------------- // // temp.c - Application to find and read the 1-Wire Net // DS1920/DS1820/DS18S20 - temperature measurement. // // This application uses the files from the 'Public Domain' // 1-Wire Net libraries ('general' and 'userial'). // // // Version: 2.00 // #include #include #include #include #include "ownet.h" #include "temp10.h" #include "findtype.h" // defines #define MAXDEVICES 20 // global serial numbers uchar FamilySN[MAXDEVICES][8]; int portnum = 0; // variables int family_code; //---------------------------------------------------------------------- // Main Test for DS1920/DS1820 temperature measurement // int output2mrtg (float temp1, float temp2 , char *label); int listdevices(); int main(int argc, char **argv) { float current_temp; int i = 0; int NumDevices=0; float ctemp1; float ctemp2; char chartempserial1[100]; uchar uchar_rev_tempserial1[100]; uchar uchar_rev_tempserial2[100]; uchar uchartempserial1[100]; uchar uchartempserial2[100]; char mrtglabel[100]; int listoffset; if (argc != 3) { printf("\n/2006-08-22(23.00.25)--------------------\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("1-Wire Net name required on command line!\n" " (example: \"COM1\" (Win32 DS2480),\"/dev/cua0\" " "(Linux DS2480),\"1\" (Win32 TMEX)\n"); printf("\n rsH_1wiretemp.exe port listoffset \n"); printf("\n rsH_1wiretemp.exe \"com1\" 0 \n"); portnum = owAcquireEx(argv[1]); listdevices(); exit(1); } // listoffset = atoi(argv[2]); // if( listoffset < 0 || listoffset > 10) // { // printf("\n problem with offsetvalue, out of range (1-10):%d\n",listoffset); // exit(1); // } // sprintf(mrtglabel,"TEMP%d",listoffset); // attempt to acquire the 1-Wire Net if((portnum = owAcquireEx(argv[1])) < 0) { output2mrtg (-10, -10 , mrtglabel); OWERROR_DUMP(stdout); exit(1); } // remember convert hex string to serial number format strcpy( chartempserial1,"7B0008010FCDC910,6A0008010FCEFF10,mrtgcoolabel,"); strcpy( chartempserial1,argv[2]); //printf ("\n serial number %s \n",chartempserial1); i= sscanf( chartempserial1, "%2X%2X%2X%2X%2X%2X%2X%2X,%2X%2X%2X%2X%2X%2X%2X%2X,%s,", &uchar_rev_tempserial1[0],&uchar_rev_tempserial1[1],&uchar_rev_tempserial1[2], &uchar_rev_tempserial1[3],&uchar_rev_tempserial1[4],&uchar_rev_tempserial1[5], &uchar_rev_tempserial1[6],&uchar_rev_tempserial1[7], &uchar_rev_tempserial2[0],&uchar_rev_tempserial2[1],&uchar_rev_tempserial2[2], &uchar_rev_tempserial2[3],&uchar_rev_tempserial2[4],&uchar_rev_tempserial2[5], &uchar_rev_tempserial2[6],&uchar_rev_tempserial2[7],&mrtglabel); if (i != 17) { printf("%d items processed, bad serial number strings sent to program",i); exit(1); } uchartempserial1[7]= uchar_rev_tempserial1[0]; uchartempserial1[6]= uchar_rev_tempserial1[1]; uchartempserial1[5]= uchar_rev_tempserial1[2]; uchartempserial1[4]= uchar_rev_tempserial1[3]; uchartempserial1[3]= uchar_rev_tempserial1[4]; uchartempserial1[2]= uchar_rev_tempserial1[5]; uchartempserial1[1]= uchar_rev_tempserial1[6]; uchartempserial1[0]= uchar_rev_tempserial1[7]; uchartempserial2[7]= uchar_rev_tempserial2[0]; uchartempserial2[6]= uchar_rev_tempserial2[1]; uchartempserial2[5]= uchar_rev_tempserial2[2]; uchartempserial2[4]= uchar_rev_tempserial2[3]; uchartempserial2[3]= uchar_rev_tempserial2[4]; uchartempserial2[2]= uchar_rev_tempserial2[5]; uchartempserial2[1]= uchar_rev_tempserial2[6]; uchartempserial2[0]= uchar_rev_tempserial2[7]; // printf ("\n sscanf %d, serial number %s \n",i,chartempserial1); //PrintSerialNum(uchartempserial0); //exit (0); ReadTemperature(portnum,uchartempserial1,¤t_temp); ctemp1=current_temp; ReadTemperature(portnum,uchartempserial2,¤t_temp); ctemp2=current_temp; output2mrtg (ctemp1, ctemp2 , mrtglabel); exit (0); // below is old method of searching all devices, should never get here... // 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)) { // ctemp=current_temp * 9 / 5 + 32; //tempconvert= floor(ctemp+0.5); // do a sanity check // if (ctemp<=190&&ctemp>=1) { // PrintSerialNum(FamilySN[i]); // printf ("%d",i); if (i==listoffset*2) { ctemp1=current_temp;} if (i==(listoffset*2)+1) { ctemp2=current_temp; sprintf(mrtglabel,"TEMP%d",listoffset); output2mrtg (ctemp1, ctemp2 , mrtglabel); exit(0); //return 0; } // } // converting temperature from Celsius to Fahrenheit } else printf(" Error reading temperature, verify device present:%d\n", (int)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); //printf("Closing port %s.\n", argv[1]); //printf ("%s\n%s\nN/A\nTEMP1\n",ctemp1,ctemp2); exit(0); return 0; } int output2mrtg (float temp1, float temp2 , char *label) { float ctemp1; float ctemp2; //tempconvert= floor(ctemp+0.5); ctemp1=floor((temp1 * 9 / 5 + 32)+.5); // convert to farenheit ctemp2=floor((temp2 * 9 / 5 + 32)+.5); // tempconvert= floor(ctemp+0.5); // sprintf(ctemp1,"%d", tempconvert); printf ("%.1f\n%.1f\nN/A\n%s\n",ctemp1,ctemp2,label); return 0; } int listdevices() { int i; int NumDevices=0; printf("searching for devices\n"); NumDevices = FindDevices(portnum, &FamilySN[0], 0x10, MAXDEVICES); if (NumDevices>0) { printf("Device(s) Found: \n"); for (i = 0; i < NumDevices; i++) { PrintSerialNum(FamilySN[i]); printf("\n"); } printf("\n\n"); } return 0; }