LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot receive data fast enough using CVI serial lib calls

I am trying to read in 50 byte messages at 30 hz with a 30 msec gap between them. My problem is I cannot detect the 30 msec gap that is to be used as start of message. Any suggestions are welcomed.
Thanks
0 Kudos
Message 1 of 5
(3,475 Views)
There is no chance to use the CVI-lib. I use the API. So I can read 380 byte maassages at 20Hz. Good Luck!
0 Kudos
Message 2 of 5
(3,475 Views)
Thanks for your response.
I tried the Win API's too, i.e. Readfile/WRiteFile etc
Did you use Win API or some other library calls ?
Can you share the setup information please
0 Kudos
Message 3 of 5
(3,475 Views)
Hello,

I understand that you are reading a 50 byte message that is repeated over and over again with a 30ms delay in between each repetition. It will be rather difficult to detect a 30ms delay using software. I can imagine that possibly calling GetInQLen() in a tight loop and checking the time that it takes to change from n to n+1 would be a good place to start.


I would like more information about your application so that I can better assist you. I'm not sure what you mean by 30hz. Do you mean that the 50 byte message is sent 30 times per second? How many bits per second is this transmission? It would be much easier to simply start your acquisition application before the first byte was received on the serial port so that you could read in chunks of 50 byte
s and not have to worry about the 30ms delay. Is this possible in your situation? How about the data, are there any headers or footers in it to determine where a "packet" starts and stops?

Scott B.
Applications Engineer
National Instruments
0 Kudos
Message 4 of 5
(3,475 Views)
Hi FastIO1,
this is an extract of my program:

#include
#include
#include
#include
#include
#include

int initRS422(char *, BOOL);
int readRS422(int);
int writeRS422(int);
void closeRS422(void);

DCB dcb;
HANDLE hCom;
BOOL fSuccess;
COMMTIMEOUTS timeouts;

int writeRS422(int write_cnt)
{
o_k = off;
FlushFileBuffers(hCom);
o_k = WriteFile (hCom, (void *)write_tmp, size_d, &rd_size, NULL);
return o_k;
}

int readRS422(int stat)
{
o_k = off;
size_d = (unsigned long)size_ram;
o_k = ReadFile (hCom, (void *)read_tmp, size_d, &rd_size, NULL);
return o_k;
}


int initRS422(char *pcCommPort, int stat)
{
o_k = on;
size_b = sizeof(byte_tst);
read_tmp = malloc (size_ram);
write_tmp = malloc (size_sim);

// Try to open the port COM
hCom = CreateFile (pcCommPort, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
if (hCom == INVALID_HANDLE_VALUE) {
sprintf (&text[0], "CreateFile failed!\nError# %d\n", GetLastError());
MessagePopup ("Error Message", text);
return 2;
}

// Setting the input and output buffer

fSuccess = SetupComm(hCom, 8, 8);
if (!fSuccess) {
sprintf (&text[0], "SetupComm failed!\nError# %d\n", GetLastError());
MessagePopup ("Error Message", text);
return 2;
}

// Setting for the port
fSuccess = GetCommState (hCom, &dcb);
if (!fSuccess) {
sprintf (&text[0], "GetCommState failed!\nError# %d\n", GetLastError());
MessagePopup ("Error Message", text);
return 2;
}
dcb.BaudRate = 921600; //(e.g. max speed)
dcb.ByteSize = 8;
dcb.Parity = EVENPARITY;
dcb.StopBits = ONESTOPBIT;
fSuccess = SetCommState(hCom, &dcb);
if (!fSuccess) {
sprintf (&text[0], "SetCommState failed!\nError# %d\n", GetLastError());
MessagePopup ("Error Message", text);
return 2;
}

// Set timouts for the port
GetCommTimeouts(hCom, &timeouts);
timeouts.ReadIntervalTimeout = 0;
timeouts.ReadTotalTimeoutMultiplier = 1;
timeouts.ReadTotalTimeoutConstant = 20;
SetCommTimeouts (hCom, &timeouts);

return o_k;
}


void closeRS422()
{
free (read_tmp);
free (write_tmp);
FlushFileBuffers(hCom);
CloseHandle (hCom);
}

Do not include other CVI-Headerfiles.
0 Kudos
Message 5 of 5
(3,475 Views)