<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How does DataSocket.SyncRead really work in Measurement Studio for .NET Languages</title>
    <link>https://ni.lithium.com/t5/Measurement-Studio-for-NET/How-does-DataSocket-SyncRead-really-work/m-p/247336#M2016</link>
    <description>&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT size="2"&gt;I'm trying to synchronously read a text string from a DSTP data socket.&amp;nbsp; According to the documentation SyncRead is supposed to wait for the data to be updated before returning a false signifying a successful read, it will return a true if the read times out.&amp;nbsp; I've tried using using this method and it always returns true without actually waiting for the timeout period.&amp;nbsp;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT size="2"&gt;I've got a series of VI's running on a cFP unit.&amp;nbsp; These VI's poll for information from the DataSocketServer and when they receive it successfully they write an acknowledgement to another DataSocketServer variable.&amp;nbsp; I've opened two different sockets one with the&amp;nbsp;Write AccessMode anf the other with Read AccessMode.&amp;nbsp; &lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT size="2"&gt;Here is an example of what I'm trying to do&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="Courier New"&gt;
&lt;P&gt;&lt;FONT size="2"&gt;public bool SendData(double data)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;{&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // make sure there is no data already waiting for us&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; bool result = _rx_socket.SyncRead(100000);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Send the data&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; _tx_socket.Data.Value = data;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; _tx_socket.Update();&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Wait for the acknowledgement&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; result = _rx_socket.SyncRead(10000);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return (result &amp;amp;&amp;amp; _rx_socket.Data.Value.ToString() == "OK")&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Arial" size="2"&gt;When I run this code the first SyncRead returns immediately and _rx_socket.Data.Value contains the value written to the socket data by the cFP VI,&amp;nbsp;the result variable is set to true.&amp;nbsp; The second SyncRead also returns immediately and _rx_socket.Data.Value contains the old value written to the socket data by the cFP VI,&amp;nbsp;the result variable is set to true.&amp;nbsp; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Arial" size="2"&gt;According to the docs 'If the buffer contains unprocessed data, the next value is dequeued into the Data &lt;/FONT&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT face="Arial" size="2"&gt;property and the return value is false'.&amp;nbsp; This doesn't seem to be the case.&amp;nbsp; Do I need to call the update method as well and if so do I do it before or after the call the SyncRead.&amp;nbsp;&lt;/FONT&gt;&lt;/FONT&gt;&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;FONT face="Arial" size="2"&gt;If I open a socket with the AutoRead access mode I get the correct data, I would prefer to not to go down that path however to avoid having to run a separate thread and do all the required synchronization.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/DIV&gt;</description>
    <pubDate>Thu, 28 Jul 2005 01:03:50 GMT</pubDate>
    <dc:creator>kgallagher</dc:creator>
    <dc:date>2005-07-28T01:03:50Z</dc:date>
    <item>
      <title>How does DataSocket.SyncRead really work</title>
      <link>https://ni.lithium.com/t5/Measurement-Studio-for-NET/How-does-DataSocket-SyncRead-really-work/m-p/247336#M2016</link>
      <description>&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT size="2"&gt;I'm trying to synchronously read a text string from a DSTP data socket.&amp;nbsp; According to the documentation SyncRead is supposed to wait for the data to be updated before returning a false signifying a successful read, it will return a true if the read times out.&amp;nbsp; I've tried using using this method and it always returns true without actually waiting for the timeout period.&amp;nbsp;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT size="2"&gt;I've got a series of VI's running on a cFP unit.&amp;nbsp; These VI's poll for information from the DataSocketServer and when they receive it successfully they write an acknowledgement to another DataSocketServer variable.&amp;nbsp; I've opened two different sockets one with the&amp;nbsp;Write AccessMode anf the other with Read AccessMode.&amp;nbsp; &lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT size="2"&gt;Here is an example of what I'm trying to do&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="Courier New"&gt;
&lt;P&gt;&lt;FONT size="2"&gt;public bool SendData(double data)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;{&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // make sure there is no data already waiting for us&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; bool result = _rx_socket.SyncRead(100000);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Send the data&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; _tx_socket.Data.Value = data;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; _tx_socket.Update();&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Wait for the acknowledgement&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; result = _rx_socket.SyncRead(10000);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return (result &amp;amp;&amp;amp; _rx_socket.Data.Value.ToString() == "OK")&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Arial" size="2"&gt;When I run this code the first SyncRead returns immediately and _rx_socket.Data.Value contains the value written to the socket data by the cFP VI,&amp;nbsp;the result variable is set to true.&amp;nbsp; The second SyncRead also returns immediately and _rx_socket.Data.Value contains the old value written to the socket data by the cFP VI,&amp;nbsp;the result variable is set to true.&amp;nbsp; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Arial" size="2"&gt;According to the docs 'If the buffer contains unprocessed data, the next value is dequeued into the Data &lt;/FONT&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT face="Arial" size="2"&gt;property and the return value is false'.&amp;nbsp; This doesn't seem to be the case.&amp;nbsp; Do I need to call the update method as well and if so do I do it before or after the call the SyncRead.&amp;nbsp;&lt;/FONT&gt;&lt;/FONT&gt;&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;FONT face="Arial" size="2"&gt;If I open a socket with the AutoRead access mode I get the correct data, I would prefer to not to go down that path however to avoid having to run a separate thread and do all the required synchronization.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 28 Jul 2005 01:03:50 GMT</pubDate>
      <guid>https://ni.lithium.com/t5/Measurement-Studio-for-NET/How-does-DataSocket-SyncRead-really-work/m-p/247336#M2016</guid>
      <dc:creator>kgallagher</dc:creator>
      <dc:date>2005-07-28T01:03:50Z</dc:date>
    </item>
    <item>
      <title>Re: How does DataSocket.SyncRead really work</title>
      <link>https://ni.lithium.com/t5/Measurement-Studio-for-NET/How-does-DataSocket-SyncRead-really-work/m-p/247882#M2027</link>
      <description>&lt;DIV&gt;Hi kgallagher,&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;I will try to create a small datasocket app to see if I get the same behaviour on my side. On a side note along with setting the accessmode to read/write, ensure you are also setting the ReadMode property to "Synchronous". &lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;I will post here soon. Thank you for your patience. &lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;SijinK&lt;/DIV&gt;
&lt;DIV&gt;National Instruments.&lt;/DIV&gt;</description>
      <pubDate>Thu, 28 Jul 2005 22:48:47 GMT</pubDate>
      <guid>https://ni.lithium.com/t5/Measurement-Studio-for-NET/How-does-DataSocket-SyncRead-really-work/m-p/247882#M2027</guid>
      <dc:creator>SijinK</dc:creator>
      <dc:date>2005-07-28T22:48:47Z</dc:date>
    </item>
    <item>
      <title>Re: How does DataSocket.SyncRead really work</title>
      <link>https://ni.lithium.com/t5/Measurement-Studio-for-NET/How-does-DataSocket-SyncRead-really-work/m-p/247895#M2028</link>
      <description>&lt;DIV&gt;Hi kgallagher, &lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;I wanted to follow up. Two things, ensure that you are setting the ReadMode property to "Synchronous". This is the common cause for a lot of errors. Also another note. When you perform a Write, you need to call the update method, then before you perform a read (SyncRead) you need to call the update method again. &lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;I am sure that this should fix your issue.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;SijinK&lt;/DIV&gt;
&lt;DIV&gt;National Instruments&lt;/DIV&gt;</description>
      <pubDate>Thu, 28 Jul 2005 23:42:46 GMT</pubDate>
      <guid>https://ni.lithium.com/t5/Measurement-Studio-for-NET/How-does-DataSocket-SyncRead-really-work/m-p/247895#M2028</guid>
      <dc:creator>SijinK</dc:creator>
      <dc:date>2005-07-28T23:42:46Z</dc:date>
    </item>
    <item>
      <title>Re: How does DataSocket.SyncRead really work</title>
      <link>https://ni.lithium.com/t5/Measurement-Studio-for-NET/How-does-DataSocket-SyncRead-really-work/m-p/250795#M2062</link>
      <description>&lt;DIV&gt;Unfortunately it does not.&amp;nbsp; I have set the ReadMode to 'Synchronous' &lt;FONT size="2"&gt;(an aside the docs don't mention this property has to be set prior to connecting or it is ignored)&lt;/FONT&gt; and it still doesn't work.&amp;nbsp; I have tried it with the AccessMode set both Read and ReadAutoUpdate as well as with calling and not calling Update.&amp;nbsp; I always get the same results it returns immediately with False, indicating a successful read.&amp;nbsp; This is actually&amp;nbsp;impossible because there are&amp;nbsp;no processes that have opened my particular socket with&amp;nbsp;write access much less actually writing to the socket.&amp;nbsp; The Data property is always an integer data type with a value of 0.&amp;nbsp;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Did you try this out and did it work.?&lt;/DIV&gt;
&lt;DIV&gt;If you open a socket and don't write to it does the SyncConnect function timeout?&amp;nbsp; &lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;As a work around I'm going to have set the ReadMode to Asynchronous and AccessMode to ReadAutoUpdate and then set some sort of event,&amp;nbsp;flag, etc once I get data in the DataSocket.DataUpdated event.&amp;nbsp; My first pass at this does not work because everything is running in the same thread&amp;nbsp;and I'm assuming my WaitHandle.Wait(timeout) function is blocking the socket from actually sending the DataUpdated event.&amp;nbsp; Is there a way to have the DataSocket fire event from a different thread than the one that created the socket (The SynchronizationObject property is null)?&amp;nbsp; Is there any sample code out there for trying to accomplish this?&amp;nbsp; I'd greatly appreciate any help with a workaround.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Thu, 04 Aug 2005 21:10:43 GMT</pubDate>
      <guid>https://ni.lithium.com/t5/Measurement-Studio-for-NET/How-does-DataSocket-SyncRead-really-work/m-p/250795#M2062</guid>
      <dc:creator>kgallagher</dc:creator>
      <dc:date>2005-08-04T21:10:43Z</dc:date>
    </item>
    <item>
      <title>Re: How does DataSocket.SyncRead really work</title>
      <link>https://ni.lithium.com/t5/Measurement-Studio-for-NET/How-does-DataSocket-SyncRead-really-work/m-p/251313#M2077</link>
      <description>&lt;DIV&gt;&lt;/DIV&gt;
&lt;P&gt;Hi KGallagher,&lt;/P&gt;
&lt;P&gt;I believe that the one setting that you are missing is to set the AccessMode to ReadBufferedAutoUpdate.&amp;nbsp; Before, if you were just doing a simple read, the data was not being buffered so there was no data to pick up.&amp;nbsp; This way, it will automatically buffer all the data being written.&amp;nbsp; I have put together a small example for you.&amp;nbsp; All I have done is change the datasocket example that ships with MeasurementStudio so that it uses a SyncRead.&amp;nbsp; I made sure to also set the ReadMode to Synchronous and the AccessMode to ReadBufferedAutoUpdate.&amp;nbsp; If you start the Writer and select Connect(AutoUpdate) then you can press the Connect(AutoUpdate) on the Reader and then everytime you press "Update" the SyncRead will read data from the buffer.&amp;nbsp; (I have placed Message Boxes within the code to show whether we have received data.&amp;nbsp; You can also select to Connect (Mannual Update) on both Reader and Writer and then select Update on the Writer and then the Reader and receive data.&amp;nbsp; If you were not to select Update on the Writer but&amp;nbsp;then selected Update on the Reader, there would be no data in the buffer thus you will see a timeout.&lt;/P&gt;
&lt;P&gt;Try this example out and let me know if you have any more question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Aug 2005 23:14:01 GMT</pubDate>
      <guid>https://ni.lithium.com/t5/Measurement-Studio-for-NET/How-does-DataSocket-SyncRead-really-work/m-p/251313#M2077</guid>
      <dc:creator>Caroline Bright</dc:creator>
      <dc:date>2005-08-05T23:14:01Z</dc:date>
    </item>
  </channel>
</rss>

