File: portint.h

package info (click to toggle)
ponyprog 3.1.4%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,904 kB
  • sloc: cpp: 35,932; python: 981; sh: 565; xml: 67; makefile: 45; ansic: 38
file content (133 lines) | stat: -rw-r--r-- 4,177 bytes parent folder | download
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
//=========================================================================//
//                                                                         //
//  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. //
//                                                                         //
//=========================================================================//

#ifndef _PORTINTERFACE_H
#define _PORTINTERFACE_H

#include <QtCore>

#include "types.h"

#ifdef Q_OS_WIN32
#include <windows.h>

typedef void (__stdcall *lpOut32)(short, short);
typedef short(__stdcall *lpInp32)(short);
typedef BOOL (__stdcall *lpIsInpOutDriverOpen)(void);
typedef BOOL (__stdcall *lpIsXP64Bit)(void);

#endif

// Maximum number of printer ports that would be installed on a system
#define MAX_LPTPORTS    4
#define MAX_COMPORTS    8

struct base_len
{
	unsigned int base, len;
};

class PortInterface
{
  public:
	PortInterface();
	virtual ~PortInterface();

	int OpenPort(const base_len *ports);
	void ClosePort();
	int OpenSerial(int no);
	void CloseSerial();
	int OpenParallel(int no);
	void CloseParallel();
	int GetFirstPort() const
	{
		return first_port;
	}
	int GetLastPort() const
	{
		return last_port;
	}
	int GetNoPorts() const
	{
		return no_ports;
	}
	int GetSerBasePort(int no);
	int GetParBasePort(int no);

	virtual int InPort(int no = -1) const;
	virtual int OutPort(int val, int no = -1);
	virtual int OutPortMask(int mask, int val);

  protected:
	uint8_t GetCPWReg()
	{
		return cpwreg;
	}

#ifdef Q_OS_WIN32
	HANDLE  hCom;
#endif

	int write_port,             // Number of output port (write I/O port address)
		read_port;              // Number of input port (read I/O port address)
	uint8_t cpwreg;                 // write register image in memory (the content is the same of the hardware register)

  private:
	int IOperm(int a, int b, int c);

	void DetectPorts();

#ifdef Q_OS_WIN32
	//void DetectPorts9x();         // Win9x version
	void DetectLPTPortsNT();        // WinNT/2000 version
	void DetectCOMPortsNT();        // WinNT/2000 version

	int LPTCount;                   //Number of LPT ports on the system
	int COMCount;                   //Number of COM ports on the system

	DWORD   old_mask;

	HINSTANCE hInpOutDll;

	//Some global function pointers (messy but fine for an example)
	lpOut32 gfpOut32;
	lpInp32 gfpInp32;
	lpIsInpOutDriverOpen gfpIsInpOutDriverOpen;
	lpIsXP64Bit gfpIsXP64Bit;
#else
	int lcr_copy;
	int ier_copy;
#endif

	int first_port;
	int last_port;
	int no_ports;

	base_len ser_ports[MAX_COMPORTS];
	base_len par_ports[MAX_LPTPORTS];
};

#endif