Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

VISA read return count changes at times

Solved!
Go to solution
Highlighted

The read return count changes at times. Thus making the communication to be lost and re establish itself when the return count comes back to normal. I am using an RS232 cable and serial port to communicate with Nanotech C5 motion controller. Kindly Help !

0 Kudos
Message 1 of 10
(351 Views)

I would imagine that the two independent loops each writing/reading from the same bus might be the cause of your issue.  You could end up with something like the following:

 

string wr1 |                | string rd1

                 | string wr | 

 

Uncertain how the instrument might react

  1. respond to both the string wr1 & string wr
  2. respond only to the first response awaiting in the queue
  3. respond only to the last request (Dump / overwrite previous request)
Help the Community (and future reviewers) by marking posts as follows:
If it helped - KUDOS
If it answers the issue - SOLUTION
Message 2 of 10
(309 Views)

As stated in one of your other threads, you are dealing with raw/hex/binary data.  Therefore you need to make sure the Termination Character is turned OFF.  Otherwise, if there just happens to be a 0xA byte in your message, the read will end there and you will not have all of your message.  Use the VISA Configure Serial Port.  One of the inputs on the top is to enable the termination character.  Set that to FALSE.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
Message 3 of 10
(299 Views)

I tried setting the termination character to false in the visa configure serial port. But Still the return count from visa read changes. I am expecting a return count of 23 from the visa read. But I obtain a return count of 4 at times which changes to 23 after a while. 

0 Kudos
Message 4 of 10
(288 Views)

So is the 4chars response some sort of error? What does the 4 char response mean according to the instrument manual?

 

One solution is to put the read-write in a while loop, use a case statement to catch the 4 vs 23 char cases, repeat the write-read for 4 char and continue for 23 char cases.

 

It likely that you are doing the read too quickly after the write and a short delay (10ms? 100ms?) might prevent the 4char responses.

 

Craig

0 Kudos
Message 5 of 10
(275 Views)

Remove the VISA Open.  That might be resetting all of your settings.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
Message 6 of 10
(273 Views)

I removed visa open and tried but there is still an issue with my visa read.

0 Kudos
Message 7 of 10
(146 Views)

I am expecting my string(Hexadecimal string) read to be : 4E54 0013 052B 0D00 0001 60FD 0000 0000 0400 0003 0096 00 (23 bytes). But I get a return count of 19 from my visa read at times (randomly ) which changes my string read to :0003 0096 (4 bytes) causing a timeout in my visa read.

0 Kudos
Message 8 of 10
(144 Views)
Solution
Accepted by topic author KarthikMurali

As Minions pointed out, you are hammering away at the instrument in two parallel loops.  You might want to introduce a small delay between Write and Read.  You might also want to capture when the read byte count isn't correct and do something.  Here's a first take at just repeating the Write, delay, Read process when the read count and byte count are not equal.

write_delay_read_repeat.png

 

I'd run this and monitor when the loop has to iterate more than once (read count) and track down the source of the problems.

 

Craig

Message 9 of 10
(94 Views)

The problem was using two parallel loops.  Whenever the read file in both the loops tried to access the resource at the same time, it got timed out thus causing an error. I made a serial connection and it started to work well. 

0 Kudos
Message 10 of 10
(65 Views)