1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334
|
//=========================================================================//
// //
// PonyProg - Serial Device Programmer //
// //
// Copyright (C) 1997-2025 Claudio Lanconelli //
// //
// https://github.com/lancos/ponyprog //
// //
//-------------------------------------------------------------------------//
// //
// This program is free software; you can redistribute it and/or //
// modify it under the terms of the GNU General Public License //
// as published by the Free Software Foundation; either version2 of //
// the License, or (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU //
// General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program (see LICENSE); if not, write to the //
// Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. //
// //
//=========================================================================//
#include "pgminter.h"
#include "errcode.h"
#include "e2cmdw.h"
#include <QDebug>
class e2CmdWindow;
SIProgInterface::SIProgInterface()
: RS232Interface()
{
//qDebug() << "SIProgInterface::SIProgInterface()";
//DeInstall();
//old_portno = GetInstalled();
}
//SIProgInterface::~SIProgInterface()
//{
//}
//se res == 1 abilita il BREAK --> Tx = +12v
// altrimenti disabilita il BREAK --> Tx = -12v
void SIProgInterface::SetControlLine(int res)
{
if (IsInstalled())
{
if (cmdWin->GetPolarity() & RESETINV)
{
res = !res;
}
SetSerialBreak(res);
}
}
//La alimentazione e` data dalle tre linee: SCL, SDA, RESET.
// Se una qualsiasi di queste tre linee e` a 1 vi e` alimentazione
int SIProgInterface::SetPower(bool onoff)
{
if (onoff)
{
SetControlLine(1);
//SetClockData(); //29/05/98 non funziona la verifica subito dopo la scrittura delle 93Cx6
}
else
{
ClearClockData();
SetControlLine(0);
}
return OK;
}
int SIProgInterface::Open(int com_no)
{
qDebug() << "SIProgInterface::Open(" << com_no << ") IN *** Inst=" << IsInstalled();
int ret_val = OK;
if (GetInstalled() != com_no)
{
if ((ret_val = RS232Interface::OpenSerial(com_no)) == OK)
{
// SetSerialEventMask(0);
//SetPower(true); //08/02/1998 -- ora diamo alimentazione prima di ogni operazione e la togliamo subito dopo
Install(com_no);
}
}
qDebug() << "SIProgInterface::Open() = " << ret_val << " OUT";
return ret_val;
}
void SIProgInterface::Close()
{
qDebug() << "SIProgInterface::Close() IN *** Inst=" << IsInstalled();
if (IsInstalled())
{
SetPower(false);
//SetCommMask(hCom, old_mask);
DeInstall();
RS232Interface::CloseSerial();
}
qDebug() << "SIProgInterface::Close() OUT";
}
void SIProgInterface::SetDataOut(int sda)
{
// qDebug() << "SIProgInterface::SetDataOut(" << sda << ") *** Inst=" << IsInstalled();
if (IsInstalled())
{
if (cmdWin->GetPolarity() & DOUTINV)
{
sda = !sda;
}
SetSerialDTR(sda);
}
}
void SIProgInterface::SetClock(int scl)
{
// qDebug() << "SIProgInterface::SetClock(" << scl << ") *** Inst=" << IsInstalled();
if (IsInstalled())
{
if (cmdWin->GetPolarity() & CLOCKINV)
{
scl = !scl;
}
SetSerialRTS(scl);
}
}
void SIProgInterface::SetClockData()
{
// qDebug() << "SIProgInterface::SetClockData() *** Inst=" << IsInstalled();
if (IsInstalled())
{
unsigned int control = cmdWin->GetPolarity();
if ((control & CLOCKINV) && (control & DOUTINV))
{
SetSerialRTSDTR(0);
}
else if (!(control & CLOCKINV) && !(control & DOUTINV))
{
SetSerialRTSDTR(1);
}
else
{
if (control & CLOCKINV)
{
SetSerialRTS(0);
SetSerialDTR(1);
}
else
{
SetSerialRTS(1);
SetSerialDTR(0);
}
}
}
}
void SIProgInterface::ClearClockData() //aggiunto il 06/03/98
{
// qDebug() << "SIProgInterface::ClearClockData() *** Inst=%" << IsInstalled();
if (IsInstalled())
{
unsigned int control = cmdWin->GetPolarity();
if ((control & CLOCKINV) && (control & DOUTINV))
{
SetSerialRTSDTR(1);
}
else if (!(control & CLOCKINV) && !(control & DOUTINV))
{
SetSerialRTSDTR(0);
}
else
{
if (control & CLOCKINV)
{
SetSerialRTS(1);
SetSerialDTR(0);
}
else
{
SetSerialRTS(0);
SetSerialDTR(1);
}
}
}
}
int SIProgInterface::GetDataIn()
{
// qDebug() << "SIProgInterface::GetDataIn() *** Inst=" << IsInstalled();
if (IsInstalled())
{
if (cmdWin->GetPolarity() & DININV)
{
return !GetSerialCTS();
}
else
{
return GetSerialCTS();
}
}
else
{
return E2ERR_NOTINSTALLED;
}
}
int SIProgInterface::GetClock()
{
return 1;
}
int SIProgInterface::IsClockDataUP()
{
// qDebug() << "SIProgInterface::GetSCLSDAup() *** Inst=" << IsInstalled();
return GetDataIn();
}
int SIProgInterface::IsClockDataDOWN()
{
// qDebug() << "SIProgInterface::GetSCLSDAdown() *** Inst=" << IsInstalled();
return !GetDataIn();
}
int SIProgInterface::TestPort(int com_no)
{
qDebug() << "SIProgInterface::TestPort(" << com_no << ") IN";
int ret_val = TestSave(com_no);
if (ret_val == OK)
{
ret_val = E2ERR_OPENFAILED;
SetPower(false);
w.WaitMsec(100);
SetSerialRTS(true);
w.WaitMsec(50);
if (GetSerialDSR())
{
SetSerialRTS(false);
w.WaitMsec(50);
if (!GetSerialDSR())
{
SetSerialRTS(true);
w.WaitMsec(50);
if (GetSerialDSR())
{
ret_val = OK;
}
}
}
SetPower(false);
}
TestRestore();
qDebug() << "SIProgInterface::TestPort() = " << ret_val << " OUT";
return ret_val;
}
/***
//Salva le porte attuali ed apre una nuova seriale (per Test)
int SIProgInterface::TestSave(int port_no)
{
qDebug() << "SIProgInterface::TestSave(" << port_no<< ") IN";
int ret_val;
old_portno = IsInstalled();
Close();
if ( (ret_val = Open(port_no)) == OK )
{
}
qDebug() << "SIProgInterface::TestSave() = "<< ret_val<<" OUT";
return ret_val;
}
//Ripristina la situazione precedente a TestSave()
void SIProgInterface::TestRestore()
{
qDebug() << "SIProgInterface::TestRestore() IN *** Inst="<< IsInstalled();
if (IsInstalled())
{
Close();
}
if (old_portno)
{
Open(old_portno);
}
old_portno = 0;
qDebug() << "SIProgInterface::TestRestore() OUT";
}
***/
|