//--------------------------------------------------------------------------- // Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved. // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included // in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. // IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES // OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // OTHER DEALINGS IN THE SOFTWARE. // // Except as contained in this notice, the name of Dallas Semiconductor // shall not be used except as stated in the Dallas Semiconductor // Branding Policy. //-------------------------------------------------------------------------- // // swt1f.c - Does commands on the DS2409 device // // version 2.00-digitemp // Fixed problem of not finding more than 1 device on main branch by // changing owBranchNext to use Smart Main instead of Main On command // // 03/12/2002 Porting to the Windows for passive adapter. // bcl // // version 2.00 // - future version will have branch of a branch searches // // Include files #include #include #include "onewire.h" #include "ownet.h" #include "swt1f.h" // external One Wire functions from nework layer //extern SMALLINT owAccess(int); //extern SMALLINT owFirst(int,SMALLINT,SMALLINT); //extern SMALLINT owNext(int,SMALLINT,SMALLINT); //extern void owSerialNum(int,uchar *,SMALLINT); // external One Wire functions from transaction layer //extern SMALLINT owBlock(int,SMALLINT,uchar *,SMALLINT); //---------------------------------------------------------------------- // SUBROUTINE - SetSwitch1F // // This routine sets the main and auxilary on and off for DS2409. // // 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to // indicate the symbolic port number. // 'SerialNum' - Serial Number of DS2409 to set the switch state // 'Swtch' - '0' Sets Main and Auxilary off // '1' Sets Main on // '2' Sets Auxilary on // '3' Read Status Info Byte // '4' Smart On Main // 'NumExtra' - The number of extra bytes for a command. // 'InfoByte' - Returns the info byte and other information depending // on the command. The InfoByte size changes depending on // the NumExtra which is buffer length * (NumExtra + 1) // 'rst' - True then reset the search for devices // False don't reset search // // Returns: TRUE(1) State of DS2409 set and verified // FALSE(0) could not set the DS2409, perhaps device is not // in contact // int SetSwitch1F(HANDLE *hCom, uchar *SerialNum, int Swtch, int NumExtra, uchar *InfoByte, int rst) { int send_cnt, i, cmd, num_response; uchar send_block[50]; if(1) { send_cnt = 0; /* Match ROM command */ send_block[send_cnt++] = 0x55; /* Serial Number */ for(i = 0; i < 8; i++ ) { send_block[send_cnt++] = SerialNum[i]; } // The switch command switch(Swtch) { case 0: // All lines off send_block[send_cnt++] = 0x66; cmd = 0x66; num_response = 1; break; case 1: // Direct on Main send_block[send_cnt++] = 0xA5; cmd = 0xA5; num_response = 1; break; case 2: // Smart on Auxilary send_block[send_cnt++] = 0x33; cmd = 0x33; num_response = 3; break; case 3: // Status Read/Write send_block[send_cnt++] = 0x5A; cmd = 0x5A; num_response = 3; // bytes 0-2: don't care // bytes 3-4: write control 0 to change status // byte 5: 0 = auto-control, 1 = manual mode // byte 6: 0 = main, 1 = auxiliary // byte 7: value to be written to control output, manual mode only // 0x00 default value *InfoByte = 0x00; send_block[send_cnt++] = *InfoByte; break; case 4: // Smart on Main send_block[send_cnt++] = 0xCC; cmd = 0xCC; num_response = 3; break; default: return FALSE; } // extra bytes and confirmation for(i=0; i