PEBL 2.2
Psychology Experiment Building Language - Cross-platform psychological experiment development system
PParallelPort Class Reference

#include <PParallelPort.h>

Inheritance diagram for PParallelPort:
PDevice PEBLObjectBase

Public Member Functions

 PParallelPort ()
 The Standard constructor.

 
virtual ~PParallelPort ()
 The Standard destructor.

 
virtual void Init ()
 
virtual void SetPort (Variant v)
 
virtual void Close ()
 
virtual char GetStatusState ()
 
virtual char GetDataState ()
 
virtual void SetDataState (char x)
 
virtual void EmulateStandardPort ()
 
virtual void SetOutputMode ()
 
virtual void SetInputMode ()
 
virtual int GetState (int iface)
 
- Public Member Functions inherited from PDevice
 PDevice ()
 The Standard constructor.
 
virtual ~PDevice ()
 The Standard destructor.
 
virtual PEBL_DEVICE_TYPE GetDeviceType ()
 
virtual int GetState (int iface) const
 
- Public Member Functions inherited from PEBLObjectBase
 PEBLObjectBase ()
 Standard Constructor.
 
 PEBLObjectBase (ComplexDataType cdt)
 Standard Constructor.
 
 PEBLObjectBase (const PEBLObjectBase &pob)
 
virtual ~PEBLObjectBase ()
 Standard Destructor.
 
virtual bool InitializeProperty (std::string name, Variant v)
 
virtual bool SetProperty (std::string name, Variant v)
 
Variant GetProperty (std::string) const
 
virtual ObjectValidationError ValidateProperty (std::string, Variant v) const
 
virtual ObjectValidationError ValidateProperty (std::string) const
 
ComplexDataType GetType ()
 
virtual std::string ObjectName () const
 
virtual std::ostream & PrintProperties (std::ostream &out)
 
virtual Variant GetPropertyList ()
 

Protected Member Functions

virtual std::ostream & SendToStream (std::ostream &out) const
 

Protected Attributes

unsigned int mPort
 
bool mIsOpen
 
- Protected Attributes inherited from PEBLObjectBase
ComplexDataType mCDT
 
std::map< std::string, VariantmProperties
 

Detailed Description

Definition at line 37 of file PParallelPort.h.

Constructor & Destructor Documentation

◆ PParallelPort()

PParallelPort::PParallelPort ( )

The Standard constructor.

Definition at line 67 of file PParallelPort.cpp.

67 :
69 mIsOpen(false)
70{
72}
@ CDT_PARALLELPORT
Definition PEBLObject.h:65
@ PEBLPPortLPT1
ComplexDataType mCDT
Definition PEBLObject.h:109
unsigned int mPort

References CDT_PARALLELPORT, and PEBLObjectBase::mCDT.

◆ ~PParallelPort()

PParallelPort::~PParallelPort ( )
virtual

The Standard destructor.

Definition at line 75 of file PParallelPort.cpp.

76{
77 if(mIsOpen)
78 Close();
79}
virtual void Close()

References Close(), and mIsOpen.

Member Function Documentation

◆ Close()

void PParallelPort::Close ( )
virtual

Definition at line 161 of file PParallelPort.cpp.

162{
163#ifdef PEBL_LINUX
164 int out =ioperm(mPort,3,0);
165#elif defined (PEBL_WIN32)
166
167 //This doesnot work yet:
168// FreeLibrary(hLib);
169#endif
170 mIsOpen = false;
171}

References mIsOpen, and mPort.

Referenced by ~PParallelPort().

◆ EmulateStandardPort()

void PParallelPort::EmulateStandardPort ( )
virtual

Definition at line 222 of file PParallelPort.cpp.

223{
224//Not functional
225
226}

◆ GetDataState()

char PParallelPort::GetDataState ( )
virtual

Definition at line 197 of file PParallelPort.cpp.

198{
199#if defined(PEBL_LINUX)
200 return (inb(mPort));
201
202#elif defined (PEBL_WIN32)
203 return Inp32(mPort);
204#else
205 return '\0';
206#endif
207
208}
int Inp32(int i)

References Inp32(), and mPort.

Referenced by GetState().

◆ GetState()

int PParallelPort::GetState ( int  iface)
virtual

Definition at line 275 of file PParallelPort.cpp.

276{
277 int out =0;
278 if(iface==0)
279 {
281 SetDataState((char)0);
282 SetInputMode();
283 out = GetDataState();
284 } else
285 if(iface==1)
286 {
287 out = GetStatusState();
288 }
289
290 return out;
291}
virtual void SetDataState(char x)
virtual void SetOutputMode()
virtual char GetStatusState()
virtual void SetInputMode()
virtual char GetDataState()

References GetDataState(), GetStatusState(), SetDataState(), SetInputMode(), and SetOutputMode().

◆ GetStatusState()

char PParallelPort::GetStatusState ( )
virtual

Definition at line 183 of file PParallelPort.cpp.

184{
185#if defined(PEBL_LINUX)
186 return inb(mPort+1);
187#elif defined (PEBL_WIN32)
188 return Inp32(mPort+1);
189#else
190 return '\0';
191#endif
192 // return (inb(mPort+1)>>3)^0x10;
193}

References Inp32(), and mPort.

Referenced by GetState().

◆ Init()

void PParallelPort::Init ( )
virtual

Definition at line 83 of file PParallelPort.cpp.

84{
85
86#ifdef PEBL_LINUX
87 //This works on linux: open 3 bytes to access
88 int out = ioperm(mPort, 3, 1);
89 //int out = iopl(3);
90 mIsOpen = true;
91 std::cerr << "Initiating parallel port. Return value :["<<out<<"]\n";
92
93
94 // EmulateStandardPort();
95 if(out)
96 {
97 PError::SignalFatalError("Unable to Access Parallel Port. Make sure script is run with root access.\n");
98 }
99
100
101#elif defined(PEBL_WIN32)
102 HINSTANCE hLib;
103 inpfuncPtr inp32fp;
104 oupfuncPtr oup32fp;
105 hLib = LoadLibrary("inpout32.dll");
106 if(hLib == NULL)
107 {
108 PError::SignalFatalError("Unable to load library inpout32.dll. Cannot initiate parallel port device");
109 }
110
111// Get the address of the Input function
112
113 inp32fp = (inpfuncPtr) GetProcAddress(hLib, "Inp32");
114
115 if (inp32fp == NULL)
116 {
117 PError::SignalFatalError("Unable to get Inp32.");
118 }
119
120
121 oup32fp = (oupfuncPtr) GetProcAddress(hLib, "Out32");
122
123 if (oup32fp == NULL) {
124
125 PError::SignalFatalError("Unable to get oup32");
126 }
127
128
129#endif
130
131
132
133
134}
#define NULL
Definition BinReloc.cpp:317
void SignalFatalError(const std::string &message)

References mIsOpen, mPort, NULL, and PError::SignalFatalError().

◆ SendToStream()

ostream & PParallelPort::SendToStream ( std::ostream &  out) const
protectedvirtual

Reimplemented from PDevice.

Definition at line 266 of file PParallelPort.cpp.

267{
268 out << "<Generic Parallel Port Object>" << flush;
269 return out;
270}

◆ SetDataState()

void PParallelPort::SetDataState ( char  x)
virtual

Definition at line 211 of file PParallelPort.cpp.

212{
213#if defined(PEBL_LINUX)
214 outb(x,mPort);
215#elif defined (PEBL_WIN32)
216 Out32(mPort,x);
217#endif
218
219}
int Out32(int i, int x)

References mPort, and Out32().

Referenced by GetState().

◆ SetInputMode()

void PParallelPort::SetInputMode ( )
virtual

Definition at line 251 of file PParallelPort.cpp.

252{
253
254#if defined(PEBL_LINUX)
255 unsigned char x = inb(mPort+2);
256 // turns 7th bit of the control byte on
257 outb( x | 0x20, mPort+2);
258#elif defined (PEBL_WIN32)
259 unsigned char x = Inp32(mPort+2);
260 Out32(mPort+2,x|0x20);
261#endif
262
263
264}

References Inp32(), mPort, and Out32().

Referenced by GetState().

◆ SetOutputMode()

void PParallelPort::SetOutputMode ( )
virtual

Definition at line 231 of file PParallelPort.cpp.

232{
233
234
235#if defined(PEBL_LINUX)
236 unsigned char x;
237 x = inb(mPort+2); //get state of control register
238 outb(x & ~0x20, mPort+2);
239#elif defined (PEBL_WIN32)
240 unsigned char x;
241 x = Inp32(mPort+2);
242 Out32(mPort+2,x&~0x20);
243#endif
244
245
246}

References Inp32(), mPort, and Out32().

Referenced by GetState().

◆ SetPort()

void PParallelPort::SetPort ( Variant  v)
virtual

Definition at line 140 of file PParallelPort.cpp.

141{
142 if(v=="LPT1")
143 {
145
146 }else if(v=="LPT2")
147 {
149 } else if(v=="LPTX")
150 {
152 }else{
153
154 //SHould allow to set to arbitrary hex-coded port address here.
155 std::cerr << "Cannot set port to ["<<v<<"]. Setting to LPT1.\n";
156 }
157
158}
@ PEBLPPortLPTX
@ PEBLPPortLPT2

References mPort, PEBLPPortLPT1, PEBLPPortLPT2, and PEBLPPortLPTX.

Member Data Documentation

◆ mIsOpen

bool PParallelPort::mIsOpen
protected

Definition at line 66 of file PParallelPort.h.

Referenced by Close(), Init(), and ~PParallelPort().

◆ mPort

unsigned int PParallelPort::mPort
protected

The documentation for this class was generated from the following files: