I want to do continuous read but only write once through serial communication. I receive the error as attached.
If i do continuous write e.g., sending 45, there is no error, however, it is sent as 45 and 0 in a continuous way. My program is attached as well. Please suggest the way.
the problem is very simple,
in parallel to your while-loop,
you write once and then immediately close the VISA connection.
that's why you get a timeout.
EDIT: using highlight execution, you would have noticed that.
i am not sure whether you can write and read in parallel,
i would recommend you put the write also in the loop,
guarded by a case-structure.
you could put it either in front/back of the reads,
or put the reads in the false case and the write in the true.
I'm a bit concerned that you are closing the VISA Session following the Write while continuing to use it in the Read Loop. I could well believe that doing this would cause the Read to "not perform", thereby causing the VISA Read command to time out, generating the error you observed.
Whenever I have used VISA or other Serial devices, I've always interacted with them in a "serial" manner. I initialize them, do a Write (to set up initial parameters and start them going), do serial Reads in a While loop, and if I need to break out of the loop, I do so and issue another Write to stop the Read process in the loop (or I may stop the Read process and then break out of the loop). I generally do not try to do these things "in parallel" or asynchronously ...
But i don't want to write continuously, just once.
thats why you would use a control as input for the case-structure
and as bob suggested think more serial (one after the other)
Thanks for your response Bob. The requirement is to send a "set point" through serial communication once in the program and be able to read the sensors continuously. How can I achieve this sir? The reason for write in a parallel loop is because I want it execute at a particular time of the day.
if you really just have to write once,
put the write in front of the loop.
"write once ... every day"
either you start the program by hand every day,
or you put the write inside the loop as suggested above,
and the input for the case-structure is something, that checks for the correct time.
EDIT: also you think of throttling the loop, atm it runs as fast as it can ... which surely is not necessary.
just put a frame at the end of the loop and inside a "wait (ms)" function, and to make sure it is executed at the end/front you put for example the error wire to it.
This does work sir, thanks for help. The other thing is i want to execute the write 4AM to 7AM every day. Please suggest on that .