X-Git-Url: http://git.smho.de/gw/?p=owTools.git;a=blobdiff_plain;f=src%2FowTMEXWIN.cpp;fp=src%2FowTMEXWIN.cpp;h=6905165a37ab95b4d9f473b898b9fd785cb43817;hp=0000000000000000000000000000000000000000;hb=1a6465a924428af072a8eb5e75ee547c394f4d8e;hpb=039b202e5c68834801d23e22eecc7cae2879ea83 diff --git a/src/owTMEXWIN.cpp b/src/owTMEXWIN.cpp new file mode 100644 index 0000000..6905165 --- /dev/null +++ b/src/owTMEXWIN.cpp @@ -0,0 +1,122 @@ +// Copyright (c) 2017, Tobias Mueller tm(at)tm3d.de +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the +// distribution. +// * All advertising materials mentioning features or use of this +// software must display the following acknowledgement: This product +// includes software developed by tm3d.de and its contributors. +// * Neither the name of tm3d.de nor the names of its contributors may +// be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#pragma once + + +#include + +#include + +#include +#include "owTMEXWIN.h" + + +int owTMEXWIN::InitAdapter(std::string s) { + // resu = owi.InitAdapter("{1,6}"); + + // int resu = owi.InitAdapter("{4,5}"); + char hs[100]; + sprintf_s(hs, 100, "%s", s.c_str()); + portnum = owAcquireEx(hs); + if (portnum > -1) { + owSpeed(portnum, 2); + return 1; + } + return 0; +} + + +int owTMEXWIN::owFirst() { + uchar SNum[8]; + int res=owFirst_(portnum, TRUE, FALSE); + if (res) { + owSerialNum(portnum, &SNum[0], TRUE); + for (int i = 0; i<8; i++) ROM_NO[i] = SNum[i]; + } + return res; + +} +int owTMEXWIN::owNext() { + uchar SNum[8]; + int res = owNext_(portnum, TRUE, FALSE); + if (res) { + owSerialNum(portnum, &SNum[0], TRUE); + for (int i = 0; i<8; i++) ROM_NO[i] = SNum[i]; + } + return res; + +} + + +void owTMEXWIN::ReleaseAdapter() { + owRelease(portnum); +} + + +int owTMEXWIN::Reset() { + return owTouchReset(portnum); +} + +int owTMEXWIN::MatchRom(snum_t snum) { + owSerialNum(portnum, snum.byte, FALSE); + return owAccess(portnum); +} +uint8_t owTMEXWIN::sendrecivByte(uint8_t byte) { + return owTouchByte(portnum, byte); + +} +uint8_t owTMEXWIN::sendrecivBit(uint8_t bit) { + return owTouchBit(portnum, bit); + +} + +int owTMEXWIN::Communicate(std::vector *data, int scount, int rcount) { + int i = 0; + uint8_t buf[400]; + data->resize(scount); + for (uint8_t v : *data) { + buf[i++] = v; + } + for (int j = 0; j < rcount; j++) { + buf[i++] = 0xFF; + } + int ret = owBlock(portnum, FALSE, buf, scount + rcount); + if (ret) { + for (int j = 0; j < rcount; j++) { + data->push_back(buf[scount + j]); + } + } + return ret; + +} +