07-25-2024 08:55 AM
Have you tried changing all your VISA Writes/Reads to synchronous?
07-25-2024 09:07 AM
Hi there,
I had tried that, I just tried again but sadly I still get the same error.
Sam
07-25-2024 12:21 PM - edited 07-25-2024 12:22 PM
>> 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
07-26-2024 04:25 AM - edited 07-26-2024 04:48 AM
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
07-26-2024 07:15 AM
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.
07-29-2024 04:22 AM - edited 07-29-2024 04:54 AM
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:
07-29-2024 11:39 AM
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?
07-31-2024 09:06 AM
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.
07-31-2024 09:58 AM
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.
07-31-2024 11:52 AM
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!