01-17-2014 04:41 AM
hi, i read a couple of posts here with a same topic, but my problem not solved. i'm must to read opcode like this one (";TST;") from chip after his booting, it takes 10-15 seconds.
i wrote this code:
//15 Seconds
for(i=0;i<1500;i++)
{
viGetAttribute(ssp, VI_ATTR_ASRL_AVAIL_NUM, &num_bytes);
viRead (ssp, Databuf, num_bytes, &RTCount);
if(strlen(Databuf)>5)
{
string = strtok(Databuf, ";")
if(strcmp(string, "TST")
retrurn 1;
}
Sleep(10);
}
it works but sometimes it is not reading buffer in time or gets ("") in Databuf, and VISA gets out with error -1705something.
are VISA have attrinbutes to wait until all buffer full with data or start buffering only then it get string (";TST;")
?
01-20-2014 03:43 PM
I'm not sure what exactly you're asking. Could you clarify your question? Are you asking about whether or not the VISA Read is completing before your program reaches the "if" statement (or if there's a way to check that)?
If you're just looking for information about different VISA attributes, I've linked a document below lists and gives descriptions of VISA attributes (along with a lot of other information about creating a VISA program in C).
NI-VISA Programmer Reference Manual
http://www.ni.com/pdf/manuals/370132c.pdf
Let me know if that document helps!
Regards,
01-20-2014 04:19 PM
thanks for an answer i will check this doc.
ok i will describe a problem more specific.
after booting a chip. it has delay about 10-15 seconds and return string ";TST;" thru the com port.
what is a best way to catch this string using NI-VISA commands. viRead, viScanf, viReadBuf?
my code sometimes catch this string and some times return nothing in buffer.
01-21-2014 01:59 AM - edited 01-21-2014 01:59 AM
You should read only after having all bytes available in the buffer, otherwise you may be reading only part of the message in one loop and overwriting it with the rest of the message on the second read. Additionally, the strtok is probably unnecessary since you may be testing the complete message without need to split it in tokens.
You should rewrite your code along this line:
for (i = 0; i < 1500; i++) { viGetAttribute(ssp, VI_ATTR_ASRL_AVAIL_NUM, &num_bytes); if (numBytes >= 5) { // Wait for a complete message to be at port viRead (ssp, Databuf, num_bytes, &RTCount); if (!strcmp (Databuf, ":TST:")) return 1; // Message OK else return 0; // Wrong message Sleep(10); }