10-12-2010 09:01 AM
Hi all
1)
I am trying to do serial communication in Labwindows. The basic structure of my code is as following
// Global variable
BOOL bThreadLoop = True;
Callback_start()
// executed only once
Opencomconfig ( port no , baudrate , ....etc)
userThread();
UserThread()
{
while(bThreadLoop) // while(1)
// Executed repeatedly
ComRd( portno, no of bytes to read ....etc)
// code for Displaying the serially get values on Front Panel
SetCtrlVal(.......)
.................
...............
ProcessSystemEvents();
}
callback_stop()
{
bThreadLoop = False;
// Executed only once
Closecom(port no)
}
The problem which i am facing is that the values which i am receiving serially are not updated on the front panel
The front panel only updates for one time only that is at the beginning when i start the program.
2) My second question is that if i want to acquire 30 bytes only, then what value will i set
for the parameter Input Queue Length in Opencomconfig?
10-12-2010 10:55 AM
Regarding your first question, adding a ProcessSystemEvents may help in updating the main panel. Nevertheless in a scenario like yours it wold be better to send acquired data to the main thread (e.g. via a queue) and let that thread update the user interface, optionally at a slover speed that the second thread is acquiring and handling data.
With reference to the second question, the input queue lenght in OpenComConfig must be set at a reasonable value depending on your serial activity (i.e. considering the worst case of accumulation of data in the input queue). When you read from the queue with ComRd you must set the desired amount of bytes to read from the queue (your actual 30 bytes chunk).
In my experience, leaving standard 512 bytes queue lenght when opening the port is enough for the majority of applications.