From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
Mark_Yedinak

Modify the TCP Read primitive to terminate a read on a single character

Status: New

It would be nice if we had the option to terminate a TCP Read on a single character rather than only a CR/LF. There are many times where you would terminate a read on some end character such as a 0x03 (ETX). In order to accomplish this now we need to have a tight loop which reads from the connection a single byte at a time. Even better would be if we could specify a string as the termination sequence. However, I would be happy with a single character option.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
9 Comments
Brian_Powell
Active Participant

I wonder whether the VISA API (which supports TCP sockets and lets you set termination characters) would work better here.  Would you want to use it?

Mark_Yedinak
Trusted Enthusiast

I believe the VISA TCP will allow this to work. However there are other subtle differences between the VISA methods and teh native TCP. In addition, other code that uses TCP connections will not operate directly with the TCP primatives and vise versa. How would I support a TCP listener in VISA? Othe ritems such as setting socket options, enabling/disabling the Nagle algorithm, must be done with a TCP connection refrerence. As far as I know this cannot be done using VISA. Not to mention if the applictaion is network only using VISA requires the installation of the VISA libraries when deploying the application. Native TCP does not require any additional libraries.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Brian_Powell
Active Participant

I didn't realize you were wanting to set up a listener.  As far as I know, there's no way to do that in VISA.

 

VISA does have a way of disabling the Nagle algorithm--with the VI_ATTR_TCPIP_NODELAY property.

 

And you're right, it requires installing VISA to work.

 

I didn't quite understand what you mean by "other code that uses TCP connections will not operate directly with the TCP primitives", and what the "subtle differences" are.  I'd like to understand this better.

 

Mark_Yedinak
Trusted Enthusiast

If you want to do any special configurations on the connection besides configuring the Nagle algorithm you need to access the low level socket options. There is an old library that shows how to do this for the Nagle algorithm but there are many other options available. Granted, this is getting into low level socket control but I don't know how you would do this via VISA. If you want to interact with any of the connections from the internet toolkit you need the TCP connection reference, not a VISA resource. If I implement other protocols (such as LPD for example) why use VISA where this communication will never occur over any other connection type given it is a networking protocol. VISA brings lots of baggage (not that it is necessarily a bad thing) that simply is not required for a network only connection. Besides, why support this feature (termination) character in two different ways on connections. Right there is a subtle difference. Also, I don't think you can have a VISA read and write in parallel loops. They block each other. I think this is possible on a TCP connection though. I would have to test to confirm.

 

BTW, I wasn't aware that the Nagle algorithm was exposed on VISA connections. Thanks for that little tidbit of information.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Brian_Powell
Active Participant

Thanks for that clarification.  I agree with these points, and they help justify why this idea (and in general, keeping the TCP/IP primitives as powerful as possible) is worth voting for.

 

I don't believe a VISA or TCP Writes and Reads will block each other, but I haven't tested that.  If they do block, fixing them would be another good idea. 🙂

 

Mark_Yedinak
Trusted Enthusiast

VISA Read/Writes definitely block each other. We had to write fairly specific code to simulate this in our applications. I suppose this makes sense if the connection is half duplex. But it should not be the case when the connection is full duplex.

 

I also have to test if this occurs with the TCP Read/Write primitives.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
RobCole
Active Participant

I  just ran into this with an instrument that terminates all commands and responses with 0x0D. Sending 0x0A along with it gives me error messages. It is simple enough to add 0x0D to the end of a command sent, but it would be very nice to read input until a 0x0D character.

 

Currently, I'm reading a high number of characters with a time-out so my reads take a little time.

 

Rob

chembo
Active Participant

I have similar problem with a DAQ device which sends 0x0A (line feed). It will be really nice to have configurable termination character or string.

RCooper
Member

Same for me, the instrument replies with just 0x0D to terminate.  It is puzzling the configurable termination is not an option since it is in VISA.

 

Please consider adding it to the standard TCP read.