09-24-2014 12:35 AM - edited 09-24-2014 12:36 AM
Hi everyone,
I use viRead to get a string terminated by 0xA(linefeed) from a USBTMC compatible USB INSR, the string lenth is 51(count termiate char in). The code is like this:
viSetAttribute (lInstr, VI_ATTR_TMO_VALUE, 10000);
viSetAttribute (lInstr, VI_ATTR_TERMCHAR, '\n');
viSetAttribute (lInstr, VI_ATTR_TERMCHAR_EN, VI_TRUE);
viWrite (lInstr, "*IDN?\n", 6, &lByteCnt);
lStatus = viRead (lInstr, lBufRead, 100, &lByteCnt);
After ran this code, the content of lBufRead is right, lByteCnt=51 and lStatus=VI_SUCCESS, but viRead function takes 10 secends(seems like timeout).
The questions are:
1. Why viRead takes 10 secends? I am pretty sure the response of the device does not need 10 secends.
2. Why it returns VI_SUCCESS but not VI_SUCCESS_TERM_CHAR?
thanks,
Bance
09-24-2014 02:04 AM
Just a guess, as I haven't used Visa to talk to USB instruments.
I wonder if USB End Mode for Reads (VI_ATTR_USB_END_IN) attribute is relevant in this scenario, possibly setting it to VI_USB_END_SHORT_OR_COUNT.
Take a look also to Suppress End Enable (VI_ATTR_SUPPRESS_END_EN) attribute.
09-24-2014 02:34 AM - edited 09-24-2014 02:35 AM
Since the function is waiting until timeout period expires and does not return VI_SUCCESS_TERM_CHAR, it looks like the device does not send the terminating character or somehow END indicator is received first.
So it waits until timeout for filling 100 bytes or the terminating character, but it looks like neither happens.
Can you try putting 51 instead of 100?
VI_SUCCESS
The operation completed successfully and the END indicator was received (for interfaces that have END indicators).
This completion code is returned regardless of whether the termination character is received or the number of bytes read is equal to count.
VI_SUCCESS_TERM_CHAR
The specified termination character was read but no END indicator was received.
This completion code is returned regardless of whether the number of bytes read is equal to count.
09-24-2014 09:30 PM
Hi ebalci,
Thanks for helping.
The received 51 lenth string was exactly ended by the terminater I am setting('\n') .
I tried change it to 51, but all results were the same.
And I also tried this:
lStatus = viRead (lInstr, lBufRead1, 50, &lBufByteCntAc);
lStatus = viRead (lInstr, lBufRead2, 50, &lBufByteCntAc);
The first call returns a 50 lenth string, and VI_SUCCESS_MAX_CNT, the secend call returns a single character '\n', and VI_SUCCESS. And in this case the 10 secends timeout does not happen. It seems so strange, I can't explain it anyway.
Thanks,
Bance
09-24-2014 09:35 PM
Hi Roberto,
The VI_ATTR_USB_END_IN and VI_ATTR_SUPPRESS_END_EN are used for USB RAW class only, we can't setting them in USB INSTR resource.
Anyway, thanks for helping!
Bance
09-25-2014 01:22 AM
Hi everyone, I found the 10 secends timeout maybe cased by the USB device.
When I send "*IDN?\n" to device, the response will timeout. But I send other commands to it, the timeout does not happen again.
I don't know how the difference between the device's response could case this problem. At least the response message read from the device does not have any format or content error.