LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

viRead/viScanf Problem On VISA-USB INSR

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

 

0 Kudos
Message 1 of 6
(5,889 Views)

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.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 6
(5,875 Views)

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.

 

S. Eren BALCI
IMESTEK
0 Kudos
Message 3 of 6
(5,871 Views)

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

0 Kudos
Message 4 of 6
(5,847 Views)

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

0 Kudos
Message 5 of 6
(5,845 Views)

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. 

0 Kudos
Message 6 of 6
(5,835 Views)