LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

serial communications

Hello,

Using the serial communications library found in LabVIEW 8.2, every command invokes a new visa session reference number. Can continually creating visa reference nums cause problems or errors in the code (perhaps memory issues)? Would it be better to re-write the vi's to use the same reference num?

Many thanks,

Steve
0 Kudos
Message 1 of 3
(2,820 Views)
Depends on your use.

If the serial port is only used by one process, it good practise to open the session once and use it and afterwards close it.

André
Regards,
André (CLA, CLED)
Message 2 of 3
(2,801 Views)
 
Using the serial communications library found in LabVIEW 8.2, every command invokes a new visa session reference number. Can continually creating visa reference nums cause problems or errors in the code (perhaps memory issues)? Would it be better to re-write the vi's to use the same reference num?

Hi Steve,
 
Something doesn't sound right.  You shouldn't have a new session ref num for each command.  Maybe that was an example not meant to evolve in it's current form (I'd have to see that vi).
 
Typically, serial communication follows this description:
 
Open serial communication (REF#1)
Configure port
Send / Receive data  (REF#1): do this as many times as needed
Write to serial port (REF#1)
 
Verify number of bytes available at port  (REF#1)
Read number of available bytes at port (REF#1)

Done Serial communication

Close Port (REF#1)

Sending data includes sending commands.  It uses the same reference for the complete transaction, from opening to closing the port.  But DO NOT do the following (I see this all the time 😠 )
 
DO NOT DO THE FOLLOWING:
 
Open serial communication (REF#2)
Send data  (REF#2)
Close Port (REF#2)
Open serial communication (REF#3)
Read ALL data at port (using timeout)  (REF#3)
Close Port (REF#3)
Open serial communication (REF#4)
Send data  (REF#4)
Close Port (REF#4)
... and so on..
 
Worse than that is when the serial port is not closed...  A single reference is (usually) sufficient, unless you have multiple serial ports. The word usually is for those special circumstances that we won't get into for now...
Message 3 of 3
(2,792 Views)