Esempio n. 1
0
//----------------------------------------------------------------------
// Search for devices
//
// 'portnum'  - number 0 to MAX_PORTNUM-1.  This number is provided to
//              indicate the symbolic port number.
// 'FamilySN' - an array of all the serial numbers with the matching
//              family code
// 'family_code' - the family code of the devices to search for on the
//                 1-Wire Net
// 'MAXDEVICES'  - the maximum number of devices to look for with the
//                 family code passed.
//
// Returns: TRUE(1)  success, device type found
//          FALSE(0) device not found
//
SMALLINT FindDevices(int portnum, uchar FamilySN[][8], SMALLINT family_code, int MAXDEVICES)
{
   int NumDevices=0;

   // find the devices
   // set the search to first find that family code
   owFamilySearchSetup(portnum,family_code);

   // loop to find all of the devices up to MAXDEVICES
   NumDevices = 0;
   do
   {
      // perform the search
      if (!owNext(portnum,TRUE, FALSE))
         break;
         
      owSerialNum(portnum,FamilySN[NumDevices], TRUE);
      if ((FamilySN[NumDevices][0] & 0x7F) == (family_code & 0x7F))
      {
         NumDevices++;
      }
   }
   while (NumDevices < (MAXDEVICES - 1));

   // check if not at least 1 device
   return NumDevices;
}
Esempio n. 2
0
File: ownet.c Progetto: ckgt/bladeRF
//--------------------------------------------------------------------------
// The 'owFirst' finds the first device on the 1-Wire Net  This function
// contains one parameter 'alarm_only'.  When
// 'alarm_only' is TRUE (1) the find alarm command 0xEC is
// sent instead of the normal search command 0xF0.
// Using the find alarm command 0xEC will limit the search to only
// 1-Wire devices that are in an 'alarm' state.
//
// 'portnum'    - number 0 to MAX_PORTNUM-1.  This number is provided to
//                indicate the symbolic port number.
// 'do_reset'   - TRUE (1) perform reset before search, FALSE (0) do not
//                perform reset before search.
// 'alarm_only' - TRUE (1) the find alarm command 0xEC is
//                sent instead of the normal search command 0xF0
//
// Returns:   TRUE (1) : when a 1-Wire device was found and it's
//                        Serial Number placed in the global SerialNum[portnum]
//            FALSE (0): There are no devices on the 1-Wire Net.
//
SMALLINT owFirst(int portnum, SMALLINT do_reset, SMALLINT alarm_only)
{
   // reset the search state
   LastDiscrepancy[portnum] = 0;
   LastDevice[portnum] = FALSE;
   LastFamilyDiscrepancy[portnum] = 0;

   return owNext(portnum,do_reset,alarm_only);
}
Esempio n. 3
0
//----------------------------------------------------------------------
// SUBROUTINE - owBranchNext
//
// This routine is used like owFirst but for devices on a branch.
//
// 'portnum'    - number 0 to MAX_PORTNUM-1.  This number is provided to
//                indicate the symbolic port number.
// 'BrSN'       - This is the DS2409 device branch
// 'AlarmD'     - True or False, to do Alarm search or false for regular search
// 'NextMain'   - True then search main branch, False search Aux. branch
//
// Returns:   TRUE (1) : when a 1-Wire device was found and it's
//                        Serial Number placed in the global SerialNum
//            FALSE (0): There are no devices on the 1-Wire Net.
//
int owBranchNext(int portnum, uchar BrSN[8], int AlarmD, int NextMain)
{
   int smart_main = 4;
   int smart_aux = 2;
   int numextra = 2;
   uchar extra[3];

   if(NextMain)
   {
      if(SetSwitch1F(portnum, &BrSN[0], smart_main, numextra, extra, TRUE))
         return owNext(portnum,FALSE, AlarmD);
   }
   else
   {
      if(SetSwitch1F(portnum, &BrSN[0], smart_aux, numextra, extra, TRUE))
         return owNext(portnum,FALSE, AlarmD);
   }

   return FALSE;
}
Esempio n. 4
0
//--------------------------------------------------------------------------
// The 'owFirst' finds the first device on the 1-Wire Net  This function
// contains one parameter 'alarm_only'.  When
// 'alarm_only' is TRUE (1) the find alarm command 0xEC is
// sent instead of the normal search command 0xF0.
// Using the find alarm command 0xEC will limit the search to only
// 1-Wire devices that are in an 'alarm' state.
//
// 'portnum'    - number 0 to MAX_PORTNUM-1.  This number is provided to
//                indicate the symbolic port number.
// 'do_reset'   - TRUE (1) perform reset before search, FALSE (0) do not
//                perform reset before search.
// 'alarm_only' - TRUE (1) the find alarm command 0xEC is
//                sent instead of the normal search command 0xF0
//
// Returns:   TRUE (1) : when a 1-Wire device was found and it's
//                        Serial Number placed in the global SerialNum[portnum]
//            FALSE (0): There are no devices on the 1-Wire Net.
//
BYTE owFirst(BYTE portnum, BYTE do_reset, BYTE alarm_only)
{
   owSetCurrentPort(portnum);
   
   // reset the search state
   owNetCurrent.LastDiscrepancy       = 0;
   owNetCurrent.LastDevice            = FALSE;
   owNetCurrent.LastFamilyDiscrepancy = 0;

   return owNext(owCurrentPortnum, do_reset, alarm_only);
}
Esempio n. 5
0
//----------------------------------------------------------------------
//  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
  }
}
Esempio n. 6
0
//---------------------------------------------------------------------
// Finds new SHA iButtons on the given port.  Uses 'triple-buffer'
// technique to insure it only finds 'new' buttons.
//
// 'portnum'     - number 0 to MAX_PORTNUM-1.  This number is provided to
//                 indicate the symbolic port number.
// 'devAN'       - pointer to buffer for device address
// 'resetList'   - if TRUE, final buffer is cleared.
//
// Returns: TRUE, found a new SHA iButton.
//          FALSE, no new buttons are present.
//
SMALLINT FindNewSHA(int portnum, uchar* devAN, SMALLINT resetList)
{
   uchar ROM[8];
   uchar tempList[MAX_SHA_IBUTTONS] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
                                       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
   int tempIndex = 0, i;
   SMALLINT hasDevices = TRUE, completeList = FALSE;

   // force back to standard speed
   if(MODE_NORMAL != owSpeed(portnum,MODE_NORMAL))
   {
      OWERROR(OWERROR_LEVEL_FAILED);
      return FALSE;
   }

   in_overdrive[portnum&0x0FF] = FALSE;

   // get first device in list with the specified family
   if(needsFirst || resetList)
   {
      hasDevices = owFirst(portnum, TRUE, FALSE);
      completeList = TRUE;
      if(resetList)
         listIndex = 0;
   }
   else
   {
      hasDevices = owNext(portnum, TRUE, FALSE);
   }

   if(hasDevices)
   {
      do
      {
         // verify correct device type
         owSerialNum(portnum, ROM, TRUE);
         tempList[tempIndex++] = ROM[7];

         // compare crc to complete list of ROMs
         for(i=0; i<listIndex; i++)
         {
            if(ROM[7] == ListOfKnownSHA[portnum&0x0FF][i])
               break;
         }

         // found no match;
         if(i==listIndex)
         {
            // check if correct type and not copr_rom
            if ((SHA_FAMILY_CODE   == (ROM[0] & 0x7F)) ||
                (SHA33_FAMILY_CODE == (ROM[0] & 0x7F)))
            {
               // save the ROM to the return buffer
               owSerialNum(portnum,devAN,TRUE);
               ListOfKnownSHA[portnum&0x0FF][listIndex++] = devAN[7];
               return TRUE;
            }
         }
      }
      while(owNext(portnum, TRUE, FALSE));
   }

   // depleted the list, start over from beginning next time
   needsFirst = TRUE;

   if(completeList)
   {
      // known list is triple-buffered, listBuffer is intermediate
      // buffer.  tempList is the immediate buffer, while
      // ListOfKnownSHA is the final buffer.
      if( (memcmp(tempList, listBuffer[portnum&0x0FF], MAX_SHA_IBUTTONS)==0) &&
          tempIndex == indexBuffer )
      {
         memcpy(ListOfKnownSHA[portnum&0x0FF], tempList, MAX_SHA_IBUTTONS);
         listIndex = tempIndex;
      }
      else
      {
         memcpy(listBuffer[portnum&0x0FF], tempList, MAX_SHA_IBUTTONS);
         indexBuffer = tempIndex;
      }

   }
   return FALSE;
}
Esempio n. 7
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;
}
Esempio n. 8
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;
}
Esempio n. 9
0
//----------------------------------------------------------------------
//  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
  }
}
Esempio n. 10
0
//----------------------------------------------------------------------
//  Main for tstfind
//
int main(int argc, char **argv)
{
   int rslt,cnt;
   int portnum=0;
   uchar SNum[8];

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

   //----------------------------------------
   // Introduction
   printf("\n/---------------------------------------------\n");
   printf("  Loop to find all iButton on 1-Wire Net.\n\n");

   do
   {
      printf("-------------------- Start of search\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);

         // print the Serial Number of the device just found
         owSerialNum(portnum,&SNum[0],TRUE);
         PrintSerialNum(&SNum[0]);
         printf("\n");

         // find the next device
         rslt = owNext(portnum, TRUE, FALSE);
      }
      printf("-------------------- End of search\n\n");

   }
   while (!key_abort());

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

   return 0;
}
Esempio n. 11
0
int main(int argc, char **argv)
{
   int len, addr, page, answer, i;
   int done      = FALSE;
   SMALLINT  bank = 1;
   uchar     data[552];
   int portnum = 0;
   uchar AllSN[MAXDEVICES][8];
   int NumDevices;
   int owd;
   char msg[132];


      // 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\n",msg);
      return 0;
   }

   printf("\n1-Wire Memory utility console application Version 0.01\n");

   if((portnum = owAcquireEx(argv[1])) < 0)
   {
      OWERROR_DUMP(stdout);
      return 0;
   }
   else
   {
      // loop to do menu
      do
      {

         // Main menu
         switch (menuSelect(MAIN_MENU,&AllSN[0][0]))
         {

            case MAIN_SELECT_DEVICE :

               // find all parts
               // loop to find all of the devices up to MAXDEVICES
               NumDevices = 0;
               do
               {
                  // perform the search
                  if (!owNext(portnum,TRUE, FALSE))
                     break;

                  owSerialNum(portnum,AllSN[NumDevices], TRUE);
                  NumDevices++;
               }
               while (NumDevices < (MAXDEVICES - 1));

               /* for test devices without a serial number
               if(NumDevices == 0)
               {
                  for(i=0;i<8;i++)
                     AllSN[0][i] = 0x00;
                  NumDevices++;
               }*/

               // select a device
               owd = selectDevice(NumDevices,&AllSN[0]);

               // display device info
               printDeviceInfo(portnum,&AllSN[owd][0]);

               // select a bank
               bank = selectBank(bank, &AllSN[owd][0]);

               if((AllSN[owd][0] == 0x33) || (AllSN[owd][0] == 0xB3))
                  bank = optionSHAEE(bank,portnum,&AllSN[owd][0]);

               // display bank information
               displayBankInformation(bank,portnum,&AllSN[owd][0]);

               // loop on bank menu
               do
               {
                  switch (menuSelect(BANK_MENU,&AllSN[owd][0]))
                  {

                     case BANK_INFO :
                        // display bank information
                        displayBankInformation(bank,portnum,&AllSN[owd][0]);
                        break;

                     case BANK_READ_BLOCK :
                        // read a block
                        printf("Enter the address to start reading: ");
                        addr = getNumber(0, (owGetSize(bank,&AllSN[owd][0])-1));
                        printf("\n");

                        printf("Enter the length of data to read: ");
                        len = getNumber(0, owGetSize(bank, &AllSN[owd][0]));
                        printf("\n");

                        if(!dumpBankBlock(bank,portnum,&AllSN[owd][0],addr,len))
                           OWERROR_DUMP(stderr);
                        break;

                     case BANK_READ_PAGE :
                        printf("Enter the page number to read:  ");

                        page = getNumber(0, (owGetNumberPages(bank,&AllSN[owd][0])-1));

                        printf("\n");

                        if(!dumpBankPage(bank,portnum,&AllSN[owd][0],page))
                           OWERROR_DUMP(stderr);

                        break;

                     case BANK_READ_UDP :
                        printf("Enter the page number to read: ");

                        page = getNumber(0, (owGetNumberPages(bank,&AllSN[owd][0])-1));

                        printf("\n");

                        if(!dumpBankPagePacket(bank,portnum,&AllSN[owd][0],page))
                           OWERROR_DUMP(stderr);
                        break;

                     case BANK_WRITE_BLOCK :
                        // write a block
                        printf("Enter the address to start writing: ");

                        addr = getNumber(0, (owGetSize(bank,&AllSN[owd][0])-1));

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

                        if(!bankWriteBlock(bank,portnum,&AllSN[owd][0],addr,data,len))
                        {
                           OWERROR_DUMP(stderr);
                           break;
                        }

                        if(owCanRedirectPage(bank,&AllSN[owd][0]))
                        {
                           printf("Enter if you want to redirect page (0 no, 1 yes): ");

                           answer = getNumber(0,1);

                           if(answer)
                           {
                              printf("What page would you like to redirect:");

                              page = getNumber(0,255);

                              printf("Where would you like to redirect:");

                              addr = getNumber(0,255);

                              if(!redirectPage(bank,portnum,&AllSN[owd][0],page,addr))
                              {
                                 OWERROR_DUMP(stderr);
                                 break;
                              }
                           }
                        }

                        if(owCanLockPage(bank,&AllSN[owd][0]))
                        {
                           printf("Enter if you want to lock page (0 no, 1 yes):");

                           answer = getNumber(0,1);

                           if(answer)
                           {
                              printf("What page would you like to lock?");

                              page = getNumber(0,255);

                              if(!lockPage(bank,portnum,&AllSN[owd][0],page))
                              {
                                 OWERROR_DUMP(stderr);
                                 break;
                              }
                           }
                        }

                        if(owCanLockRedirectPage(bank,&AllSN[owd][0]))
                        {
                           printf("Enter if you want to lock redirected page (0 no, 1 yes):");

                           answer = getNumber(0,1);

                           if(answer)
                           {
                              printf("Which redirected page do you want to lock:");

                              page = getNumber(0,255);

                              if(!lockRedirectPage(bank,portnum,&AllSN[owd][0],page))
                              {
                                 OWERROR_DUMP(stderr);
                                 break;
                              }
                           }
                        }
                        break;

                     case BANK_WRITE_UDP :
                        printf("Enter the page number to write a UDP to: ");

                        page = getNumber(0, (owGetNumberPages(bank,&AllSN[owd][0])-1));

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

                        if(!bankWritePacket(bank,portnum,&AllSN[owd][0],page,data,len))
                           OWERROR_DUMP(stderr);
                        break;

                     case BANK_BM_READ_PASS:
                        printf("Enter the 8 byte read only password if less 0x00 will be filled in.");

            				if(menuSelect(ENTRY_MENU,&AllSN[owd][0]) == MODE_TEXT)
            					len = getData(data,8,MODE_TEXT);
            				else
            					len = getData(data,8,MODE_HEX);

                        if(len != 8)
                        {
                           for(i=len;i<8;i++)
                              data[i] = 0x00;
                        }

                        if(!owSetBMReadOnlyPassword(portnum,&AllSN[owd][0],data))
                           OWERROR_DUMP(stderr);

                        break;

                     case BANK_BM_RW_PASS:
                        printf("Enter the 8 byte read/write password if less 0x00 will be filled in.");

            				if(menuSelect(ENTRY_MENU,&AllSN[owd][0]) == MODE_TEXT)
            					len = getData(data,8,MODE_TEXT);
            				else
            					len = getData(data,8,MODE_HEX);

                        if(len != 8)
                        {
                           for(i=len;i<8;i++)
                              data[i] = 0x00;
                        }

                        if(!owSetBMReadWritePassword(portnum,&AllSN[owd][0],data))
                           OWERROR_DUMP(stderr);

                        break;

                     case BANK_READ_PASS:
                        printf("Enter the 8 byte read only password if less 0x00 will be filled in.");

            				if(menuSelect(ENTRY_MENU,&AllSN[owd][0]) == MODE_TEXT)
            					len = getData(data,8,MODE_TEXT);
            				else
            					len = getData(data,8,MODE_HEX);

                        if(len != 8)
                        {
                           for(i=len;i<8;i++)
                              data[i] = 0x00;
                        }

                        if(!owSetReadOnlyPassword(portnum,&AllSN[owd][0],data))
                           OWERROR_DUMP(stderr);

                        break;

                     case BANK_RW_PASS:
                        printf("Enter the 8 byte read/write password if less 0x00 will be filled in.");

            				if(menuSelect(ENTRY_MENU,&AllSN[owd][0]) == MODE_TEXT)
            					len = getData(data,8,MODE_TEXT);
            				else
            					len = getData(data,8,MODE_HEX);

                        if(len != 8)
                        {
                           for(i=len;i<8;i++)
                              data[i] = 0x00;
                        }

                        if(!owSetReadWritePassword(portnum,&AllSN[owd][0],data))
                           OWERROR_DUMP(stderr);

                        break;

                     case BANK_ENABLE_PASS:
                        if(!owSetPasswordMode(portnum,&AllSN[owd][0],ENABLE_PSW))
                           OWERROR_DUMP(stderr);
                        break;

                     case BANK_DISABLE_PASS:
                        if(!owSetPasswordMode(portnum,&AllSN[owd][0],DISABLE_PSW))
                           OWERROR_DUMP(stderr);
                        break;

                     case BANK_NEW_BANK :
                        // select a bank
                        bank = selectBank(bank,&AllSN[owd][0]);

                        if((AllSN[owd][0] == 0x33) || (AllSN[owd][0] == 0xB3))
                           bank = optionSHAEE(bank,portnum,&AllSN[owd][0]);

                        // display bank information
                        displayBankInformation(bank,portnum,&AllSN[owd][0]);
                        break;

                     case BANK_MAIN_MENU :
                        done = TRUE;
                        break;
                  }
               }
               while (!done);

               done = FALSE;
               break;

            case MAIN_QUIT :
               done = TRUE;
               break;

         }  // Main menu switch
      }
      while (!done);  // loop to do menu

      owRelease(portnum);
   }  // else for owAcquire

   return 1;
}