1 //---------------------------------------------------------------------------
2 // Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
4 // Permission is hereby granted, free of charge, to any person obtaining a
5 // copy of this software and associated documentation files (the "Software"),
6 // to deal in the Software without restriction, including without limitation
7 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 // and/or sell copies of the Software, and to permit persons to whom the
9 // Software is furnished to do so, subject to the following conditions:
11 // The above copyright notice and this permission notice shall be included
12 // in all copies or substantial portions of the Software.
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 // IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
18 // OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 // OTHER DEALINGS IN THE SOFTWARE.
22 // Except as contained in this notice, the name of Dallas Semiconductor
23 // shall not be used except as stated in the Dallas Semiconductor
25 //---------------------------------------------------------------------------
27 // owSesU.C - Acquire and release a Session on the 1-Wire Net.
31 // History: 1.03 -> 2.00 Changed 'MLan' to 'ow'. Added support for
38 // keep port name for later message when closing
39 static char portname[MAX_PORTNUM][128];
41 //---------------------------------------------------------------------------
42 // Attempt to acquire a 1-Wire net using a com port and a DS2480 based
45 // 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to
46 // OpenCOM to indicate the port number.
47 // 'port_zstr' - zero terminated port name. For this platform
48 // use format COMX where X is the port number.
49 // 'return_msg' - zero terminated return message.
51 // Returns: TRUE - success, COM port opened
53 int owAcquire(int portnum, char *port_zstr, char *return_msg)
56 portname[portnum][0] = 0;
58 // attempt to open the communications port
59 if (OpenCOM(portnum,port_zstr))
60 cnt += sprintf(&return_msg[cnt],"%s opened\n",port_zstr);
63 cnt += sprintf(&return_msg[cnt],"Could not open port %s,"
64 " aborting.\nClosing port %s.\n",port_zstr,port_zstr);
69 if (DS2480Detect(portnum))
70 cnt += sprintf(&return_msg[cnt],"DS2480-based adapter detected\n");
73 cnt += sprintf(&return_msg[cnt],"DS2480-based adapter not detected, aborting program\n");
74 cnt += sprintf(&return_msg[cnt],"Closing port %s.\n",port_zstr);
80 sprintf(portname[portnum],"%s",port_zstr);
84 //---------------------------------------------------------------------------
85 // Release the previously acquired a 1-Wire net.
87 // 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to
88 // OpenCOM to indicate the port number.
89 // 'return_msg' - zero terminated return message.
91 void owRelease(int portnum, char *return_msg)
93 // close the communications port
94 sprintf(return_msg,"Closing port %s.\n",portname[portnum]);