ni.com is currently experiencing unexpected issues.

Some services may be unavailable at this time.

Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

problem with multiline reading from serial RS232

hello dear LabView gurus,
 
i am having small problem with my serial port
i am using labview to talk to one device
i tried using hyperterminal that the communication works and the device receive and respond
i created simple vi to write/read from rs232 and it more or less works
i use all the port settings i used in HT and the device receives commands (i see its doing what it should do)
the strange thing i am getting is that the response from the device (which is always few lines, checked  using hyperterminal) is sent (receieved by my vy) line by line even if i am using BytesAtPort to get the right number of bytes
first line is always echoed command (which i dont get on HT) and then every another line.
i am getting one line at time so to get 4 line response i need to run the vi 5 times (one run is for the echoed command)
 
also, VISA seems to hog my port even if i am using VISA Close: after i shut the vi i cant access the port from HT (complains another program uses it)
i dont have any other vi's running
i tried access the prot from MAX and get message:
status code 0xBFF0072,
status name: VI_ERROR_RSRC_BUSY
the resource is valid but VISA cannot currently access it (and i know it actually can from my vi, it does not release it after that)
 
heres my code
 
cheers people!
0 Kudos
Message 1 of 20
(5,361 Views)
I can't open your VI but my guess is that for the VISA Configure Serial Port, you left the Enable Termination Charact input unwired. With it unwired, it defaults to True and with it true, a VISA Read will terminate as soon as the termination character is detected - no matter what you specify for bytes to read. The default termination character is \n or a LF. That is why you cannot get multi-line messages.
0 Kudos
Message 2 of 20
(5,353 Views)
Dennis is right.

Your second point about VISA keeping the port is because you do  not explicitly close the port by calling VISA Close.
Simply closing your vi is not enough. Either close LabVIEW or call the visa close for that comport.
greetings from the Netherlands
0 Kudos
Message 3 of 20
(5,347 Views)

thank you for your help people

i dont know why you cant open the vi i attached, i am using labview 8 eval version at the moment and was working ok

thanks a lot for the tip about termination character, its not clearly stated in help

regarding port hogging: i explicitly use VISA Close in my program with right visa session refnum passed and it does not return any errors so i would expect it to actually close the session and free the port

 

cheers

 

 

0 Kudos
Message 4 of 20
(5,342 Views)


@Dennis Knutson wrote:
I can't open your VI but my guess is that for the VISA Configure Serial Port, you left the Enable Termination Charact input unwired. With it unwired, it defaults to True and with it true, a VISA Read will terminate as soon as the termination character is detected - no matter what you specify for bytes to read. The default termination character is \n or a LF. That is why you cannot get multi-line messages.


Could this also hinder the read of multiple single line files causing a timeout error...

When the read VI first reads the incoming data it reports the error.

0 Kudos
Message 5 of 20
(5,318 Views)
hello all
 
first of all, VISA no longer hogs the port if its of interest to anyone
i did nothing to the program to fix it, it stopped misbehaving after i restarted PC
i guess when i was experimenting with different settings VISA went somehow wild but restart helped it a lot
now i can switch between HT and LV as i want to
 
regarding reading multiline messages: thank you for your hint Dennis
indeed, i did not set EnableTerminationChar to False
after i set it to False it helped
 
well, partially helped
i get all the responses in Highlight Execution mode (all and every line)  but nothing appers in the buffer in normal mode!
return count is 0 and no chars in the read buffer
i was suspecting that VISA closes the port before it can read actually from it so i put some sequence structures before VISA Close to make it wait before it closes (with delay time up to 10 sec) but it doesnt help, output buffer is still clear and return count is 0
any ideas?
 
regards
 
 
 
0 Kudos
Message 6 of 20
(5,297 Views)
follow up: i just noticed that BytesAtPort property returns 0 when in normal mode and actual length of the response when in highlight mode so there is nothing to read there (still the device receives commands and does what it should do)
 
does anyone know why it should behave so strangely?
0 Kudos
Message 7 of 20
(5,295 Views)
problem solved, topic closed: VISA Write lets next element in chain to execute (passes refnum and error cluster) before it actually finishes its job: maybe it has to do with my sluggish device but program goes further before my device can respond to the command
otherwise, VISA reads before the devices writes which is kinda suprising to newbie like me
putting a delay before reading solved the problem
 
thanks for all responses!
0 Kudos
Message 8 of 20
(5,294 Views)
Hey Misio,
 
My problem may be related to yours in a way.  Would you mind posting your vi so I could take a quick look at it?
0 Kudos
Message 9 of 20
(5,258 Views)
hello Steve,
 
no prob
the vi is saved in LV 8 so you might not be able to run it but you should still open it
 
cheers
Message 10 of 20
(5,246 Views)