Click here to Skip to main content
15,887,027 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Invalid operands to binary expression Pin
Member 1486266714-Jun-20 2:38
Member 1486266714-Jun-20 2:38 
GeneralRe: Invalid operands to binary expression Pin
Richard MacCutchan14-Jun-20 4:30
mveRichard MacCutchan14-Jun-20 4:30 
GeneralRe: Invalid operands to binary expression Pin
Member 1486266714-Jun-20 20:50
Member 1486266714-Jun-20 20:50 
GeneralRe: Invalid operands to binary expression Pin
Richard MacCutchan14-Jun-20 22:17
mveRichard MacCutchan14-Jun-20 22:17 
QuestionData packet was cut when sending from Arduino Uno to Raspberry Pi 3 in C++ Pin
Ahmad ZULKIPLEE24-Apr-18 23:26
Ahmad ZULKIPLEE24-Apr-18 23:26 
AnswerRe: Data packet was cut when sending from Arduino Uno to Raspberry Pi 3 in C++ Pin
Jochen Arndt25-Apr-18 0:17
professionalJochen Arndt25-Apr-18 0:17 
GeneralRe: Data packet was cut when sending from Arduino Uno to Raspberry Pi 3 in C++ Pin
Ahmad ZULKIPLEE25-Apr-18 2:15
Ahmad ZULKIPLEE25-Apr-18 2:15 
GeneralRe: Data packet was cut when sending from Arduino Uno to Raspberry Pi 3 in C++ Pin
Jochen Arndt25-Apr-18 3:06
professionalJochen Arndt25-Apr-18 3:06 
When you send data with the format "R%03dE T%03dE" it will be of fixed length like in "R450E T030E". The length is 11 characters plus the the line termination appended Serial.println(). Assuming that it appends a single LF and not a CR-LF pair, the length will be 12 bytes.

Knowing that you can implement reading until all bytes of a package has been received (untested from scratch):
C++
const int packetLength = 12;
int packetRead = 0;
while (packetRead < packetLength)
{
    // Append data to buffer
    int read = RS232_PollComport(cport_nr, (unsigned char *)str_recv + packetRead, (int)BUF_SIZE - packetRead);
    // Check for error
    if (read < 0)
    {
        return;
    }
    packetRead += read;
}
// Null terminate the buffer so that it can be used with string functions
// This will replace the trailing LF
str_recv[packetRead - 1] = 0;
// Get data from the received string
char cmd1, cmd2;
int val1, val2
sscanf(str_recv, "%c%03dE %c%03dE", &cmd1, &val1, &cmd2, &val2);
// Handle data here
if ('R' == cmd1)
    position = val1;
else
    position = -1;

An application can be splitted into multiple threads. You typically have the main thread that is doing the user interaction and screen outout (often also called GUI thread) and background threads that perform asnychronous operations like networking or serial communication as in your case.

If you execute such polling operations (or calling sleep()) within the main thread that will be blocked for long times resulting in lags and stuttering screen update. Note also the error check in the above code. Without that your application would stuck forever when the serial connection is interrupted by unplugging the cable or switching the Arduino off.

The solution is to create a worker thread that receives the data and uses events to signal the main (GUI) thread when new data has been received. The main thread then handles the event and can update the screen with the new data.

However, using threads is an advance programming topic so you might proceed with the polling for testing the communication. But sooner or later you would have to use threads. The thread itself can be implemented as pthread or QThread Class | Qt Core 5.10[^]. Inside the worker thread use a QEvent Class | Qt Core 5.10[^] to signal new data to the main thread.

In any case read the Qt documentation for the used functions which includes example code. You might also search the web for additional information. The Terminal Example | Qt Serial Port 5.10[^] and Blocking Slave Example | Qt Serial Port 5.10[^] might be for example of interest.
AnswerRe: Data packet was cut when sending from Arduino Uno to Raspberry Pi 3 in C++ Pin
Richard MacCutchan25-Apr-18 0:19
mveRichard MacCutchan25-Apr-18 0:19 
AnswerRe: Data packet was cut when sending from Arduino Uno to Raspberry Pi 3 in C++ Pin
leon de boer25-Apr-18 15:05
leon de boer25-Apr-18 15:05 
QuestionFrom framebuffer to SPI via ioctl in Linux Pin
Vaclav_23-Apr-18 3:16
Vaclav_23-Apr-18 3:16 
AnswerRe: From framebuffer to SPI via ioctl in Linux Pin
Jochen Arndt23-Apr-18 3:59
professionalJochen Arndt23-Apr-18 3:59 
GeneralRe: From framebuffer to SPI via ioctl in Linux Pin
Vaclav_23-Apr-18 4:17
Vaclav_23-Apr-18 4:17 
GeneralRe: From framebuffer to SPI via ioctl in Linux Pin
Jochen Arndt23-Apr-18 4:24
professionalJochen Arndt23-Apr-18 4:24 
GeneralRe: From framebuffer to SPI via ioctl in Linux Pin
Vaclav_23-Apr-18 8:08
Vaclav_23-Apr-18 8:08 
GeneralRe: From framebuffer to SPI via ioctl in Linux Pin
Jochen Arndt23-Apr-18 10:28
professionalJochen Arndt23-Apr-18 10:28 
GeneralRe: From framebuffer to SPI via ioctl in Linux Pin
Vaclav_23-Apr-18 13:39
Vaclav_23-Apr-18 13:39 
GeneralRe: From framebuffer to SPI via ioctl in Linux Pin
Jochen Arndt23-Apr-18 21:21
professionalJochen Arndt23-Apr-18 21:21 
GeneralRe: From framebuffer to SPI via ioctl in Linux Pin
Vaclav_24-Apr-18 12:16
Vaclav_24-Apr-18 12:16 
GeneralRe: From framebuffer to SPI via ioctl in Linux Pin
Jochen Arndt24-Apr-18 21:07
professionalJochen Arndt24-Apr-18 21:07 
GeneralRe: From framebuffer to SPI via ioctl in Linux Pin
Vaclav_25-Apr-18 3:36
Vaclav_25-Apr-18 3:36 
GeneralRe: From framebuffer to SPI via ioctl in Linux Pin
Jochen Arndt25-Apr-18 4:20
professionalJochen Arndt25-Apr-18 4:20 
GeneralRe: From framebuffer to SPI via ioctl in Linux Pin
Vaclav_25-Apr-18 9:11
Vaclav_25-Apr-18 9:11 
GeneralRe: From framebuffer to SPI via ioctl in Linux Pin
Vaclav_25-Apr-18 9:11
Vaclav_25-Apr-18 9:11 
AnswerRe: From framebuffer to SPI via ioctl in Linux Pin
Vaclav_23-Apr-18 5:21
Vaclav_23-Apr-18 5:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.