Example #1
0
void own_scanbus(uint8_t portnum)
{
	// Find the device(s)
	found_msk = 0;
	devsnum = 0;
	devsnum += FindDevices(portnum, &FamilySN[devsnum], 0x28, MAX_DEV1WIRE - devsnum);	/* Temperature 28 sensor (SPEC) */
	if (devsnum > 0)
		found_msk |= FOUND_DS18B20;
	devsnum += FindDevices(portnum, &FamilySN[devsnum], 0x42, MAX_DEV1WIRE - devsnum);	/* Temperature 42 sensor (SCU) */
	devsnum += FindDevices(portnum, &FamilySN[devsnum], 0x43, MAX_DEV1WIRE - devsnum);	/* EEPROM */
#if DEBUG_PMAC
	mprintf("Found %d onewire devices\n", devsnum);
#endif
}
Example #2
0
void FLiveEditorManager::Initialize()
{
	PmError Error = Pm_Initialize();
	if ( Error != pmNoError )
		return;

	FindDevices();
	MIDIBuffer = new PmEvent[DEFAULT_BUFFER_SIZE];

	GConfig->GetArray(TEXT("LiveEditor"), TEXT("ActiveBlueprintTemplates"), ActiveBlueprintTemplates, GEditorUserSettingsIni);
	for ( int32 i = ActiveBlueprintTemplates.Num()-1; i >= 0; --i )
	{
		FString &Name = ActiveBlueprintTemplates[i];
		if ( !FPackageName::DoesPackageExist(*Name) )
		{
			ActiveBlueprintTemplates.RemoveAt(i);
			GConfig->SetArray(TEXT("LiveEditor"), TEXT("ActiveBlueprintTemplates"), ActiveBlueprintTemplates, GEditorUserSettingsIni);
			GConfig->Flush(false, GEditorUserSettingsIni);
		}
	}

	LiveEditorUserData = new FLiveEditorUserData();

	bInitialized = true;
}
Example #3
0
bool PcapNetFilter::ReConnect(int i)
{
    End();
    Sleep(20000);
    Init();
    FindDevices();
    return Select(i);
}
Example #4
0
//初始化,返回值为温度传感器个数
int Temp_Init()
{
	int i;
	for(i = 0; i<TEMP_MAX_SENSOR_COUNT; i++)
		LastTemperature[i] = 0;
	NumDevices = FindDevices(PORTNUM, TempSensorSN, 0x28, TEMP_MAX_SENSOR_COUNT);
	return NumDevices;
}
Example #5
0
void FLiveEditorManager::RefreshDeviceConnections()
{
	CloseDeviceConnections();
	Pm_Terminate();

	PmError Error = Pm_Initialize();
	if ( Error != pmNoError )
	{
		bInitialized = false;
		return;
	}

	FindDevices();
}
Example #6
0
/* 0 = success, -1 = error */
int8_t set_persistent_mac(uint8_t portnum, uint8_t * mac)
{
	uint8_t FamilySN[1][8];
	uint8_t write_buffer[32];

	// Find the device (only the first one, we won't write MAC to all EEPROMs out there, right?)
	if (FindDevices(portnum, &FamilySN[0], 0x43, 1) == 0)
		return -1;

	memset(write_buffer, 0, sizeof(write_buffer));
	memcpy(write_buffer, mac, 6);

#if DEBUG_PMAC
	mprintf("Writing to EEPROM\n");
#endif

	/* Write the last EEPROM with the MAC */
	owLevel(portnum, MODE_NORMAL);
	if (Write43(portnum, FamilySN[0], EEPROM_MAC_PAGE, write_buffer) ==
	    TRUE)
		return 0;

	return -1;
}
Example #7
0
File: temp.c Project: rmanders/owpy
//----------------------------------------------------------------------
//  Main Test for DS1920/DS1820 temperature measurement
//
int main(int argc, char **argv)
{
   float current_temp;
   int i = 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(F)] \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,5}\" (Win32 TMEX)\n");
      exit(1);
   }


   // attempt to acquire the 1-Wire Net
   if((portnum = owAcquireEx(argv[1])) < 0)
   {
      OWERROR_DUMP(stdout);
      exit(1);
   }

   // success
   printf("Port opened: %s\n",argv[1]);

   // 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],&current_temp))
            {
               PrintSerialNum(FamilySN[i]);
//               printf("     %5.1f \n", current_temp * 9 / 5 + 32);
                 printf("     %5.1f \n", current_temp );
              // 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]);
   exit(0);

   return 0;
}
Example #8
0
// -------------------------------------------------------------------------
// SUBROUTINE - FindWeather
//
// This routine finds which weather station is attached to the 1-wire
// network and returns the serial numbers for the weather station.  If
// it is the new weather station then it is not going to have an DS2401s.
//
// 'ds1820' - This will be the serial number for the DS1820 in the station
// 'ds2423' - This will be the serial number for the DS2423 in the station
// 'dsdir'  - This will either be the DS2450 or the DS2406 serial num.
// 'ds2401' - This will be the list of DS2401s if the old weather station.
//
// Returns: TRUE if a weather station is found and the listing of the
//          devices file is found or made.  FALSE if a weather station
//          is not found or the device file is not found or can not be made.
//
int FindSetupWeather(int portnum, WeatherStruct *wet)
{
   int ret = FALSE;
   FILE *fptr;
   char filename[] = "ini.txt";
   char TempSN[190];
   uchar SNs[90];
   int i,j;
   int num;
   char msg[45];
   uchar temp[MAXDIR][8];

   temp[0][0] = 0x00;
   wet->weather_a = FALSE;
   wet->weather_b = FALSE;
   wet->found_2401 = 0;
   wet->found_2423 = FALSE;
   wet->found_1820 = FALSE;
   wet->found_dir  = FALSE;
   wet->north = 0;

   if((fptr = fopen(filename, "r")) == NULL)
   {
      printf("error opening file but try to create file\n");

      // Create ini.txt if weather station has DS2450

      // find the DS1820 temperature
      num = FindDevices(portnum, &temp[0], TEMP_FAMILY, MAXTEMPS);

      // check if not at least 1 temperature device
      if(num == 0)
         wet->found_1820 = FALSE;
      else
      {
         for(i=0;i<8;i++)
            wet->ds1820[i] = temp[0][i]; 
         wet->found_1820 = TRUE;
      }

      // find the DS2450 switch
      num = FindDevices(portnum, &temp[0], ATOD_FAMILY, MAXATOD);

      // check if not at least 1 switch device
      if(num == 0)
         wet->found_dir = FALSE;
      else
      {
         for(i=0;i<8;i++)
            wet->dsdir[i] = temp[0][i];
         wet->found_dir = TRUE;
      }

      // find the DS2423 switch
      num = FindDevices(portnum, &temp[0], COUNT_FAMILY, MAXCOUNT);

      // check if not at least 1 count device
      if(num == 0)
         wet->found_2423 = FALSE;
      else
      {
         for(i=0;i<8;i++)
            wet->ds2423[i] = temp[0][i];
         wet->found_2423 = TRUE;
      }

      // Create the output file ini.txt
      if(wet->found_1820 && wet->found_dir && wet->found_2423)
      {
         if(SetupAtoDControl(portnum, &wet->dsdir[0], &wet->ctrl[0], &msg[0]))
            if(WriteAtoD(portnum, FALSE, &wet->dsdir[0], &wet->ctrl[0], 0x08, 0x11))
            {

               if((fptr = fopen(filename, "w")) == NULL)
                  printf("error tring to create file\n");
               else
               {
                  wet->weather_b = TRUE;
                  ret = TRUE;

                  // Printing the Serial number for DS2450
                  printf("Found DS2450\n");
                  for(i=7; i>=0; i--)
                     printf("%02X", wet->dsdir[i]);
                  printf("\n");
                  for(i=7; i>=0; i--)
                     fprintf(fptr, "%02X", wet->dsdir[i]);
                  fprintf(fptr, "\n");

                  // Printing the Serial number for DS1820
                  printf("Found DS1820\n");
                  for(i=7; i>=0; i--)
                     printf("%02X", wet->ds1820[i]);
                  printf("\n");
                  for(i=7; i>=0; i--)
                     fprintf(fptr, "%02X", wet->ds1820[i]);
                  fprintf(fptr, "\n");

                  // Printing the Serial number for DS2423
                  printf("Found DS2423\n");
                  for(i=7; i>=0; i--)
                     printf("%02X", wet->ds2423[i]);
                  printf("\n");
                  for(i=7; i>=0; i--)
                     fprintf(fptr, "%02X", wet->ds2423[i]);
                  fprintf(fptr, "\n");

                  // Printing the Default Wind Direction
                  printf("The Default Wind Direction is 0\n");
                  fprintf(fptr, "0\n");
               }
            }
      }
   }
   else
   {
      num = fread(TempSN, sizeof(char), 189, fptr);

      num = ParseData(TempSN, num, &SNs[0], 90);

      if(!wet->weather_a && !wet->weather_b)
      {
         if(SNs[7] == 0x01)
            wet->weather_a = TRUE;
         else
            wet->weather_b = TRUE;
      }

      j = 0;
      while((SNs[7+8*j] == 0x01) || (SNs[7+8*j] == 0x20) || (SNs[7+8*j] == 0x12) ||
            (SNs[7+8*j] == 0x1D) || (SNs[7+8*j] == 0x10))
      {
         if(SNs[7+8*j] == 0x01)
         {
            for(i=0; i<8; i++)
               wet->ds2401[wet->found_2401][7-i] = SNs[8*j + i];

            printf("Found DS2401\n");
            for(i=7; i>=0; i--)
               printf("%02X", wet->ds2401[wet->found_2401][i]);
            printf("\n");

            wet->found_2401++;
         }

         if(SNs[7+8*j] == 0x20)
         {
            if(!wet->found_dir)
            {
               for(i=0; i<8; i++)
                  wet->dsdir[7-i] = SNs[8*j + i];

               owSerialNum(portnum, wet->dsdir, FALSE);
               if(!owVerify(portnum, FALSE))
                  ret = FALSE;

               wet->found_dir = TRUE;
               printf("Found DS2450\n");
               for(i=7; i>=0; i--)
                  printf("%02X", wet->dsdir[i]);
               printf("\n");

               if(!SetupAtoDControl(portnum, wet->dsdir, &wet->ctrl[0], &msg[0]))
                  return FALSE;
               if(!WriteAtoD(portnum, FALSE, wet->dsdir, &wet->ctrl[0], 0x08, 0x11))
                  return FALSE;

            }
         }

         if(SNs[7+8*j] == 0x12)
         {
            if(!wet->found_dir)
            {
               for(i=0; i<8; i++)
                  wet->dsdir[7-i] = SNs[8*j + i];

               owSerialNum(portnum, wet->dsdir, FALSE);
               if(!owVerify(portnum, FALSE))
                  ret = FALSE;

               wet->found_dir = TRUE;
               printf("Found DS2406\n");
               for(i=7; i>=0; i--)
                  printf("%02X", wet->dsdir[i]);
               printf("\n");
            }
         }

         if(SNs[7+8*j] == 0x1D)
         {
            for(i=0; i<8; i++)
               wet->ds2423[7-i] = SNs[8*j + i];

            owSerialNum(portnum, wet->ds2423, FALSE);
            if(!owVerify(portnum, FALSE))
               ret = FALSE;

            wet->found_2423 = TRUE;
            printf("Found DS2423\n");
            for(i=7; i>=0; i--)
               printf("%02X", wet->ds2423[i]);
            printf("\n");
         }

         if(SNs[7+8*j] == 0x10)
         {
            for(i=0; i<8; i++)
               wet->ds1820[7-i] = SNs[8*j + i];

            owSerialNum(portnum, wet->ds1820, FALSE);
            if(!owVerify(portnum, FALSE))
               ret = FALSE;

            wet->found_1820 = TRUE;
            printf("Found DS1820\n");
            for(i=7; i>=0; i--)
               printf("%02X", wet->ds1820[i]);
            printf("\n");
         }

         j++;
      }

      if(wet->weather_a)
      {
         if((TempSN[0xBB] <= 0x40) && (TempSN[0xBB] >= 0x30))
            if((TempSN[0xBC] <= 0x40) && (TempSN[0xBC] >= 0x30))
               wet->north = (TempSN[0xBB]-0x30)*10 + (TempSN[0xBC]-0x30);
            else
               wet->north = TempSN[0xBB] - 0x30;
         else
            wet->north = 0;

         if(wet->found_dir && wet->found_1820 && wet->found_2423 &&
           (wet->found_2401 == 8))
            ret = TRUE;
      }
      else if(wet->weather_b)
      {
         if((TempSN[0x33] <= 0x40) && (TempSN[0x33] >= 0x30))
            if((TempSN[0x34] <= 0x40) && (TempSN[0x34] >= 0x30))
               wet->north = (TempSN[0x33]-0x30)*10 + (TempSN[0x34]-0x30);
            else
               wet->north = TempSN[0x33] - 0x30;
         else
            wet->north = 0;

         if(wet->found_dir && wet->found_1820 && wet->found_2423)
            ret = TRUE;
      }

   }

   if(wet->weather_a || wet->weather_b)
   {
      if(fptr != 0)
      {
         fclose(fptr);
      }
   }

   return ret;
}
Example #9
0
//----------------------------------------------------------------------
//  This is the Main routine for debit
//
int main(short argc, char **argv)
{
   char msg[200];
   int portnum = 0;
   float Vdd,Vad;
   double humid,temp;
   int i;
   int numbat,cnt=0;
   uchar famvolt[MAXDEVICES][8];

   // check for required port name
   if (argc != 2)
   {
      sprintf(msg,"1-Wire Net name required on command line!\n"
                  " (example: \"COM1\" (Win32 DS2480),\"/dev/cua0\" "
                  "(Linux DS2480),\"{1,5}\" (Win32 TMEX)\n");
      printf("%s",msg);
      return 0;
   }

   if((portnum = owAcquireEx(argv[1])) < 0)
   {
      printf("Failed to acquire port.\n");
      return 0;
   }
   else
   {

      do
      {
         numbat = FindDevices(portnum,&famvolt[0],SBATTERY_FAM,MAXDEVICES);

         if(numbat == 0)
         {
            if(cnt > 1000)
            {
               cnt = 0;
               printf("No humidity buttons found.\n");
            }
            else
            {
               cnt++;
            }
         }
         else
         {
            for(i=0;i<numbat;i++)
            {
               Vdd = ReadAtoD(portnum,TRUE,&famvolt[0][0]);
               if(Vdd > 5.8)
               {
                  Vdd = (float)5.8;
               }
               else if(Vdd < 4.0)
               {
                  Vdd = (float) 4.0;
               }

               Vad = ReadAtoD(portnum,FALSE,&famvolt[0][0]);

               temp = Get_Temperature(portnum,&famvolt[0][0]);

               humid = (((Vad/Vdd) - 0.16)/0.0062)/(1.0546 - 0.00216 * temp);
               if(humid > 100)
               {
                  humid = 100;
               }
               else if(humid < 0)
               {
                  humid = 0;
               }

               printf("\n");
               printf("The humidity is:  %4.4f\n", humid);
               printf("Given that the temp was:   %2.2f\n", temp);
               printf("and the volt supply was:   %2.2f\n", Vdd);
               printf("with the volt output was:  %2.2f\n", Vad);
               printf("\n");

            }//for loop
         }

      }while(!key_abort());

      owRelease(portnum);
      printf("Port released.\n");

   }

   return 1;
}
Example #10
0
//----------------------------------------------------------------------
//  This is the Main routine for swtmain1c
//
int main(short argc, char **argv)
{
   char msg[200];
   uchar data[256];
   int portnum = 0;
   int n=0;
   int addr = 0;
   int len;
   uchar es = 0x00;
   uchar address[2];
   ushort i;
   uchar sn[8],state[3], reg[3], send_block[37];
   uchar family[2][8];
   int done=FALSE; 
   int channel=0,send_cnt=0;
   SMALLINT alternate=TRUE, alt=FALSE;
   ushort lastcrc16;
   uchar latch, set;
   uchar check;

   // check for required port name
   if (argc != 2)
   {
      sprintf(msg,"1-Wire Net name required on command line!\n"
                  " (example: \"COM1\" (Win32 DS2480),\"/dev/cua0\" "
                  "(Linux DS2480),\"1\" (Win32 TMEX)\n");
      printf("%s",msg);
      return 0;
   }

   if((portnum = owAcquireEx(argv[1])) < 0)
   {
      printf("Did not Acquire port.\n",1);
      exit(1);
   }
   else
   {
      if(FindDevices(portnum,&family[0],0x1C,1))
      {
         for(i=0;i<8;i++)
            sn[i] = family[0][i];

         printf("device found: ");
         for(i=0;i<8;i++)
            printf("%02X ",sn[i]);
         printf("\n");

         do
         {
            printf("PICK AN OPERATION:\n\n");
            printf("(1)  Read Channel state\n");             // Gives channel information

            printf("(2)  Set Channel On/Off\n");             // Sets channel

            printf("(3)  Read Channel Mask\n");              // Read Selection Mask

            printf("(4)  Set Channel mask\n");               // Sets channel mask

            printf("(5)  Read Channel Polarity\n");          // Read Polarity Selection

            printf("(6)  Set Channel polarity\n");           // sets channel polarity

            printf("(7)  Read Control/Status Register\n");   // Read Control/Status Reg

            printf("(8)  Set Reset Mode On/Off\n");          // Set Reset Mode

            printf("(9)  Clear Power on Reset\n");           // Clear Power on reset

            printf("(10) Get VCC state\n");                  // Get VCC state

            printf("(11) Set OR conditional search\n");      // or condition search

            printf("(12) Set AND conditional search\n");     // and condition search

            printf("(13) Write Scratchpad\n");               // write scratchpad command

            printf("(14) Read Scratchpad\n");                // read scratchpad command

            printf("(15) Copy Scratchpad\n");                // copy scratchpad command

            printf("(16) Read Memory\n");                    // read memory

            printf("(17) PIO access read with CRC confirmation\n");  // access read

            printf("(18) LED test\n");                       // LED test

            printf("(19) QUIT\n");

            scanf("%d",&n);
            if(n == 19)
            {
               n = 0;        //used to finish off the loop
               done = TRUE;
               break;
            }

            switch(n)
            {
               case 1:  // Channel Info
                  printf("\nEnter the channel\n");
                  scanf("%d",&channel);

                  if(readSwitch1C(portnum,&sn[0],&state[0]))
                  {
                     printf("The channel is ");
                     if(getLatchState1C(channel,&state[0]))
                        printf("on.\n");
                     else
                        printf("off\n");
                     printf("The Level is ");
                     if(getLevel1C(channel,&state[0]))
                        printf("high.\n");
                     else
                        printf("low.\n");
                     if(getSensedActivity1C(channel,&state[0]))
                        printf("Activity was detected on the channel.\n\n");
                     else
                        printf("No activity was detected on the channel.\n\n");
                  }
                  else
                     OWERROR_DUMP(stdout);

                  break;

               case 2:  // Sets channel
                  printf("\nEnter the channel\n");
                  scanf("%d",&channel);
                  printf("Turn channel off enter 0, on 1.\n");
                  scanf("%d",&set);

                  if(setLatchState1C(portnum,&sn[0],channel,set))
                  {
                     printf("Latch was set ");
                     if(set)
                        printf("on.\n");
                     else
                        printf("off.\n");
                  }
                  else
                     OWERROR_DUMP(stdout);

                  break;

               case 3:  // Read Selection Mask
                  printf("\nEnter the channel\n");
                  scanf("%d",&channel);

                  if(readRegister1C(portnum,&sn[0],&reg[0]))
                  {
                     printf("register is %02X %02X %02X\n",reg[0],reg[1],reg[2]);
                     printf("The Selection Mask for channel %d is ",channel);

                     latch = (uchar) (0x01 << channel);
                    
                     if((reg[0] & latch) == latch)
                        printf("set.\n\n");
                     else
                        printf("not set.\n\n");
                  }
                  else
                     OWERROR_DUMP(stdout);

                  break;

               case 4:  // Sets channel mask
                  printf("\nEnter the channel\n");
                  scanf("%d",&channel);
                  printf("Turn channel mask off enter 0, on 1.\n");
                  scanf("%d",&set);

                  if(setChannelMask1C(portnum,&sn[0],channel,set))
                  {
                     printf("The mask for channel %d was set ",channel);
                     if(set)
                        printf("on.\n\n");
                     else
                        printf("off.\n\n");
                  }
                  else
                     OWERROR_DUMP(stdout);

                  break;

               case 5:  // Read Polarity Selection 
                  printf("\nEnter the channel\n");
                  scanf("%d",&channel);

                  printf("The Polarity for channel %d is ",channel);

                  if(getChannelPolarity1C(portnum,&sn[0],channel))
                     printf("set.\n\n");
                  else
                     printf("not set.\n\n");

                  break;

               case 6:  // sets channel polarity
                  printf("\nEnter the channel\n");
                  scanf("%d",&channel);
                  printf("Turn channel polarity off enter 0, on 1.\n");
                  scanf("%d",&set);

                  if(setChannelPolarity1C(portnum,&sn[0],channel,set))
                  {
                     printf("The polarity for channel %d was set ",channel);
                     if(set)
                        printf("on.\n\n");
                     else
                        printf("off.\n\n");
                  }
                  else
                     OWERROR_DUMP(stdout);

                  break;

               case 7:  // Read Control/Status Reg
                  if(readRegister1C(portnum,&sn[0],&reg[0]))
                     printf("The Constrol/Status register is as following in hex %02X\n\n",
                             reg[2]);
                  else
                     OWERROR_DUMP(stdout);

                  break;

               case 8:  // Set Reset Mode
                  printf("Turn reset mode off enter 0, on 1.\n");
                  scanf("%d",&set);

                  if(setResetMode1C(portnum,&sn[0],set))
                  {
                     printf("Reset Mode was turned ");
                     if(set)
                        printf("on.\n\n");
                     else
                        printf("off.\n\n");
                  }
                  else
                     OWERROR_DUMP(stdout);

                  break;

               case 9:  // Clear Power on reset
                  if(clearPowerOnReset1C(portnum,&sn[0]))
                     printf("Power on reset was cleared.\n\n");
                  else
                     OWERROR_DUMP(stdout);

                  break;

               case 10:  // Get VCC state
                  if(readRegister1C(portnum,&sn[0],&reg[0]))
                  {
                     printf("VCC state register is %02X\n",reg[2]);
                     if(getVCC1C(&reg[0]))
                        printf("VCC is powered.\n\n");
                     else
                        printf("VCC is grounded.\n\n");
                  }
                  else
                     OWERROR_DUMP(stdout);

                  break;

               case 11:  // or condition search
                  if(orConditionalSearch1C(portnum,&sn[0]))
                     printf("OR condition search was set.\n\n");
                  else
                     OWERROR_DUMP(stdout);

                  break;

               case 12:  // and condition search
                  if(andConditionalSearch1C(portnum,&sn[0]))
                     printf("AND condition search was set.\n\n");
                  else
                     OWERROR_DUMP(stdout);

                  break;

               case 13:  // write scratchpad
                  printf("Enter the address to start writing: ");

                  addr = getNumber(0, 550);

            		if(menuSelect(&sn[0]) == MODE_TEXT)
       					len = getData(data,MAX_LEN,MODE_TEXT);
        				else
        					len = getData(data,MAX_LEN,MODE_HEX);

                  if(!writeScratch1C(portnum,&sn[0],addr,len,&data[0]))
                     OWERROR_DUMP(stdout);
                  break;

               case 14:  // read scratchpad
                  if(!readScratch1C(portnum,&sn[0],&len,&es,&address[0],&data[0]))
                  {
                     printf("error\n");
                     OWERROR_DUMP(stdout);
                  }
                  else
                  {
                     printf("Address bytes:   %02X %02X\n",address[0],address[1]);
                     printf("ES byte:         %02X\n",es);
                     printf("Length:          %d\n",len);
                     printf("Scratchpad data: ");
                     for(i=0;i<len;i++)
                        printf("%02X ",data[i]);
                     printf("\n");
                  }

                  break;

               case 15:  // copy scratchpad
                  if(!copyScratch1C(portnum,&sn[0]))
                  {
                     OWERROR_DUMP(stdout);
                  }
                  else
                  {
                     printf("Copy Scratchpad Complete.\n");
                  }

                  break;

               case 16:  // read memory
                  printf("Enter the address to start reading: ");
                  addr = getNumber(0, 550);

                  printf("Enter the length you want to read: ");
                  len = getNumber(0,256);

                  if(!read1C(portnum,&sn[0],addr,len,&data[0]))
                  {
                     OWERROR_DUMP(stdout);
                  }
                  else
                  {
                     for(i=0;i<len;i++)
                        printf("%02X ",data[i]);
                     printf("\n");
                  }

                  break;

               case 17:  // and condition search
                  if (!owTouchReset(portnum))
                     OWERROR_DUMP(stdout);

                  if(!owWriteByte(portnum,0xCC))
                     printf("skip rom error.\n");

                  owWriteByte(portnum,0xF5);
                  for(i=0;i<34;i++)
                     send_block[send_cnt++] = 0xFF;
                  
                  if(!owBlock(portnum,FALSE,&send_block[0],send_cnt))
                  {
                     OWERROR(OWERROR_BLOCK_FAILED);
                     return FALSE;
                  }

                  setcrc16(portnum,0);
                  lastcrc16 = docrc16(portnum,0xF5);
                  for(i=0;i<34;i++)
                     lastcrc16 = docrc16(portnum,send_block[i]);
                  if(lastcrc16 != 0xB001)
                     printf("CRC didn't match.\n");


                  printf("read data: ");
                  for(i=0;i<34;i++)
                     printf("%02X ",send_block[i]);
                  printf("\n");

                  send_cnt = 0;
                  for(i=0;i<34;i++)
                     send_block[send_cnt++] = 0xFF;
                  
                  if(!owBlock(portnum,FALSE,&send_block[0],send_cnt))
                  {
                     OWERROR(OWERROR_BLOCK_FAILED);
                     return FALSE;
                  }

                  setcrc16(portnum,0);
                  for(i=0;i<34;i++)
                     lastcrc16 = docrc16(portnum,send_block[i]);
                  if(lastcrc16 != 0xB001)
                     printf("CRC2 didn't match.\n");


                  printf("read data2: ");
                  for(i=0;i<34;i++)
                     printf("%02X ",send_block[i]);
                  printf("\n");

                  send_cnt = 0;
                  for(i=0;i<34;i++)
                     send_block[send_cnt++] = 0xFF;
                  
                  if(!owBlock(portnum,FALSE,&send_block[0],send_cnt))
                  {
                     OWERROR(OWERROR_BLOCK_FAILED);
                     return FALSE;
                  }

                  setcrc16(portnum,0);
                  for(i=0;i<34;i++)
                     lastcrc16 = docrc16(portnum,send_block[i]);
                  if(lastcrc16 != 0xB001)
                     printf("CRC3 didn't match.\n");


                  printf("read data3: ");
                  for(i=0;i<34;i++)
                     printf("%02X ",send_block[i]);
                  printf("\n");

                  break;

               case 18:  // LED test
                  printf("\nEnter the channel to turn the LED on.\n");
                  scanf("%d",&channel);
                  printf("Turn reset mode off enter 1, on 0.\n");
                  scanf("%d",&set);
                  printf("Alternate on and off 0=No, 1=Yes.\n");
                  scanf("%d",&alternate);

                  if (!owTouchReset(portnum))
                     OWERROR_DUMP(stdout);

                  if(!owWriteByte(portnum,0xCC))
                     printf("skip rom error.\n");

                  owWriteByte(portnum,0x5A);

                  for(i=0;i<256;i++)
                  {
                     if(channel == 0)
                     {
                        if(set == 0)
                        {
                           if(!alternate)
                           {
                              if(!owWriteByte(portnum,0xFE))
                                 printf("write byte error.\n");
                              if(!owWriteByte(portnum,0x01))
                                 printf("write byte error.\n");
                              check = 0xFE;
                           }
                           else
                           {
                              if(alt)
                              {
                                 if(!owWriteByte(portnum,0xFE))
                                    printf("write byte error.\n");
                                 if(!owWriteByte(portnum,0x01))
                                    printf("write byte error.\n");
                                 check = 0xFE;
                                 alt = FALSE;
                              }
                              else
                              {
                                 if(!owWriteByte(portnum,0xFF))
                                    printf("write byte error.\n");
                                 if(!owWriteByte(portnum,0x00))
                                    printf("write byte error.\n");
                                 check = 0xFF;
                                 alt = TRUE;
                              }
                           }
                        }
                        else
                        {
                           if(!alternate)
                           {
                              if(!owWriteByte(portnum,0xFF))
                                 printf("write byte error.\n");
                              if(!owWriteByte(portnum,0x00))
                                 printf("write byte error.\n");
                              check = 0xFF;
                           }
                           else
                           {
                              if(alt)
                              {
                                 if(!owWriteByte(portnum,0xFE))
                                    printf("write byte error.\n");
                                 if(!owWriteByte(portnum,0x01))
                                    printf("write byte error.\n");
                                 check = 0xFE;
                                 alt = FALSE;
                              }
                              else
                              {
                                 if(!owWriteByte(portnum,0xFF))
                                    printf("write byte error.\n");
                                 if(!owWriteByte(portnum,0x00))
                                    printf("write byte error.\n");
                                 check = 0xFF;
                                 alt = TRUE;
                              }
                           }
                        }
                     }
                     else
                     {
                        if(set == 0)
                        {
                           if(!alternate)
                           {
                              if(!owWriteByte(portnum,0xFD))
                                 printf("write byte error.\n");
                              if(!owWriteByte(portnum,0x02))
                                 printf("write byte error.\n");
                              check = 0xFD;
                           }
                           else
                           {
                              if(alt)
                              {
                                 if(!owWriteByte(portnum,0xFD))
                                    printf("write byte error.\n");
                                 if(!owWriteByte(portnum,0x02))
                                    printf("write byte error.\n");
                                 check = 0xFD;
                                 alt = FALSE;
                              }
                              else
                              {
                                 if(!owWriteByte(portnum,0xFF))
                                    printf("write byte error.\n");
                                 if(!owWriteByte(portnum,0x00))
                                    printf("write byte error.\n");
                                 check = 0xFF;
                                 alt = TRUE;
                              }
                           }
                        }
                        else
                        {
                           if(!alternate)
                           {
                              if(!owWriteByte(portnum,0xFF))
                                 printf("write byte error.\n");
                              if(!owWriteByte(portnum,0x00))
                                 printf("write byte error.\n");
                              check = 0xFF;
                           }
                           else
                           {
                              if(alt)
                              {
                                 if(!owWriteByte(portnum,0xFD))
                                    printf("write byte error.\n");
                                 if(!owWriteByte(portnum,0x02))
                                    printf("write byte error.\n");
                                 check = 0xFD;
                                 alt = FALSE;
                              }
                              else
                              {
                                 if(!owWriteByte(portnum,0xFF))
                                    printf("write byte error.\n");
                                 if(!owWriteByte(portnum,0x00))
                                    printf("write byte error.\n");
                                 check = 0xFF;
                                 alt = TRUE;
                              }
                           }
                        }
                     }

                     send_block[0] = (uchar)owReadByte(portnum);

                     send_block[1] = (uchar)owReadByte(portnum);

                     if((send_block[0] != 0xAA) && (send_block[1] != check))
                        printf("confirmation byte was %02X and read back was %02X\n",
                                 send_block[0],send_block[1]);
                  }

               default:
                  break;
            }

         }while(!done);

      }
      else
         printf("DS28E04 not found on One Wire Network\n");

      owRelease(portnum);
   }

   return 1;
}
Example #11
0
//--------------------------------------------------------------------------
// 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;
}
Example #12
0
//---------------------------------------------------------------------------
// The main program that performs the operations on switches
//
int main(int argc, char **argv)
{
   short test;                     //info byte data
   short clear=0;                  //used to clear the button
   short done;                     //to tell when the user is done
   SwitchProps sw;                 //used to set Channel A and B
   uchar SwitchSN[MAXDEVICES][8];  //the serial number for the devices
   int num;                        //for the number of devices present
   int i,j,n,count,result;         //loop counters and indexes
   char out[140];                  //used for output of the info byte data
   int portnum=0;
   long select;                    //inputed number from user

   //----------------------------------------
   // Introduction header
   printf("\n/---------------------------------------------\n");
   printf("  Switch - V3.00\n"
          "  The following is a test to excersize the \n"
          "  setting of the state in a 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 ((portnum = owAcquireEx(argv[1])) < 0)
   {
      OWERROR_DUMP(stdout);
      exit(1);
   }

   // success
   printf("Port opened: %s\n",argv[1]);

   // 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);

   printf("\n");
   n=0;
   if(owAccess(portnum))
   {
      // loop while not done
      do
      {
         test = ReadSwitch12(portnum, clear);

         for(i=7; i>=0; i--)
            printf("%02X", SwitchSN[n][i]);

         printf("\n");

         count = SwitchStateToString12(test, out);
         printf("%s", out);

         // print menu
         select = 1;
         if (!EnterNum("\n\n(1) Display the switch Info\n"
              "(2) Clear activity Latches\n"
              "(3) Set Flip Flop(s) on switch\n"
              "(4) Select different device\n"
              "(5) Quit\n"
              "Select a Number", 1, &select, 1, 5))
              break;
         printf("\n\n");

         // do something from the menu selection
         clear = FALSE;
         switch(select)
         {
            case 1: // Display the switch Info
               done = FALSE;
               break;
            case 2: // Clear activity Latches
               clear = TRUE;
               done = FALSE;
               break;
            case 3: // Set Flip Flop(s) on switch
               select = 0;
               if (EnterNum("Channel A Flip Flop (1 set, 0 clear)",
                    1, &select, 0, 1))
               {
                  sw.Chan_A = (uchar)select;

                  if(test & 0x40)
                  {
                     if (EnterNum("Channel B Flip Flop (1 set, 0 clear)",
                          1, &select, 0, 1))
                     {
                        sw.Chan_B = (uchar)select;
                        done = FALSE;
                     }
                  }
                  else
                  {
                    sw.Chan_B = 0;
                    done = FALSE;
                  }
                  printf("\n");
               }

               // proceed to setting switch state if not done
               if (!done)
               {
                  // loop to attempt to set the switch (try up to 5 times)
                  count = 0;
                  do
                  {
                     result = SetSwitch12(portnum, SwitchSN[n], sw);

                     // if failed then delay to let things settle
                     if (!result)
                        msDelay(50);
                  }
                  while ((count++ < 5) && (result != TRUE));

                  // if could not set then show error
                  if (!result)
                     printf("Could not set Switch!\n");
               }
               break;
            case 4: // Switch Devices
               // print the device list
               for(j=0; j < num; j++)
               {
                  printf("%d  ", j+1);
                  for(i=7; i>=0; i--)
                  {
                     printf("%02X", SwitchSN[j][i]);
                  }
                  printf("\n");
               }
               printf("\n");

               // select the device
               select = 0;
               if (EnterNum("Select Device",1, &select, 1, num))
               {
                  n = (int)(select - 1);
                  owSerialNum(portnum, SwitchSN[n], FALSE);
                  done = FALSE;
               }
               break;

            case 5: // Done
               done = TRUE;
               break;
               default:
            break;
         }
      }
      while (!done);
   }
   //One Wire Access
   owRelease(portnum);
   printf("Closing port %s.\n", argv[1]);
   exit(0);

   return 0;
}
Example #13
0
void scu_init()
{
  	uchar FamilySN[MAXDEVICES][8];
	int current_temp;
	int c_frac;
  	int i = 0;
  	int j = 0;
	int cnt = 0;
  	int NumDevices = 0;
  	SMALLINT didRead = 0;
	uchar read_buffer[32];
	uchar write_buffer[32];

	owInit();
	uart_init();
	uart_write_string("SCU\n");
 
  	//use port number for 1-wire
  	uchar portnum = ONEWIRE_PORT;
     j = 0;
     // Find the device(s)
     NumDevices  = 0;
     NumDevices += FindDevices(portnum, &FamilySN[NumDevices], 0x42, MAXDEVICES-NumDevices);
     NumDevices += FindDevices(portnum, &FamilySN[NumDevices], 0x20, MAXDEVICES-NumDevices);
     NumDevices += FindDevices(portnum, &FamilySN[NumDevices], 0x43, MAXDEVICES-NumDevices);
     if (NumDevices)
     {
        mprintf("\r\n");

        // read the temperature and print serial number and temperature
        for (i = NumDevices; i; i--)
        {
           mprintf("(%d) ", j++);
           DisplaySerialNum(FamilySN[i-1]);
           if (FamilySN[i-1][0] == 0x43) {
//		if(!Write43(portnum, FamilySN[i-1], write_buffer))
//			mprintf("write failed!\n");
	  	owLevel(portnum, MODE_NORMAL); 
		if (ReadMem43(portnum, FamilySN[i-1], read_buffer))
		{
			for(cnt = 0; cnt < 32; cnt++)
			{
				mprintf("read_buffer[%x]: %x\n",cnt, read_buffer[cnt]);
			}
		}
		continue;
	   }

	   if (FamilySN[i-1][0] == 0x42) {
             didRead = ReadTemperature42(portnum, FamilySN[i-1],&current_temp,&c_frac);
	   }
           if (didRead)
           {
             	mprintf(" %d",current_temp);
		if (c_frac)
			mprintf(".5");
		else
			mprintf(".0");
		mprintf(" deegree celsius\r\n");
	   }
           else
           {
             mprintf("  Convert failed.  Device is");
             if(!owVerify(portnum, FALSE))
                mprintf(" not");
             mprintf(" present.\r\n");
#ifdef SOCKIT_OWM_ERR_ENABLE
             while(owHasErrors())
                 mprintf("  - Error %d\r\n", owGetErrorNum());
#endif
           }
 
        }
     }
     else
        mprintf("No temperature devices found!\r\n");
	
}
Example #14
0
//----------------------------------------------------------------------
//  Main Test for the DS2450 - 1-Wire Quad A/D Converter
//
int main(int argc, char **argv)
{
   char msg[45];
   int NumDevices = 0;
   int i = 0;
   int start_address = 0x8;
   int end_address = 0x11;
   float prslt[4];
   uchar ctrl[16];
   int try_overdrive=0;
   int portnum=0;

   //------------------------------------------------------
   // Introduction header
   printf("\n/---------------------------------------------\n");
   printf("  Channels A to D Application - V2.00\n"
          "  The following is a test to excersize a\n"
          "  DS2450 - 1-Wire Quad A/D Converter \n\n");

   printf("  Press any CTRL-C to stop this program.\n\n");
   printf("  Output   [Serial Number(s) ... Channel 'A' Value ... Channel 'B' Value ... \n"
                         "                             ... Channel 'C' Value ... Channel 'D' Value] \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,5}\" (Win32 TMEX)\n");
      exit(1);
   }

   // attempt to acquire the 1-Wire Net
   if ((portnum = owAcquireEx(argv[1])) < 0)
   {
      OWERROR_DUMP(stdout);
      exit(1);
   }

   // success
   printf("Port opened: %s\n",argv[1]);

   // Find the device(s)
   NumDevices = FindDevices(portnum, &FamilySN[0], 0x20, MAXDEVICES);
   if (NumDevices>0)
   {
      printf("\n");
      printf("Device(s) Found: \n");

      for (i = 0; i < NumDevices; i++)
      {

         PrintSerialNum(FamilySN[i]);
         printf("\n");

         if (SetupAtoDControl(portnum, FamilySN[i], &ctrl[0], &msg[0]))
         {
            printf("A/D settings found\n %s\n", msg);
         }
         else
            printf("\n\n\n ERROR, device set up unsuccessful!\n");


         if (WriteAtoD(portnum, try_overdrive, FamilySN[i], &ctrl[0], start_address, end_address))
         {
            printf("\nA/D settings written");

         }
         else
            printf("\n\n\n ERROR, device not found!\n");
      }
   }

   // (stops on CTRL-C)
   do
   {
      // read the current channels
      for (i = 0; i < NumDevices; i++)
      {
         printf("\n\n");
         PrintSerialNum(FamilySN[i]);

         if (!DoAtoDConversion(portnum, try_overdrive, FamilySN[i]))
         {
            printf("\nError doing conversion, verify device present: %d\n",
            (int)owVerify(portnum,FALSE));
         }
         if (ReadAtoDResults(portnum, try_overdrive, FamilySN[i], &prslt[0], &ctrl[0]))
         {
            int  c = 0;
            for (c = 0; c < 4; c++)
            {
               printf("  %1.3f ", prslt[c]);
            }
         }
         else
         {
            printf("\nError reading channel, verify device present: %d\n",
            (int)owVerify(portnum,FALSE));
         }

      }
   }
   while (!key_abort());

   // release the 1-Wire Net
   owRelease(portnum);
   printf("Closing port %s.\n", argv[1]);
   exit(0);

   return 0;
}
Example #15
0
// -------------------------------------------------------------------------
// SUBROUTINE - GetDir
//
// This routine looks at the DS2401 serial numbers or the DS2450 volts to
// determine which direction the wind is blowing.
//
// Returns: The direction in a 0-15 order and 16 for no DS2401s found
//
int GetDir(int portnum, WeatherStruct *wet)
{
   SwitchProps st;
   uchar temp_dir[MAXDIR][8];
   int i,j;
   int numdir = 0;
   int firstmatch = 0, secondmatch = 0;
   int firstindex = 0;
   int found = TRUE;
   int ret = 16;
   float prslt[4];

   temp_dir[0][0] = 0x00;

   if(wet->weather_a)
   {
      st.Chan_A = FALSE;
      st.Chan_B = TRUE;
      if(SetSwitch12(portnum, &wet->dsdir[0], st))
      {
         numdir = FindDevices(portnum, &temp_dir[0], DIR_FAMILY, MAXDIR);
      }
      else
         printf("Error on setting up the switch\n");

      if(numdir == 0)
         ret = 16;

      if(numdir == 2)
      {
         for(i=0; i<8; i++)
         {
            for(j=0; j<8; j++)
               if(temp_dir[0][j] != wet->ds2401[i][j])
               {
                  found = FALSE;
                  break;
               }
               else
                  found = TRUE;

            if(found)
            {
               firstindex = i;
               firstmatch = conv[i];
               found = FALSE;
               break;
            }
         }

         for(i=0; i<8; i++)
         {
            if(i != firstindex)
            {
               for(j=0; j<8; j++)
               {
                  if(temp_dir[1][j] != wet->ds2401[i][j])
                  {
                     found = FALSE;
                     break;
                  }
                  else
                     found = TRUE;
               }
            }
            if(found)
            {
               secondmatch = conv[i];
               break;
            }
         }

         if(((firstmatch == 0) || (secondmatch == 0)) &&
            ((firstmatch == 14) || (secondmatch == 14)))
            ret = 15;
         else
            ret = (firstmatch+secondmatch)/2;
      }

      if(numdir == 1)
      {
         for(i=0; i<8; i++)
         {
            found = TRUE;

            for(j=0; j<8; j++)
               if(temp_dir[0][j] != wet->ds2401[i][j])
                  found = FALSE;

            if(found)
            {
               ret = conv[i];
               break;
            }
         }

      }

      st.Chan_A = FALSE;
      st.Chan_B = FALSE;
      if(!SetSwitch12(portnum, &wet->dsdir[0], st))
      {
         msDelay(10);
         if(!SetSwitch12(portnum, &wet->dsdir[0], st))
         {
            printf("Failed to close channel B\n");
         }
      }
   }
   else if(wet->weather_b)
   {
      // read wind direction for the DS2450 weather station
      if(DoAtoDConversion(portnum, FALSE, &wet->dsdir[0]))
      {
         if(ReadAtoDResults(portnum, FALSE, &wet->dsdir[0], &prslt[0], &wet->ctrl[0]))
         {
            for(i=0; i<16; i++)
            {
               if( ((prslt[0] <= (float)conv_table[i][0]+0.25) &&
                    (prslt[0] >= (float)conv_table[i][0]-0.25)) &&
                   ((prslt[1] <= (float)conv_table[i][1]+0.25) &&
                    (prslt[1] >= (float)conv_table[i][1]-0.25)) &&
                   ((prslt[2] <= (float)conv_table[i][2]+0.25) &&
                    (prslt[2] >= (float)conv_table[i][2]-0.25)) &&
                   ((prslt[3] <= (float)conv_table[i][3]+0.25) &&
                    (prslt[3] >= (float)conv_table[i][3]-0.25)) )
               {
                  ret = i;
                  break;
               }
            }
         }
         else
         {
            printf("\n");
            printf("\nError reading channel, verify device present: %d\n",
            (int)owVerify(portnum, FALSE));
         }
      }
   }

   return ret;
}
Example #16
0
//----------------------------------------------------------------------
//  This is the Main routine for thermoms.
//
int main(int argc, char **argv)
{
   int Fahrenheit=FALSE,num,i,j;
   char str[800];
   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 > 3) || ((argc > 1) && (argv[1][0] == '?' || argv[1][1] == '?')))
      ExitProg("\nusage: thermoms 1wire_net_name </Fahrenheit>\n"
              "  - Thermochron configuration on the 1-Wire Net port\n"
              "  - 1wire_net_port required port name\n"
              "    example: \"COM1\" (Win32 DS2480),\"/dev/cua0\" \n"
              "    (Linux DS2480),\"{1,5}\" (Win32 TMEX)\n"
              "  - </Fahrenheit> optional Fahrenheit mode (default Celsius)\n"
              "  - version 2.00\n",1);

   // attempt to acquire the 1-Wire Net
   if((portnum = owAcquireEx(argv[1])) < 0)
   {
      OWERROR_DUMP(stdout);
      exit(1);
   }

   // success
   printf("Port opened: %s\n",argv[1]);

   //----------------------------------------
   // Introduction
   printf("\n/---------------------------------------------\n");
   printf("  Find and mission DS1921 Thermochron iButton(s)\n"
          "  Version 2.00\n\n");

   // check arguments
   Fahrenheit = FALSE;
   if (argc >= 3)
   {
      if ((argv[2][0] == '/') &&
           ((argv[2][1] == 'F') || (argv[2][1] == 'f')))
         Fahrenheit = TRUE;
   }

   // 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 mission each Thermochron
   for (i = 0; i < num; i++)
   {
      // set the serial number portion in the thermo state
      printf("\nRead status of Thermochron: ");
      for (j = 7; j >= 0; j--)
      {
         ThermoState.MissStat.serial_num[j] = ThermoSN[i][j];
         printf("%02X",ThermoSN[i][j]);
      }
      printf("\n");

      // read Thermochron state
      if (ReadThermoStatus(portnum,&ThermoSN[i][0],&ThermoState,stdout))
      {

         // display mission status
         InterpretStatus(&ThermoState.MissStat);
         MissionStatusToString(&ThermoState.MissStat, Fahrenheit, &str[0]);
         printf("\n%s\n",str);

         // ask user mission questions
         if (!InputMissionType(&ThermoState,Fahrenheit))
         {
            printf("Input abort\n");
            continue;
         }

    	 GAMEOVER();

         // run the script to display the thermochron
         if (MissionThermo(portnum,&ThermoSN[i][0],&ThermoState,stdout))
         {
            // read Thermochron state
            if (ReadThermoStatus(portnum,&ThermoSN[i][0],&ThermoState,stdout))
            {
               // display the new mission status
               InterpretStatus(&ThermoState.MissStat);
               MissionStatusToString(&ThermoState.MissStat, Fahrenheit, &str[0]);
               printf("\n%s\n",str);
            }
            else
               printf("ERROR reading Thermochon state\n");
         }
         else
            printf("ERROR, Thermochon missioning not complete\n");
      }
      else
         printf("ERROR reading Thermochon state\n");
   }

   // release the 1-Wire Net
   owRelease(portnum);
   printf("\nClosing port %s.\n", argv[1]);
   printf("End program normally\n");
   exit(0);

   return 0;
}
Example #17
0
/*
 * main for testing
 */
int main (int argc, char **argv)
{
    Bool success = true;
    UInt8 i;
    UInt8 x;
    SInt32 portNumber = 0;
    UInt8 numBatteryDevices;
    UInt8 numIODevices;
    UInt8 batteryDeviceArray[MAX_BATTERY_DEVICES][NUM_BYTES_IN_SERIAL_NUM];
    UInt8 ioDeviceArray[MAX_IO_DEVICES][NUM_BYTES_IN_SERIAL_NUM];
    UInt8 pageBuffer[DS2408_MAX_BYTES_IN_CHANNEL_ACCESS];
    SInt16 current;
    double temperature;
    UInt16 voltage;
    SInt16 offsetCalibration;

    setDebugPrintsOn();
    setProgressPrintsOn();

    if (argc == 2)
    {
        portNumber = oneWireStartBus (argv[1]);
    }
    else
    {
        portNumber = oneWireStartBus (ONEWIRE_PORT);
    }

    if (portNumber < 0)
    {
        printDebug ("Failed to acquire port.\n");
        success = false;
    }
    else
    {  
        numBatteryDevices = FindDevices (portNumber, &batteryDeviceArray[0], FAMILY_SBATTERY, MAX_BATTERY_DEVICES);
        numIODevices = FindDevices (portNumber, &ioDeviceArray[0], FAMILY_PIO, MAX_IO_DEVICES);

        if (numBatteryDevices == 0)
        {
            success = false;
            ASSERT_ALWAYS_STRING ("No battery monitoring devices found.\n");
        }
        else
        {
            printProgress ("Found %d battery monitoring devices.\n", numBatteryDevices);
            for (i = 0; (i < numBatteryDevices) && success; i++)
            {
                UInt32 longOne1 = 0xFFFFFF01;
                UInt32 longOne2 = 0xFFFFFF02;
                UInt16 capacity = 1000;                
                
                printProgress ("Writing time %lu and capacity %d.\n", longOne1, capacity);
                success = writeTimeCapacityDS2438 (portNumber, &batteryDeviceArray[i][0], &longOne1, &capacity, false);
                if (success)
                {
                    printProgress ("Writing something to DISC/EOC page.\n");
                    pageBuffer[0] = 0xFF;
                    pageBuffer[1] = 0xFF;
                    pageBuffer[2] = 0xFF;
                    pageBuffer[3] = 0xFF;
                    pageBuffer[4] = 0xFF;
                    pageBuffer[5] = 0xFF;
                    pageBuffer[6] = 0xFF;
                    pageBuffer[7] = 0xFF;
        
                    success = writeNVPageDS2438 (portNumber, &batteryDeviceArray[i][0], 2, &pageBuffer[0], DS2438_NUM_BYTES_IN_PAGE);
                    if (success)
                    {
                        printProgress ("Writing something to CCA and DCA registers.\n");
                        success = writeNVChargeDischargeDS2438 (portNumber, &batteryDeviceArray[i][0], &longOne1, &longOne2);
                        
                        if (success)
                        {
                            printProgress ("Writing something to user data pages.\n");
                            for (x = 0; (x < DS2438_NUM_USER_DATA_PAGES) && success; x++)
                            {
                                pageBuffer[0] = x + 1;
                                pageBuffer[1] = x + 2;
                                pageBuffer[2] = x + 3;
                                pageBuffer[3] = x + 4;
                                pageBuffer[4] = x + 5;
                                pageBuffer[5] = x + 6;
                                pageBuffer[6] = x + 7;
                                pageBuffer[7] = x + 8;
                                success = writeNVUserDataDS2438 (portNumber, &batteryDeviceArray[i][0], x, &pageBuffer[0], (x + 1) * 2);
                            }
                            
                            if (success)
                            {
#if 0
                                printProgress ("Calibrating: MAKE SURE NO CURRENT GOING THROUGH RSENS!\n");
                                success = performCalDS2438 (portNumber, &batteryDeviceArray[i][0], &offsetCalibration);
                                printProgress ("New offset %d.\n", offsetCalibration);
#endif                                
                            }
                        }
                    }
                }
            }
            /* Check that the configurations are setup correctly and if
             * not write in the values we need and flush them to NV so
             * that they will be correct next time */
            for (i = 0; (i < numBatteryDevices) && success; i++)
            {
                UInt8 config;
                
                success = readNVConfigThresholdDS2438 (portNumber, &batteryDeviceArray[i][0], &config, PNULL);
                if (success &&
                    ((config | DS2438_IAD_IS_ENABLED) == 0 ||
                     (config | DS2438_CA_IS_ENABLED) == 0 ||
                     (config | DS2438_EE_IS_ENABLED) == 0))
                {
                    config = DS2438_IAD_IS_ENABLED | DS2438_CA_IS_ENABLED | DS2438_EE_IS_ENABLED;
                    success = writeNVConfigThresholdDS2438 (portNumber, &batteryDeviceArray[i][0], &config, PNULL);                        
                }
            }
        } /* numBatteryDevices > 0 */
        
        if (numIODevices == 0)
        {
            success = false;
            ASSERT_ALWAYS_STRING ("No IO devices found.\n");
        }
        else
        {
            printProgress ("Found %d IO devices.\n", numIODevices);
            for (i = 0; (i < numIODevices) && success; i++)
            {              
                UInt8 controlByte = 0;
                
                printProgress ("Disable test mode.\n");
                success = disableTestModeDS2408 (portNumber, &ioDeviceArray[i][0]);
                if (success)
                {
                    printProgress ("Reset activity latches.\n");
                    success = resetActivityLatchesDS2408 (portNumber, &ioDeviceArray[i][0]);
                    if (success)
                    {
                        controlByte &= ~(DS2408_DEVICE_HAS_POWER_ON_RESET | DS2408_RSTZ_IS_STROBE);
                        controlByte |= (DS2408_SEARCH_IS_AND | DS2408_SEARCH_IS_ACTIVITY_LATCHED);
                        printProgress ("Setup the control registers.\n");
                        success = writeControlRegisterDS2408 (portNumber, &ioDeviceArray[i][0], controlByte);
                        if (success)
                        {
                            printProgress ("Setup the conditional search channel selection mask registers.\n");
                            success = writeCSChannelSelectionMaskRegisterDS2408 (portNumber, &ioDeviceArray[i][0], 0x18);                        
                            if (success)
                            {
                                printProgress ("Setup the conditional search channel priority selection registers.\n");
                                success = writeCSChannelPolaritySelectionRegisterDS2408 (portNumber, &ioDeviceArray[i][0], 0x28);                        
                                if (success)
                                {
                                    UInt8 outputByte = 0x80;
                                    
                                    printProgress ("Set P7 of each device to be high.\n");
                                    success = channelAccessWriteDS2408 (portNumber, &ioDeviceArray[i][0], &outputByte);                        
                                }
                            }
                        }
                    }
                }
            }
        }  /* numIODevices > 0 */
                
        if (success)
        {
            do
            {
                printProgress("---- IO Devices ---- \n");
                for (i = 0; (i < numIODevices) && success; i++)
                {
                    printProgress ("Device %d, address %.2x:%.2x:%.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n", i, ioDeviceArray[i][0], ioDeviceArray[i][1], ioDeviceArray[i][2], ioDeviceArray[i][3], ioDeviceArray[i][4], ioDeviceArray[i][5], ioDeviceArray[i][6], ioDeviceArray[i][7]);
                    success = readControlRegisterDS2408 (portNumber, &ioDeviceArray[i][0], &pageBuffer[0]);
                    if (success)
                    {
                        printProgress (" status reg: 0x%.2x", pageBuffer[0]);
                        success = readPIOLogicStateDS2408 (portNumber, &ioDeviceArray[i][0], &pageBuffer[0]);
                        if (success)
                        {
                            printProgress (", IO reg: 0x%.2x", pageBuffer[0]);
                            success = readPIOOutputLatchStateRegisterDS2408 (portNumber, &ioDeviceArray[i][0], &pageBuffer[0]);
                            if (success)
                            {
                                UInt8 bytesRead;
                                
                                printProgress (", IO O/P latch reg: 0x%.2x", pageBuffer[0]);
                                bytesRead = channelAccessReadDS2408 (portNumber, &ioDeviceArray[i][0], &pageBuffer[0], DS2408_MAX_BYTES_IN_CHANNEL_ACCESS);                                    
                                if (bytesRead > 0)
                                {
                                    printProgress (", IO %d times: ", bytesRead);
                                    for (x = 0; x < bytesRead; x++)
                                    {
                                        printProgress (" 0x%.2x", pageBuffer[x]);                                            
                                    }
                                    success = readCSChannelSelectionMaskRegisterDS2408 (portNumber, &ioDeviceArray[i][0], &pageBuffer[0]);
                                    if (success)
                                    {
                                        printProgress (", CS select reg: 0x%.2x", pageBuffer[0]);
                                        success = readCSChannelPolaritySelectionRegisterDS2408 (portNumber, &ioDeviceArray[i][0], &pageBuffer[0]);
                                        if (success)
                                        {
                                            printProgress (", CS polarity reg: 0x%.2x.\n", pageBuffer[0]);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    printProgress("\n");
                } /* IO Devices for loop */
                
                printProgress("---- Battery Devices ---- \n");
                for (i = 0; (i < numBatteryDevices) && success; i++)
                {
                    printProgress ("Device %d, address %.2x:%.2x:%.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n", i, batteryDeviceArray[i][0], batteryDeviceArray[i][1], batteryDeviceArray[i][2], batteryDeviceArray[i][3], batteryDeviceArray[i][4], batteryDeviceArray[i][5], batteryDeviceArray[i][6], batteryDeviceArray[i][7]);
                    success = readVddDS2438 (portNumber, &batteryDeviceArray[i][0], &voltage);
                    if (success)
                    {
                        printProgress (" Vdd was:  %d mV\n", voltage);
                        success = readVadDS2438 (portNumber, &batteryDeviceArray[i][0], &voltage);
                        if (success)
                        {
                            printProgress (" Vad was:  %d mV\n", voltage);
                            success = readTemperatureDS2438 (portNumber, &batteryDeviceArray[i][0], &temperature);
                            if (success)
                            {
                                printProgress (" Temperature was:  %2.2f C\n", temperature);
                                success = readCurrentDS2438 (portNumber, &batteryDeviceArray[i][0], &current);
                                if (success)
                                {
                                    printProgress (" Current was:  %d ma (-ve means discharge)\n", current);
                                    success = readBatteryDS2438 (portNumber, &batteryDeviceArray[i][0], &voltage, &current);
                                    if (success)
                                    {
                                        printProgress ("Battery was %2.2f V, %1.3f A, %2.3f W\n", (double) voltage/1000, (double) current/1000, ((double) (voltage *  current * -1)) / 1000000);
                                    }
                                }
                            }
                            for (x = 0; (x < 8) && success; x++)
                            {
                                success = readNVPageDS2438 (portNumber, &batteryDeviceArray[i][0], x, &pageBuffer[0]);
                                printProgress ("Page %d contents: %2x:%2x:%2x:%2x:%2x:%2x:%2x:%2x\n", x, pageBuffer[0], pageBuffer[1], pageBuffer[2], pageBuffer[3], pageBuffer[4], pageBuffer[5], pageBuffer[6], pageBuffer[7]);
                            }
                        }
                    }
                    
                    /* Check other data */
                    if (success)
                    {
                        UInt32 elapsedTime;
                        UInt16 remainingCapacity;
                        UInt32 piOff;
                        UInt32 chargingStopped;
                        UInt32 accumulatedCharge;
                        UInt32 accumulatedDischarge;
                        
                        success = readTimeCapacityCalDS2438 (portNumber, &batteryDeviceArray[i][0], &elapsedTime, &remainingCapacity, &offsetCalibration, false);
                        if (success)
                        {
                            printProgress ("Elapsed time: %lu secs, remaining capacity: %u mAHr, cal. offset: %d\n", elapsedTime, remainingCapacity, offsetCalibration);
                            success = readTimePiOffChargingStoppedDS2438 (portNumber, &batteryDeviceArray[i][0], &piOff, &chargingStopped);
                            if (success)
                            {
                                printProgress ("Pi last switched off: %lu secs, charging last stopped: %lu secs\n", piOff, chargingStopped);                                
                                success = readNVChargeDischargeDS2438 (portNumber, &batteryDeviceArray[i][0], &accumulatedCharge, &accumulatedDischarge);
                                if (success)
                                {
                                    printProgress ("Accumulated charge: %lu mAHr, accumulated discharge %lu mAHr\n", accumulatedCharge, accumulatedDischarge);
                                    for (x = 0; (x < DS2438_NUM_USER_DATA_PAGES) && success; x++)
                                    {
                                        success = readNVUserDataDS2438 (portNumber, &batteryDeviceArray[i][0], x, &pageBuffer[0]);
                                        if (success)
                                        {
                                            printProgress ("UserData %d contents: %2x:%2x:%2x:%2x:%2x:%2x:%2x:%2x\n", x, pageBuffer[0], pageBuffer[1], pageBuffer[2], pageBuffer[3], pageBuffer[4], pageBuffer[5], pageBuffer[6], pageBuffer[7]);
                                        }
                                    }
                                }
                            }                            
                        }
                    }                    
                    printProgress("\n");
                } /* Battery devices for loop */
            } while (!key_abort() && success);
        }
        
        if (!success)
        {
            printDebug ("Either something returned false or at least one IO device and at least one Battery device were not found.\n");
        }
    
        oneWireStopBus (portNumber);
        printProgress ("Port released.\n");    
    }

    return success;
}
Example #18
0
//----------------------------------------------------------------------
//  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;
}
Example #19
0
//--------------------------------------------------------------------------
// This is the begining of the program that tests the commands for the
// DS2405
//
int main(int argc, char **argv)
{
   uchar SwitchSN[MAXDEVICES][8];  //the serial numbers for the devices
   short i,j;                      //loop counters
   int num;                        //for the number of DS2405s
   int lev;
   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,5}\" (Win32 TMEX)\n");
      exit(1);
   }

   // attempt to acquire the 1-Wire Net
   if((portnum = owAcquireEx(argv[1])) < 0)
   {
      OWERROR_DUMP(stdout);
      exit(1);
   }

   // this is to get the number of the devices and the serial numbers
	num = FindDevices(portnum, &SwitchSN[0], SWITCH_FAMILY, MAXDEVICES);

   for( i=0; i<num; i++)
   {
      if(SetSwitch05(portnum, SwitchSN[i], 1))
      {
         printf("Device ");

         for(j=7; j>=0; j--)
            printf("%02X", SwitchSN[i][j]);

         printf(" is active\n");
      }
      else
         printf("Error setting device on\n");

      if(ReadSwitch05(portnum, SwitchSN[i], &lev))
      {
         printf("Device ");

         for(j=7; j>=0; j--)
            printf("%02X", SwitchSN[i][j]);

         if(lev)
            printf(" is active and is high.\n");
         else
            printf(" is active and is low.\n");
      }
      else
         printf("Error reading active device\n");

      if(SetSwitch05(portnum, SwitchSN[i], 0))
      {
         printf("Device ");

         for(j=7; j>=0; j--)
            printf("%02X", SwitchSN[i][j]);

         printf(" is not active\n");
      }
      else
         printf("Error setting device off\n");

      if(!ReadSwitch05(portnum, SwitchSN[i], &lev))
      {
         printf("Device ");

         for(j=7; j>=0; j--)
            printf("%02X", SwitchSN[i][j]);

         if(lev)
            printf(" is not active and is high.\n");
         else
            printf(" is not active and is low.\n");
      }
      else
         printf("Error reading nonactive device\n");
   }

   if(num == 0)
      printf("DS2405 not found on the 1-Wire Network.\n");

   owRelease(portnum);
   printf("Closing port %s.\n", argv[1]);
   exit(0);

   return 0;
}