Skip to content

Commit eaa7e5c

Browse files
committed
Update for Write method const char * #7
1 parent 2df6f0f commit eaa7e5c

6 files changed

+27
-18
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ x64/
4343
*.vcxproj.user
4444
Testing/
4545

46-
test
46+
test_console
4747
test_gui
4848

4949
*.pdb

CMakeLists.txt

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
cmake_minimum_required(VERSION 3.0.0)
2+
project(test_console VERSION 0.1.0 LANGUAGES C CXX)
3+
4+
include(CTest)
5+
enable_testing()
6+
7+
add_executable(test_console test_console.cpp)
8+
9+
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
10+
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
11+
include(CPack)

README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@ The explanation and examples can be found at
1616

1717

1818

19-
To build and run console example, test.cpp, on Linux
19+
To build and run console example, test_console.cpp, on Linux
2020

2121
```
22-
$ g++ test.cpp -o test -std=c++11
22+
$ g++ test_console.cpp -o test_console -std=c++11
2323
24-
$ sudo ./test
24+
$ sudo ./test_console
2525
```
2626

2727

28-
To build and run console example, test.cpp, on Windows
28+
To build and run console example, test_console.cpp, on Windows
2929

3030
```
31-
g++ test.cpp -o test.exe -std=c++11
31+
g++ test_console.cpp -o test_console.exe -std=c++11
3232
33-
.\test.exe
33+
.\test_console.exe
3434
3535
```
3636

ceSerial.h

+9-9
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ class ceSerial {
5353
long Open(void);//return 0 if success
5454
void Close();
5555
char ReadChar(bool& success);//return read char if success
56-
bool WriteChar(char ch);////return success flag
57-
bool Write(char *data);//write null terminated string and return success flag
58-
bool Write(char *data,long n);
56+
bool WriteChar(const char ch);////return success flag
57+
bool Write(const char *data);//write null terminated string and return success flag
58+
bool Write(const char *data,long n);
5959
bool SetRTS(bool value);//return success flag
6060
bool SetDTR(bool value);//return success flag
6161
bool GetCTS(bool& success);
@@ -286,7 +286,7 @@ bool ceSerial::IsOpened() {
286286
else return true;
287287
}
288288

289-
bool ceSerial::Write(char *data) {
289+
bool ceSerial::Write(const char *data) {
290290
if (!IsOpened()) {
291291
return false;
292292
}
@@ -309,7 +309,7 @@ bool ceSerial::Write(char *data) {
309309
return fRes;
310310
}
311311

312-
bool ceSerial::Write(char *data,long n) {
312+
bool ceSerial::Write(const char *data,long n) {
313313
if (!IsOpened()) {
314314
return false;
315315
}
@@ -331,7 +331,7 @@ bool ceSerial::Write(char *data,long n) {
331331
return fRes;
332332
}
333333

334-
bool ceSerial::WriteChar(char ch) {
334+
bool ceSerial::WriteChar(const char ch) {
335335
char s[2];
336336
s[0]=ch;
337337
s[1]=0;//null terminated
@@ -576,22 +576,22 @@ char ceSerial::ReadChar(bool& success) {
576576
return rxchar;
577577
}
578578

579-
bool ceSerial::Write(char *data) {
579+
bool ceSerial::Write(const char *data) {
580580
if (!IsOpened()) {return false; }
581581
long n = strlen(data);
582582
if (n < 0) n = 0;
583583
else if(n > 1024) n = 1024;
584584
return (write(fd, data, n)==n);
585585
}
586586

587-
bool ceSerial::Write(char *data,long n) {
587+
bool ceSerial::Write(const char *data,long n) {
588588
if (!IsOpened()) {return false; }
589589
if (n < 0) n = 0;
590590
else if(n > 1024) n = 1024;
591591
return (write(fd, data, n)==n);
592592
}
593593

594-
bool ceSerial::WriteChar(char ch) {
594+
bool ceSerial::WriteChar(const char ch) {
595595
char s[2];
596596
s[0]=ch;
597597
s[1]=0;//null terminated

test.cpp test_console.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// File: test.cpp
21
// Description: Serial (Com port) console program for Windows and Linux
32
// WebSite: http://cool-emerald.blogspot.sg/2017/05/serial-port-programming-in-c-with.html
43
// MIT License (https://opensource.org/licenses/MIT)

test_gui.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//File: test_gui.cpp
21
//Description: Serial communication for wxWidgets
32
//WebSite: http://cool-emerald.blogspot.sg/2017/05/serial-port-programming-in-c-with.html
43
//MIT License (https://opensource.org/licenses/MIT)

0 commit comments

Comments
 (0)