comparison Serial.h @ 1:0b3630a29ad8

Initial version based on previous repository. Project was ported to QT6 and in now cmake based.
author Ideenmodellierer <tiefenrauscher@web.de>
date Thu, 27 Nov 2025 18:40:28 +0100
parents
children
comparison
equal deleted inserted replaced
0:76ccd6ce50c0 1:0b3630a29ad8
1 //////////////////////////////////////////////////////////////////////////////
2 /// \file Serial.h
3 /// \brief RS232 serial i/o.
4 /// \author JD Gascuel.
5 ///
6 /// \copyright (c) 2011-2016 JD Gascuel. All rights reserved.
7 /// $Id$
8 //////////////////////////////////////////////////////////////////////////////
9 //
10 // BSD 2-Clause License:
11 //
12 // Redistribution and use in source and binary forms, with or without
13 // modification, are permitted provided that the following conditions
14 // are met:
15 //
16 // 1. Redistributions of source code must retain the above copyright notice,
17 // this list of conditions and the following disclaimer.
18 //
19 // 2. Redistributions in binary form must reproduce the above copyright notice,
20 // this list of conditions and the following disclaimer in the documentation
21 // and/or other materials provided with the distribution.
22 //
23 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
33 // THE POSSIBILITY OF SUCH DAMAGE.
34 //
35 //////////////////////////////////////////////////////////////////////////////
36 // HISTORY
37 // 2012-09-22 : [jDG] Split from Frog.cpp to OSTC_Planner.cpp
38 // 2013-03-17 : [jDG] Adapted from OSTC Planner to OSTC Companion.
39 // 2014-07-07 : [jDG] Cleanups for Subsurface google-summer-of-code.
40 // 2014-07-25 : [jDG] BSD 2-clause license.
41
42 #ifndef SERIAL_H
43 #define SERIAL_H
44
45 class QString;
46
47 #include <QtGlobal> // Q_OS_WIN
48
49 #ifdef Q_OS_WIN
50 #ifndef NOMINMAX
51 # define NOMINMAX
52 #endif
53 //# define NOMINMAX
54 # include <windows.h>
55 # define S_HANDLE HANDLE
56 # undef NOMINMAX
57 #else
58 # define S_HANDLE int
59 #endif
60
61 //////////////////////////////////////////////////////////////////////////////
62 // \brief RS232 serial i/o
63 class Serial
64 {
65 S_HANDLE _hSerial;
66 bool _isOpen;
67
68 public:
69 inline Serial()
70 : _hSerial(0),
71 _isOpen(false)
72 {}
73
74 virtual ~Serial();
75
76 virtual void open(const QString &port, const QString& type);
77 virtual void close();
78
79 virtual void writeByte(unsigned char byte) const;
80 virtual unsigned char readByte() const;
81
82 virtual void writeBlock(const unsigned char* ptr, unsigned int size) const;
83 virtual unsigned int readBlock(unsigned char* ptr, unsigned int size) const;
84
85 virtual void purge();
86 virtual void flush() const;
87
88 void writeShort(unsigned short word) const;
89 unsigned short readShort() const;
90
91 void writeInt24(unsigned int int24) const;
92 unsigned int readInt24() const;
93
94 void sleep(int msec) const;
95
96 inline bool isOpen() const { return _isOpen; }
97 };
98
99 #endif // SERIAL_H