Skip to content

Commit

Permalink
Update for Write method const char * #7
Browse files Browse the repository at this point in the history
  • Loading branch information
yan9a committed Mar 18, 2024
1 parent 2df6f0f commit eaa7e5c
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ x64/
*.vcxproj.user
Testing/

test
test_console
test_gui

*.pdb
Expand Down
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.0.0)
project(test_console VERSION 0.1.0 LANGUAGES C CXX)

include(CTest)
enable_testing()

add_executable(test_console test_console.cpp)

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ The explanation and examples can be found at



To build and run console example, test.cpp, on Linux
To build and run console example, test_console.cpp, on Linux

```
$ g++ test.cpp -o test -std=c++11
$ g++ test_console.cpp -o test_console -std=c++11
$ sudo ./test
$ sudo ./test_console
```


To build and run console example, test.cpp, on Windows
To build and run console example, test_console.cpp, on Windows

```
g++ test.cpp -o test.exe -std=c++11
g++ test_console.cpp -o test_console.exe -std=c++11
.\test.exe
.\test_console.exe
```

Expand Down
18 changes: 9 additions & 9 deletions ceSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ class ceSerial {
long Open(void);//return 0 if success
void Close();
char ReadChar(bool& success);//return read char if success
bool WriteChar(char ch);////return success flag
bool Write(char *data);//write null terminated string and return success flag
bool Write(char *data,long n);
bool WriteChar(const char ch);////return success flag
bool Write(const char *data);//write null terminated string and return success flag
bool Write(const char *data,long n);
bool SetRTS(bool value);//return success flag
bool SetDTR(bool value);//return success flag
bool GetCTS(bool& success);
Expand Down Expand Up @@ -286,7 +286,7 @@ bool ceSerial::IsOpened() {
else return true;
}

bool ceSerial::Write(char *data) {
bool ceSerial::Write(const char *data) {
if (!IsOpened()) {
return false;
}
Expand All @@ -309,7 +309,7 @@ bool ceSerial::Write(char *data) {
return fRes;
}

bool ceSerial::Write(char *data,long n) {
bool ceSerial::Write(const char *data,long n) {
if (!IsOpened()) {
return false;
}
Expand All @@ -331,7 +331,7 @@ bool ceSerial::Write(char *data,long n) {
return fRes;
}

bool ceSerial::WriteChar(char ch) {
bool ceSerial::WriteChar(const char ch) {
char s[2];
s[0]=ch;
s[1]=0;//null terminated
Expand Down Expand Up @@ -576,22 +576,22 @@ char ceSerial::ReadChar(bool& success) {
return rxchar;
}

bool ceSerial::Write(char *data) {
bool ceSerial::Write(const char *data) {
if (!IsOpened()) {return false; }
long n = strlen(data);
if (n < 0) n = 0;
else if(n > 1024) n = 1024;
return (write(fd, data, n)==n);
}

bool ceSerial::Write(char *data,long n) {
bool ceSerial::Write(const char *data,long n) {
if (!IsOpened()) {return false; }
if (n < 0) n = 0;
else if(n > 1024) n = 1024;
return (write(fd, data, n)==n);
}

bool ceSerial::WriteChar(char ch) {
bool ceSerial::WriteChar(const char ch) {
char s[2];
s[0]=ch;
s[1]=0;//null terminated
Expand Down
1 change: 0 additions & 1 deletion test.cpp → test_console.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// File: test.cpp
// Description: Serial (Com port) console program for Windows and Linux
// WebSite: http://cool-emerald.blogspot.sg/2017/05/serial-port-programming-in-c-with.html
// MIT License (https://opensource.org/licenses/MIT)
Expand Down
1 change: 0 additions & 1 deletion test_gui.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//File: test_gui.cpp
//Description: Serial communication for wxWidgets
//WebSite: http://cool-emerald.blogspot.sg/2017/05/serial-port-programming-in-c-with.html
//MIT License (https://opensource.org/licenses/MIT)
Expand Down

0 comments on commit eaa7e5c

Please sign in to comment.