LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using Write Multiple Element To Stream - want to send mixture of data types

What is a nice way of compiling together data of different types (some strings, some integers, and some doubles) and writing to the Network Stream.

0 Kudos
Message 1 of 11
(2,836 Views)

Create a cluster and use that as the datatype for the stream.

 

 

0 Kudos
Message 2 of 11
(2,806 Views)

You can use Flatten to String on the target and then Unflatten From String on the host.

The host needs to know the data type (a Type Definition is recommended).

--------------------------------------------------------------------------------------------------------------------------
Help the forum when you get help. Click the "Solution?" icon on the reply that answers your
question. Give "Kudos" to replies that help.
--------------------------------------------------------------------------------------------------------------------------
Message 3 of 11
(2,804 Views)

I selected Bundle and put it on my block diagram.  I wired an array of integers into the Bundles top input and wired a string into the second input of the Bundle.  This looks good.  But when I wired the resulting cluster to the data in of the Write Multiple Items to Stream, I get an error saying the sink is expecting a 1 D array of integers.  

Do you know what I'm doing wrong?  Thank you

0 Kudos
Message 4 of 11
(2,784 Views)

Please upload your code so we can help out.

 

When you're creating your Network Stream, what data type are you using for the Data Type input?

0 Kudos
Message 5 of 11
(2,779 Views)

@BertMcMahan wrote:

Please upload your code so we can help out.

 

When you're creating your Network Stream, what data type are you using for the Data Type input?


When you create a Network Stream, you need to specify the type of data that are passed in the Stream (think of it as a Queue that goes across a TCP/IP connection).  I suspect that you failed to do this, but without the code, who can say?

 

Bob Schor

0 Kudos
Message 6 of 11
(2,755 Views)

Hi Bob, 

Sorry for the slow reply.  I have attempted to upload two vi's (I'm relatively new to using this type of forum - so I might not have actually succeeded in uploading these vi's).

You are right - I changed the data type when writing the data (and didn't synchronize with the data type when creating the writer).  Now I'm ok with sending an array of strings.

But --- my application works well until I terminate at the writer end.  The reader end continues to go through it's while loop, and displays empty strings.  I don't know how to watch the reader to realize the write end has been terminated.

Any help would be appreciated.

Thank you

Wayne

Download All
0 Kudos
Message 7 of 11
(2,747 Views)

There's a trick I learned a long time ago in working with "one-way" communications pathways (like Queues, or Network Streams) -- the Sender "knows" when the pathway can be closed, but the Receiver (because it might not yet have finished processing) should be the one to actually close the Pathway.  The trick is to use a Sentinel, some value that means "I've sent you all I'm going to send, now you take care of closing the pathway".

 

One of my Network Streams was a Message Stream.  The last thing my Host system did was to send an "Exit System" message to the Remote.  When the Remote got this message, it took care of shutting down the Stream (from its end) and notifying the Host that it had finished (there were a pair of back-to-back Message Streams).  For safety, I also put a one-second delay in the Host after sending the Sentinel.

 

This is much easier to see with a Queue (less hand-shaking).  Suppose you have a Producer/Consumer Design, sending an Array of Dbls (from, say, a DAQmx Read to a processing Loop).  The Producer has a Stop Button to stop it.  When it exits, it enqueue, as a Sentinel, an Empty Array, and then does nothing else with the Queue.  The Consumer, which is dequeuing the data, first checks for an Empty Array.  If False (the "normal" case), it processes the data as before.  But if the Array is empty, the Consumer "knows" that the Producer has exited and won't be sending any more data, so the Consumer can stop its loop and safely Release the Queue.

 

Bob Schor

Message 8 of 11
(2,736 Views)

Something I forgot to say about closing Network Streams -- they have to be closed at both ends, of course (as they are not exactly like Queues).  If you are the Sender of the Stream, you want to do a Flush Stream (I use a timeout of 1000 ms, "just in case") before destroying the Writer Endpoint.  The Reader Endpoint I can destroy right away, because I've gotten the Sentinel, saying that the Writer has finished sending (so once I process the Sentinel here at the Reader, I know the Endpoint is finished, and the Writer, if he followed the beginning of this paragraph, has Flushed the Stream on its end and I can safely Destroy it on the Reader end).

 

A tad confusing when you first set it up, but once you do and can "see the logic", it's pretty sensible.

 

Bob Schor

0 Kudos
Message 9 of 11
(2,728 Views)

Hi Bob, 

Thank you very much for your detailed reply!

I notice that if I read more frequently than I write, the read yields an empty string array (in my test application, both read and write operations are in their own independent while loops).  I assume that once data is read, the buffers holding the data are automatically cleared.  To avoid this situation, I could ignore reads when the read yields an empty string array.  But, is it possible to sense that data is available before executing a read?  

Wayne

0 Kudos
Message 10 of 11
(2,717 Views)