Works now with Windows Visual Studio C++ too
[owTools.git] / src / owTMEXWIN.cpp
1 // Copyright (c) 2017, Tobias Mueller tm(at)tm3d.de\r
2 // All rights reserved.\r
3 //\r
4 // Redistribution and use in source and binary forms, with or without\r
5 // modification, are permitted provided that the following conditions are\r
6 // met:\r
7 //\r
8 //  * Redistributions of source code must retain the above copyright\r
9 //    notice, this list of conditions and the following disclaimer.\r
10 //  * Redistributions in binary form must reproduce the above copyright\r
11 //    notice, this list of conditions and the following disclaimer in the\r
12 //    documentation and/or other materials provided with the\r
13 //    distribution.\r
14 //  * All advertising materials mentioning features or use of this\r
15 //    software must display the following acknowledgement: This product\r
16 //    includes software developed by tm3d.de and its contributors.\r
17 //  * Neither the name of tm3d.de nor the names of its contributors may\r
18 //    be used to endorse or promote products derived from this software\r
19 //    without specific prior written permission.\r
20 //\r
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
32 \r
33 #pragma once\r
34 \r
35         \r
36 #include <ownet.h>\r
37 \r
38 #include <atlstr.h>\r
39 \r
40 #include <stdio.h>\r
41 #include "owTMEXWIN.h"\r
42 \r
43 \r
44 int owTMEXWIN::InitAdapter(std::string s) {\r
45         // resu = owi.InitAdapter("{1,6}");\r
46 \r
47         //  int resu = owi.InitAdapter("{4,5}");\r
48         char hs[100];\r
49         sprintf_s(hs, 100, "%s", s.c_str());\r
50         portnum = owAcquireEx(hs);\r
51         if (portnum > -1) {\r
52                 owSpeed(portnum, 2);\r
53                 return 1;\r
54         }\r
55         return 0;       \r
56 }\r
57 \r
58 \r
59 int owTMEXWIN::owFirst() {\r
60         uchar SNum[8];\r
61         int res=owFirst_(portnum, TRUE, FALSE);\r
62         if (res) {\r
63                 owSerialNum(portnum, &SNum[0], TRUE);\r
64                 for (int i = 0; i<8; i++) ROM_NO[i] = SNum[i];\r
65         }\r
66         return res;\r
67 \r
68 }\r
69 int owTMEXWIN::owNext() {\r
70         uchar SNum[8];\r
71         int res = owNext_(portnum, TRUE, FALSE);\r
72         if (res) {\r
73                 owSerialNum(portnum, &SNum[0], TRUE);\r
74                 for (int i = 0; i<8; i++) ROM_NO[i] = SNum[i];\r
75         }\r
76         return res;\r
77 \r
78 }\r
79 \r
80 \r
81 void owTMEXWIN::ReleaseAdapter() {\r
82         owRelease(portnum);\r
83 }\r
84 \r
85 \r
86 int owTMEXWIN::Reset() {\r
87         return owTouchReset(portnum);\r
88 }\r
89 \r
90 int owTMEXWIN::MatchRom(snum_t snum) {\r
91         owSerialNum(portnum, snum.byte, FALSE);\r
92         return owAccess(portnum);\r
93 }\r
94 uint8_t owTMEXWIN::sendrecivByte(uint8_t byte) {\r
95         return owTouchByte(portnum, byte);\r
96                         \r
97 }\r
98 uint8_t owTMEXWIN::sendrecivBit(uint8_t bit) {\r
99         return owTouchBit(portnum, bit);\r
100         \r
101 }\r
102 \r
103 int owTMEXWIN::Communicate(std::vector<uint8_t> *data, int scount, int rcount) {\r
104         int i = 0;\r
105         uint8_t buf[400];\r
106         data->resize(scount);\r
107         for (uint8_t v : *data) {\r
108                 buf[i++] = v;\r
109         }\r
110         for (int j = 0; j < rcount; j++) {\r
111                 buf[i++] = 0xFF;\r
112         }\r
113         int ret = owBlock(portnum, FALSE, buf, scount + rcount);\r
114         if (ret) {\r
115                 for (int j = 0; j < rcount; j++) {\r
116                         data->push_back(buf[scount + j]);\r
117                 }\r
118         }\r
119         return ret;\r
120 \r
121 }\r
122         \r