PEBL
2.2
Psychology Experiment Building Language - Cross-platform psychological experiment development system
PComPort.h
Go to the documentation of this file.
1
//* -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*- */
3
// Name: src/devices/PComPort.h
4
// Purpose: Class for handling com (serial) Port Communication
5
// Author: Shane T. Mueller, Ph.D.
6
// Copyright: (c) 2011-2026 Shane T. Mueller <smueller@obereed.net>
7
// License: GPL 2
8
//
9
//
10
//
11
// This file is part of the PEBL project.
12
//
13
// PEBL is free software; you can redistribute it and/or modify
14
// it under the terms of the GNU General Public License as published by
15
// the Free Software Foundation; either version 2 of the License, or
16
// (at your option) any later version.
17
//
18
// PEBL is distributed in the hope that it will be useful,
19
// but WITHOUT ANY WARRANTY; without even the implied warranty of
20
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
// GNU General Public License for more details.
22
//
23
// You should have received a copy of the GNU General Public License
24
// along with PEBL; if not, write to the Free Software
25
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27
//
28
// This class is targeted to the DLP-IO8 device, which is a USB device
29
// whose driver (on linux, osx, and windows) makes it appear as a com
30
// device. It may or may not work well on other devices.
31
32
#ifndef __PCOMPORT_H__
33
#define __PCOMPORT_H__
34
35
#ifdef PEBL_USEPORTS
36
37
#include "
PDevice.h
"
38
#include "../base/PEBLObject.h"
39
#include <fstream>
40
#include <string>
41
42
typedef
signed
short
temp_t;
43
44
// This data taken from Tyler Montbriand's
45
// sensor8 front-end to the DLP-io8
46
// http://burningsmell.org/sensor8/
47
48
enum
49
{
50
// Reads temperature from a DS18B20 attached to the pin
51
CMD_0_TEMP =
'9'
, CMD_1_TEMP =
'0'
,
52
CMD_2_TEMP =
'-'
, CMD_3_TEMP =
'='
,
53
CMD_4_TEMP =
'O'
, CMD_5_TEMP =
'P'
,
54
CMD_6_TEMP =
'['
, CMD_7_TEMP =
']'
,
55
56
// Reads digital 1 or 0 from the pin
57
CMD_0_DIN =
'A'
, CMD_1_DIN =
'S'
,
58
CMD_2_DIN =
'D'
, CMD_3_DIN =
'F'
,
59
CMD_4_DIN =
'G'
, CMD_5_DIN =
'H'
,
60
CMD_6_DIN =
'J'
, CMD_7_DIN =
'K'
,
61
62
// Reads analog voltage from the pin
63
CMD_0_AIN =
'Z'
, CMD_1_AIN =
'X'
,
64
CMD_2_AIN =
'C'
, CMD_3_AIN =
'V'
,
65
CMD_4_AIN =
'B'
, CMD_5_AIN =
'N'
,
66
CMD_6_AIN =
'M'
, CMD_7_AIN =
','
,
67
68
// Sets the pin high (5V)
69
CMD_0_HI =
'1'
, CMD_1_HI =
'2'
,
70
CMD_2_HI =
'3'
, CMD_3_HI =
'4'
,
71
CMD_4_HI =
'5'
, CMD_5_HI =
'6'
,
72
CMD_6_HI =
'7'
, CMD_7_HI =
'8'
,
73
74
// Sets the pin low
75
CMD_0_LO =
'Q'
, CMD_1_LO =
'W'
,
76
CMD_2_LO =
'E'
, CMD_3_LO =
'R'
,
77
CMD_4_LO =
'T'
, CMD_5_LO =
'Y'
,
78
CMD_6_LO =
'U'
, CMD_7_LO =
'I'
,
79
80
81
// Tells it to report all data human-readable
82
CMD_SET_ASCII =0x60,
83
// Tells it to report all data as binary bytes
84
// Temperatures get reported as per raw 18B20
85
CMD_SET_BINARY =0x5c,
86
// These only matter in ASCII mode
87
CMD_SET_FAHRENHEIT =0x4c,
88
CMD_SET_CELSIUS =0x3b,
89
// Asks the USB device to send a REPLY_PING back to us
90
CMD_PING =0x27,
91
REPLY_PING =0x51,
92
// If you get this temperature, reread
93
TEMP_ERROR =0xffff,
94
TEMP_RESET =0x0550,
95
// 125 degrees C / 0.0625 degrees per bit
96
TEMP_MAX =2000,
97
// -55 degrees C / 0.0625 degrees per bit
98
TEMP_MIN =-880
99
};
100
101
102
class
PComPort:
public
PDevice
,
virtual
public
PEBLObjectBase
103
{
104
105
public
:
106
108
PComPort(
unsigned
int
port,
unsigned
int
baud,
109
std::string mode);
110
112
virtual
~PComPort();
113
114
virtual
void
Init();
115
virtual
void
SetPort(
unsigned
int
portnum,
116
unsigned
int
baud);
117
118
virtual
void
Close();
119
120
virtual
void
PSendByte(
unsigned
char
);
121
virtual
unsigned
char
GetByte();
122
virtual
int
GetByte(
unsigned
char
& x);
123
virtual
Variant
GetBytes(
int
n);
124
virtual
Variant
GetPortName();
125
126
protected
:
127
128
//Inheritable printing Method.
129
virtual
std::ostream&
SendToStream
(std::ostream& out)
const
;
130
Variant
mPortName;
131
unsigned
int
mPort;
132
unsigned
int
mBaud;
133
std::string mMode;
//mode is the rs232 mode decoded line 139
134
bool
mIsOpen;
135
136
private
:
137
138
139
};
140
141
142
#endif
143
#endif
PDevice.h
PDevice
Definition
PDevice.h:71
PEBLObjectBase
Definition
PEBLObject.h:73
PEBLObjectBase::SendToStream
virtual std::ostream & SendToStream(std::ostream &out) const
Definition
PEBLObject.cpp:220
Variant
Definition
Variant.h:67
src
devices
PComPort.h
Generated by
1.9.8