From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Continuous read and single write on serial port

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.

Thanks

 

Download All
0 Kudos
Message 1 of 27
(5,827 Views)

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.

highlight-execution.PNG

 

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.


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
0 Kudos
Message 2 of 27
(5,813 Views)

But i don't want to write continuously, just once.

0 Kudos
Message 3 of 27
(5,809 Views)

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 ...

 

Bob Schor

0 Kudos
Message 4 of 27
(5,807 Views)

@sr_murd wrote:

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)


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
0 Kudos
Message 5 of 27
(5,803 Views)

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.

0 Kudos
Message 6 of 27
(5,801 Views)

if you really just have to write once,

put the write in front of the loop.


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
0 Kudos
Message 7 of 27
(5,797 Views)

Write once and that also at a particular time of the day every day.

0 Kudos
Message 8 of 27
(5,795 Views)

"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.


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
0 Kudos
Message 9 of 27
(5,790 Views)

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 .

 

thanks

0 Kudos
Message 10 of 27
(5,789 Views)