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
// //
2007-04-20 10:58:20 +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 //
2017-10-08 22:28:35 +02:00
// 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
2019-02-06 12:02:26 +01:00
# include <QtCore>
# ifdef Q_OS_LINUX
2000-02-05 22:37:44 +00:00
# include <termios.h>
# endif
2019-02-06 12:02:26 +01:00
# ifdef Q_OS_WIN32
2000-02-05 22:37:44 +00:00
# include <windows.h>
# endif
# include "types.h"
# include "e2profil.h"
2017-04-21 01:42:15 +02:00
//#define MAX_COMPORTS 64
2000-02-05 22:37:44 +00:00
class RS232Interface
{
2018-10-16 18:42:23 +02:00
public :
2000-02-05 22:37:44 +00:00
2017-04-21 01:42:15 +02:00
RS232Interface ( ) ;
2000-02-05 22:37:44 +00:00
virtual ~ RS232Interface ( ) ;
int OpenSerial ( int no ) ;
2017-04-21 01:42:15 +02:00
int OpenSerial ( QString devname ) ;
2000-02-05 22:37:44 +00:00
void CloseSerial ( ) ;
void SerialFlushRx ( ) ;
void SerialFlushTx ( ) ;
2009-11-16 23:40:43 +00:00
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 ) ;
2017-04-21 01:42:15 +02:00
// 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 ) ;
2018-10-16 18:42:23 +02:00
protected :
2000-02-05 22:37:44 +00:00
2004-11-30 17:46:48 +00:00
void WaitForTxEmpty ( ) ;
2018-10-16 18:42:23 +02:00
private :
2000-02-05 22:37:44 +00:00
2017-04-21 01:42:15 +02: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 ;
2019-02-06 12:02:26 +01:00
# 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