+++ /dev/null
-//---------------------------------------------------------------------------\r
-// Copyright (C) 2001 Dallas Semiconductor Corporation, All Rights Reserved.\r
-//\r
-// Permission is hereby granted, free of charge, to any person obtaining a\r
-// copy of this software and associated documentation files (the "Software"),\r
-// to deal in the Software without restriction, including without limitation\r
-// the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
-// and/or sell copies of the Software, and to permit persons to whom the\r
-// Software is furnished to do so, subject to the following conditions:\r
-//\r
-// The above copyright notice and this permission notice shall be included\r
-// in all copies or substantial portions of the Software.\r
-//\r
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
-// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\r
-// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES\r
-// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,\r
-// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\r
-// OTHER DEALINGS IN THE SOFTWARE.\r
-//\r
-// Except as contained in this notice, the name of Dallas Semiconductor\r
-// shall not be used except as stated in the Dallas Semiconductor\r
-// Branding Policy.\r
-//---------------------------------------------------------------------------\r
-//\r
-// owsestmx.c - Acquire and release a Session on the 1-Wire Net using TMEX.\r
-// (Requires TMEX 3.11 or newer)\r
-//\r
-// Version: 2.01\r
-//\r
-// History: 1.03 -> 2.00 Changed 'MLan' to 'ow'. Added support for\r
-// multiple ports.\r
-// 2.00 -> 2.01 Added support for owError library.\r
-//\r
-\r
-#include <stdio.h>\r
-#include <windows.h>\r
-#include "ownet.h"\r
-\r
-// external function prototypes\r
-extern long far pascal TMExtendedStartSession(short, short, void far *);\r
-extern short far pascal TMEndSession(long);\r
-extern short far pascal TMClose(long);\r
-extern short far pascal TMSetup(long);\r
-extern short far pascal TMReadDefaultPort(short far *, short far *);\r
-\r
-short PortNum=1,PortType=2;\r
-long SessionHandle[MAX_PORTNUM];\r
-SMALLINT handle_init = FALSE;\r
-\r
-//---------------------------------------------------------------------------\r
-// Attempt to acquire a 1-Wire net using a com port and a DS2480 based\r
-// adapter.\r
-//\r
-// 'port_zstr' - zero terminated port name. For this platform\r
-// use format {port number, port type}.\r
-//\r
-// Returns: port number and -1 if not successful in setting up the port.\r
-//\r
-int owAcquireEx(char *port_zstr)\r
-{\r
- int portnum;\r
- int string_counter, counter, i, lenmax;\r
- char portnum_str[15];\r
- char porttype_str[15];\r
- void *tmex_options = NULL;\r
-\r
- if(!handle_init)\r
- {\r
- for(i=0; i<MAX_PORTNUM; i++)\r
- SessionHandle[i] = 0;\r
- handle_init = TRUE;\r
- }\r
-\r
- // check to find first available handle slot\r
- for(portnum = 0; portnum<MAX_PORTNUM; portnum++)\r
- {\r
- if(!SessionHandle[portnum])\r
- break;\r
- }\r
- OWASSERT( portnum<MAX_PORTNUM, OWERROR_PORTNUM_ERROR, -1 );\r
-\r
- // convert the string in port_zstr to be the port number and port type\r
- if(port_zstr)\r
- {\r
- lenmax = strlen(port_zstr);\r
- if (lenmax > 12)\r
- lenmax = 12;\r
- string_counter = 1;\r
- counter = 0;\r
- do\r
- {\r
- portnum_str[counter] = port_zstr[string_counter];\r
-\r
- counter++;\r
- string_counter++;\r
- }\r
- while((port_zstr[string_counter] != ',') && (string_counter <= lenmax));\r
-\r
- portnum_str[counter] = '\0';\r
-\r
- string_counter++;\r
- counter = 0;\r
-\r
- do\r
- {\r
- porttype_str[counter] = port_zstr[string_counter];\r
-\r
- counter++;\r
- string_counter++;\r
- }\r
- while((port_zstr[string_counter] != '}') && (string_counter <= lenmax));\r
-\r
- porttype_str[counter] = '\0';\r
-\r
- PortNum = atoi(portnum_str);\r
- PortType = atoi(porttype_str);\r
- }\r
-\r
- // open a session\r
- SessionHandle[portnum] = TMExtendedStartSession(PortNum,PortType,tmex_options);\r
-\r
- // check the session handle\r
- if (SessionHandle[portnum] <= 0)\r
- {\r
- OWERROR(OWERROR_GET_SYSTEM_RESOURCE_FAILED);\r
- SessionHandle[portnum] = 0;\r
- return -1;\r
- }\r
-\r
- // setup the port\r
- if (TMSetup(SessionHandle[portnum]) != 1)\r
- {\r
- TMClose(SessionHandle[portnum]);\r
- TMEndSession(SessionHandle[portnum]);\r
- OWERROR(OWERROR_SYSTEM_RESOURCE_INIT_FAILED);\r
- SessionHandle[portnum] = 0;\r
- return -1;\r
- }\r
-\r
- return portnum;\r
-}\r
-\r
-//---------------------------------------------------------------------------\r
-// Attempt to acquire a 1-Wire net using a com port and a DS2480 based\r
-// adapter.\r
-//\r
-// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to\r
-// indicate the symbolic port number.\r
-// 'port_zstr' - zero terminated port name. For this platform\r
-// use format COMX where X is the port number.\r
-//\r
-// Returns: TRUE - success, COM port opened\r
-//\r
-SMALLINT owAcquire(int portnum, char *port_zstr)\r
-{\r
- int i;\r
-\r
- if(!handle_init)\r
- {\r
- for(i=0; i<MAX_PORTNUM; i++)\r
- SessionHandle[i] = 0;\r
- handle_init = TRUE;\r
- }\r
-\r
- OWASSERT( portnum<MAX_PORTNUM && portnum>=0 && !SessionHandle[portnum],\r
- OWERROR_PORTNUM_ERROR, FALSE );\r
-\r
- // read the default PortNum and PortType\r
- TMReadDefaultPort(&PortNum,&PortType);\r
-\r
- // convert the string in port_zstr to be the port number\r
- PortNum = atoi(port_zstr);\r
-\r
- // open a session\r
- SessionHandle[portnum] = TMExtendedStartSession(PortNum,PortType,NULL);\r
-\r
- // check the session handle\r
- if (SessionHandle[portnum] <= 0)\r
- {\r
- OWERROR(OWERROR_GET_SYSTEM_RESOURCE_FAILED);\r
- SessionHandle[portnum] = 0;\r
- return FALSE;\r
- }\r
-\r
- // setup the port\r
- if (TMSetup(SessionHandle[portnum]) != 1)\r
- {\r
- TMClose(SessionHandle[portnum]);\r
- TMEndSession(SessionHandle[portnum]);\r
- OWERROR(OWERROR_SYSTEM_RESOURCE_INIT_FAILED);\r
- SessionHandle[portnum] = 0;\r
- return FALSE;\r
- }\r
-\r
- return TRUE;\r
-}\r
-\r
-//---------------------------------------------------------------------------\r
-// Release the previously acquired a 1-Wire net.\r
-//\r
-// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to\r
-// indicate the symbolic port number.\r
-//\r
-void owRelease(int portnum)\r
-{\r
- TMClose(SessionHandle[portnum]);\r
- TMEndSession(SessionHandle[portnum]);\r
- SessionHandle[portnum] = 0;\r
-}\r
-\r