ponyprog/SrcPony/rs232int.h

100 lines
3.2 KiB
C
Raw Normal View History

2000-02-05 22:37:44 +00:00
//=========================================================================//
// //
// PonyProg - Serial Device Programmer //
// //
2019-02-08 00:29:55 +01:00
// Copyright (C) 1997-2019 Claudio Lanconelli //
2000-02-05 22:37:44 +00:00
// //
// http://ponyprog.sourceforge.net //
2000-02-05 22:37:44 +00:00
// //
//-------------------------------------------------------------------------//
// //
// 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 //
2000-02-05 22:37:44 +00:00
// Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. //
// //
//=========================================================================//
2017-04-18 01:25:22 +02:00
#ifndef _RS232INTERFACE_H
#define _RS232INTERFACE_H
2000-02-05 22:37:44 +00:00
#include <QtCore>
#ifdef Q_OS_LINUX
2000-02-05 22:37:44 +00:00
#include <termios.h>
#endif
#ifdef Q_OS_WIN32
2000-02-05 22:37:44 +00:00
#include <windows.h>
#endif
#include "types.h"
#include "e2profil.h"
//#define MAX_COMPORTS 64
2000-02-05 22:37:44 +00:00
class RS232Interface
{
public:
2000-02-05 22:37:44 +00:00
RS232Interface();
2000-02-05 22:37:44 +00:00
virtual ~RS232Interface();
int OpenSerial(int no);
int OpenSerial(QString devname);
2000-02-05 22:37:44 +00:00
void CloseSerial();
void SerialFlushRx();
void SerialFlushTx();
long ReadSerial(uint8_t *buffer, long len);
long WriteSerial(uint8_t *buffer, long len);
2000-02-05 22:37:44 +00:00
int SetSerialParams(long speed = -1, int bits = -1, int parity = -1, int stops = -1, int flow_control = -1);
int SetSerialTimeouts(long init_read = -1, long while_read = -1);
// void SetSerialEventMask(long mask);
2000-02-05 22:37:44 +00:00
int SetSerialBreak(int state);
int SetSerialDTR(int dtr);
int SetSerialRTS(int rts);
int GetSerialDSR() const;
int GetSerialCTS() const;
int SetSerialRTSDTR(int state);
protected:
2000-02-05 22:37:44 +00:00
2004-11-30 17:46:48 +00:00
void WaitForTxEmpty();
private:
2000-02-05 22:37:44 +00:00
QString m_devname;
2000-02-05 22:37:44 +00:00
long read_total_timeout, read_interval_timeout;
long actual_speed;
int actual_bits, actual_parity, actual_stops;
int actual_flowcontrol;
2004-11-30 17:46:48 +00:00
bool wait_endTX_mode;
2000-02-05 22:37:44 +00:00
2017-04-18 01:25:22 +02:00
// E2Profile *profile;
2019-02-06 12:10:23 +01:00
#ifdef Q_OS_WIN32
2000-02-05 22:37:44 +00:00
HANDLE hCom;
DWORD old_mask;
COMMTIMEOUTS old_timeout;
DCB old_dcb;
#elif defined(Q_OS_LINUX)
2017-04-18 01:25:22 +02:00
int fd;
2000-02-05 22:37:44 +00:00
struct termios old_termios;
#endif
};
#endif