Skip to content

Commit

Permalink
Ensure Unicode strings are converted when compiling with Unicode enab…
Browse files Browse the repository at this point in the history
…led (#3301)

TelescopeControl: handle Unicode correctly (Fix #2934)
- also remove QT6 conditional compile, use QString across Qt5/6 for Windows
  • Loading branch information
A-j-K committed Jul 4, 2023
1 parent 2943963 commit 2a77c0e
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions plugins/TelescopeControl/src/common/SerialPort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
#include <unistd.h>
#endif

#include <QString>

#include <cstring> // memset

SerialPort::SerialPort(Server &server, const char *serial_device)
Expand All @@ -39,11 +41,7 @@ SerialPort::SerialPort(Server &server, const char *serial_device)
#endif
{
#ifdef Q_OS_WIN
#if (QT_VERSION>=QT_VERSION_CHECK(6,0,0))
handle = CreateFile(LPCWSTR(serial_device), GENERIC_READ|GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, 0, nullptr);
#else
handle = CreateFile(serial_device, GENERIC_READ|GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, 0, nullptr);
#endif
handle = CreateFileW(LPCWSTR(QString(serial_device).utf16()), GENERIC_READ | GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, 0, nullptr);
if (handle == INVALID_HANDLE_VALUE)
{
*log_file << Now() << "SerialPort::SerialPort(" << serial_device << "): "
Expand Down Expand Up @@ -74,18 +72,14 @@ SerialPort::SerialPort(Server &server, const char *serial_device)
DCB dcb;
memset(&dcb, 0, sizeof(dcb));
dcb.DCBlength = sizeof(dcb);
#if (QT_VERSION>=QT_VERSION_CHECK(6,0,0))
if (!BuildCommDCB(LPCWSTR("9600,n,8,1"), &dcb))
#else
if (!BuildCommDCB("9600,n,8,1", &dcb))
#endif
if (!BuildCommDCBW(LPCWSTR(QString("9600,n,8,1").utf16()), &dcb))
{
*log_file << Now() << "SerialPort::SerialPort(" << serial_device << "): "
"BuildCommDCB() failed: " << GetLastError() << StelUtils::getEndLineChar();
}
else
{
if (!SetCommState(handle,&dcb))
if (!SetCommState(handle, &dcb))
{
*log_file << Now() << "SerialPort::SerialPort(" << serial_device << "): "
"SetCommState() failed: " << GetLastError() << StelUtils::getEndLineChar();
Expand Down

0 comments on commit 2a77c0e

Please sign in to comment.