LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VISA Read and Write Sequence Causes Timeout Error Except in "Highlight Execution Mode"

Solved!
Go to solution

Have you tried changing all your VISA Writes/Reads to synchronous?

0 Kudos
Message 11 of 20
(356 Views)

Hi there,

 

I had tried that, I just tried again but sadly I still get the same error.

 

Sam

Samuel Allen
University of St Andrews
0 Kudos
Message 12 of 20
(352 Views)

>> The top-level VI that works with the sub-VI and the new top-level VI that does not have exactly identical set up routines!

 

I don't understand that sentence.  But it might help us to look at the larger code, because there's just no reason a standalone VI or a subvi with the same setup and commands wouldn't work.  I suspect there's some clean-up or setup misstep happening here before you run the standalone.  Personally, when working with a new device I write a stand-alone app to test/torture all features and look for limitations then create subVIs of that then re-use in other applications.  

 

Make sure you aren't running the device in NI-MAX or any terminal at the same time when doing your testing..  

 

Perhaps power off the device, try the stand-alone app and see if behaviour changes.  Run the larger code, retry the stand-alone and see if your problem re-occurs.

 

Craig

0 Kudos
Message 13 of 20
(339 Views)

Hi Craig,

 

What I mean is that the set-up code / routine is exactly identical as far as the serial port is concerned between the two top-level VIs. It is then a complete mystery why the sub-VI works with one of them and not with the other!

 

NI MAX and arduino IDE are definitely closed, and I can't think of anything else that might be communicating with the device?

 

I am going to try everything mentioned again, test and test again and if not I will just have to build the top-level VI from scratch.

 

Sadly, I can't share the top-level VI with you because in order to work/make any sense it needs a proprietary labview package for controlling the other instrument, but I can share the previous version with you if that helps?

 

The previous version is a messy first attempt from a few months back, but the sub-VI works in that case. Please don't pay attention to the other cases in the case structure, these have all been re-worked in the intervening time.

 

Edit: I tried stripping away the other instrument's code from the "Update values" case in the new code, and the error still occurs.

 

Thanks,


Sam

Samuel Allen
University of St Andrews
Download All
0 Kudos
Message 14 of 20
(303 Views)

Could you also share your Arduino code?  I'm wondering if something could be happening in there to cause it to freeze up.

 

I have 2 other comments:

1. If you change the display style on your strings, make the display style visible.  This adds to the readability of your code and avoids a very common error.

2. I very rarely need to use the VISA Clear function.  I would try removing that from your subVI as well.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 15 of 20
(287 Views)

Hi there,

 

I am happy to share the relevant part of the Arduino code but sadly I probably can't share it all without my supervisor's permission. I will attach it in an edit to this post. It is worth nothing however that as I have said, the Arduino responds immediately to exactly the same commands written via NI MAX and/or Arduino IDE, so I am 99% sure the issue is not with the Arduino code.

 

1. That's good advice, I will follow that.

2. I had just thrown it in there as part of my troubleshooting, so I will remove it again as I am fairly sure it made no difference.

 

Thank you so much for your help,

 

Sam

 

Edit 1: Interestingly, in the code I provided, only the wait before the write is needed - no wait is needed between writing the command and reading the response! This leads me to think the issue arises from writing too soon, the command doesn't reach the arduino, so the read just times out because nothing is sent back if no command is received?

 

Edit 2: The relevant Arduino code:

 

const byte numChars = 32;
char receivedChars[numChars];
char tempChars[numChars];        // temporary array for use when parsing
 
// variables to hold the parsed data
 
char messageFromPC1[numChars] = {0};
char messageFromPC2[numChars] = {0};
boolean newData = false;
unsigned long integerFromPC = 0;
float floatFromPC = 0.0;
String decision;
String instruction;
 
// string_search();
 
recvWithEndMarker();
if (newData == true) {
strcpy(tempChars, receivedChars); // this temporary copy is necessary to protect the original data because strtok() used in parseData() replaces the commas with \0
parseData();
showParsedData();
newData = false;
}
 
void parseData() {      // split the data into its parts
 
char * strtokIndx; // this is used by strtok() as an index
 
strtokIndx = strtok(tempChars,",");      // get the first part - the string
strcpy(messageFromPC1, strtokIndx); // copy it to messageFromPC
 
strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
integerFromPC = atol(strtokIndx);     // convert this part to an integer
 
strtokIndx = strtok(NULL, ",");
//  floatFromPC = atof(strtokIndx);     // convert this part to a float
strcpy(messageFromPC2, strtokIndx);
instruction = String(messageFromPC1);
decision  = String(messageFromPC2);
}
 
if (instruction=="read_diff")
{
  diff = preset - total;
  Serial.print(diff);
  Serial.print("\n");
}
 
if (instruction=="read_total")
{
  Serial.print(total);
  Serial.print("\n");
}
 
if (instruction=="read_preset")
{
  Serial.print(preset);
  Serial.print("\n");
}
 
if (instruction=="read_pulse_count")
{
Serial.print(pulse_count);
Serial.print("\n")
}
 
------
 
I didn't write this code, and like I said the issue does not arise when sending commands over serial, so I am confident the Arduino code is not the issue.
Samuel Allen
University of St Andrews
0 Kudos
Message 16 of 20
(264 Views)

Hi everyone,

 

Just to be clear as I think the point gets lost in that very long message of mine... the delay that is needed to get the code working I have discovered is after the previous read executes and before the new write.

 

The response from the VISA write is therefore almost instant, as it should be, and requires no wait between the write of "read_x" and the response "x". The issue is that after I read something I have to wait at least 1 second before I can write anything again without causing an error! This wait also has to be placed before the first write, even though there is no previous read in that case. In all cases, the program is doing nothing else during this wait time.

 

Has anyone every encountered an issue like this before? Is it an issue with the latency setting of the COM port or something along those lines?

Samuel Allen
University of St Andrews
0 Kudos
Message 17 of 20
(231 Views)

Hi,

 

Just an update with another thing I have tried to rectify the issue. I have tried with the other instrument plugged in and unplugged, to see if the root cause of the issue is a conflict with the sub-VIs that came with that instrument. The answer is no: the issue still occurs.

Samuel Allen
University of St Andrews
0 Kudos
Message 18 of 20
(200 Views)
Solution
Accepted by topic author smallen

Issue solved: the only required wait is between the serial initialise and the first write... I am still unsure why but this is a workable fix that resolves the issue by just adding a 1000 ms wait to the start up of the program.

Samuel Allen
University of St Andrews
0 Kudos
Message 19 of 20
(194 Views)

Glad its solved.  I think the problem is likely that the Arduino is too busy processing and gathering data to reply unless there's a delay.  Arduino's are not high throughput or really fast A/Ds devices!

Message 20 of 20
(183 Views)