Exemple #1
0
//---------------------------------------------------------------------------
// Attempt to acquire a 1-Wire net using a USB port and a DS2490 based
// adapter.
//
// 'portnum'    - number 0 to MAX_PORTNUM-1.  This number is provided to
//                indicate the symbolic port number.
// 'port_zstr'  - zero terminated port name.  For this platform
//                use format 'DS2490-X' where X is the port number.
//
// Returns: TRUE - success, USB port opened
//
SMALLINT owAcquire(int portnum, char *port_zstr)
{
	int retportnum = 0;
	retportnum = owAcquireEx(port_zstr);
	if ((retportnum < 0) || (retportnum != portnum))
	{
		// Failure from owAcquireEx or from not matching port numbers.
		return FALSE;
	}
	return TRUE;
}
Exemple #2
0
int main(void) {

	uchar owAddrBytes[8];
	uchar writeBuffer[] = {0x64, 0xEE, 0x00, 0x00, 0x00, 0x02, 0x03};

	portNum = 0;
	strcpy(portName,"DS2490-1");
	strcpy(serial, "FA00000001743763");

	portNum = owAcquireEx(portName);
	if(portNum <= 0 ) {
		printf("Error acquiring 1-wire USB device\n");
		return 1;
	}

	// Convert string-based serial to owAddress
	if(!checkSerial(serial, owAddrBytes)) {
		owRelease(portNum);
		return 1;
	}

	// DO STUFF HERE

	owSerialNum(portNum, owAddrBytes, FALSE);

	// 1) Test Maxq Read status
	testMaxQReadStatus(portNum, owAddrBytes);

	// 2) See what's in the command buffer initially
	testReadCmdBuffer(portNum, owAddrBytes, 7);

	// 3) Write something to the command buffer
	testWriteCmdBufferExStart(portNum, owAddrBytes, writeBuffer, 7);

	// 4) Test Maxq Read status
	testMaxQReadStatus(portNum, owAddrBytes);

	// 5) Read back what we wrote
	testReadCmdBuffer(portNum, owAddrBytes, 7);

	// Notice that the write succeeds but the release sequence response fails.

	owRelease(portNum);

	printf("Finished Successfully\n");
	return 0;
}
Exemple #3
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;
}
Exemple #4
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;
}
Exemple #5
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;
}
Exemple #6
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;
}
Exemple #7
0
int main(int argc, char** argv)
{
   int i = 0;
   SHACopr copr;
   SHAUser user;
   FileEntry fe = {"COPR",0};
   uchar *authSecret;
   int authlen;
   char test[2] = {'y',0};
   long balance;

   copr.portnum = 0;
   user.portnum = 0;

   puts("\nStarting SHA initrov Application\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);
   }

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

#ifdef COPRVM
   if(!GetCoprVM(&copr, &fe))
      exit(1);
#else
   puts("\nPlease place coprocessor token on the 1-Wire bus.\n");

   while(!FindCoprSHA(&copr, &fe))
   {
      if(owHasErrors())
         msDelay(10);
   }

   printf("Found device: ");
   PrintSerialNum(copr.devAN);
   puts("\n");
#endif

   authlen = GetSecret("System Authentication Secret", &authSecret);

   EnterString("Reformat the secret for DS1961S compatibility", test, 1, 1);
   if(test[0] == 'y')
   {
      ReformatSecretFor1961S(authSecret, authlen);
      PrintHex(authSecret, authlen);
      printf("\n");
      copr.ds1961Scompatible = 0x55;
   }

   puts("\nPlease place user token on the 1-Wire bus.\n");
   do
   {
      while(!FindNewSHA(user.portnum, user.devAN, (i==0)))
      {
         if(owHasErrors())
         {  
            OWERROR_DUMP(stdout);
            msDelay(10);
         }
      }
      i++;
   }
   while(user.devAN[7]==copr.devAN[7]);
   // just check the crc of the two devices

   balance = 100;
   EnterNum("\nInitial Balance in Cents?\n", 5, &balance, 0, 0xFFFFF);

   printf("Installing Service Data on device: ");
   PrintSerialNum(user.devAN);
   puts("\n");
   if(InstallServiceData(&copr, &user, authSecret, authlen, (int)balance))
   {
      puts("User token successfully set up");
   }
   else
   {
      puts("User token setup failed");
      OWERROR_DUMP(stdout);
   }

   // and we're done
   owRelease(copr.portnum);

   // program is about to exit, but we may as well free these
   // up anyways...
   free(authSecret);

   return 0;
}
Exemple #8
0
//----------------------------------------------------------------------
//  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;
}
Exemple #9
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;
}
Exemple #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;
}
Exemple #11
0
int main(int argc, char** argv)
{
   FileEntry fe;
   int len;
   int i;
   uchar authSecret[47];
   int authlen = 21;
   uchar signSecret[11] = {(uchar)'s',(uchar)'i',(uchar)'g',(uchar)'n',
                           (uchar)' ',(uchar)'s',(uchar)'e',(uchar)'c',
                           (uchar)'r',(uchar)'e',(uchar)'t'};
   int signlen = 11;
   int ischars;


   SHACopr copr;
   SHAUser user;

   //could be different ports.
   copr.portnum = 0;
   user.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);
   }

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

   user.portnum = copr.portnum;

   // MANUALLY SETTING DATA FOR COPROCESSOR
   memcpy(copr.serviceFilename, "DLSM", 4);
   copr.serviceFilename[4] = (uchar) 102;
   copr.signPageNumber     = (uchar) 8;
   copr.authPageNumber     = (uchar) 7;
   copr.wspcPageNumber     = (uchar) 9;
   copr.versionNumber      = (uchar) 1;
   memcpy(copr.bindCode, "bindcde", 7);
   for(i=0;i<8;i++)
   {
      memcpy(&copr.bindData[i*4], "bind", 4);
   }
   copr.encCode           = 0x01;
   copr.ds1961Scompatible = 0x01;

   // Prompt for password
   printf("Enter up to 47 bytes of the Authentication Secret.\n");
   printf("  Data Entry Mode\n");
   printf("  (0) Text (single line)\n");
   printf("  (1) Hex (XX XX XX XX ...)\n");
   len = getData(authSecret,47,getNumber(0,1));
   // padd the data with spaces or 0's depending on type
   if(len < 47)
   {
      for(i = len; i < 47; i++)
         authSecret[i] = 0x00;
   }

   ReformatSecretFor1961S(authSecret, authlen);
   copr.ds1961Scompatible = 0x55;
   InstallAuthSecretVM(&copr, authSecret, authlen);
   InstallSignSecretVM(&copr, signSecret, signlen);

   puts("\nStarting SHA Software Authentication\n");
   puts("\nPlease place token on the 1-Wire bus.\n");

   memcpy(fe.Name, "DLSM", 4);
   fe.Ext = 102;

   for(;;)
   {
      if(FindUserSA(&user,&fe,FALSE))
      {
         if(VerifyUser(&copr, &user, TRUE))
         {
            PrintSerialNum(&user.devAN[0]);
            printf(", user data = ");
            // print the user data
            ischars = TRUE;
            for(i=0;i<7;i++)
            {
               if ((user.accountFile[i+22] < 0x20) ||
                   (user.accountFile[i+22] > 0x7E))
                   ischars = FALSE;
            }
            for(i=0;i<7;i++)
            {
               if (ischars)
                  printf("%c", user.accountFile[i+22]);
               else
                  printf("%02X ", user.accountFile[i+22]);
            }
            printf(", VALID\n");
            FindNewSHA(user.portnum, &user.devAN[0], TRUE);
         }
         else
         {
            PrintSerialNum(&user.devAN[0]);
            printf(", invalid\n");
            FindNewSHA(user.portnum, &user.devAN[0], TRUE);
         }
      }
      else
      {
         printf("NO DEVICE, invalid\n");
         FindNewSHA(user.portnum, &user.devAN[0], TRUE);
      }
   }

   owRelease(copr.portnum);

   return TRUE;
}
Exemple #12
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;
}
Exemple #13
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;
}