07-27-2005 08:03 PM
public bool SendData(double data)
{
// make sure there is no data already waiting for us
bool result = _rx_socket.SyncRead(100000);
// Send the data
_tx_socket.Data.Value = data;
_tx_socket.Update();
// Wait for the acknowledgement
result = _rx_socket.SyncRead(10000);
return (result && _rx_socket.Data.Value.ToString() == "OK")
}
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, the result variable is set to true. The second SyncRead also returns immediately and _rx_socket.Data.Value contains the old value written to the socket data by the cFP VI, the result variable is set to true.
According to the docs 'If the buffer contains unprocessed data, the next value is dequeued into the Data
property and the return value is false'. This doesn't seem to be the case. Do I need to call the update method as well and if so do I do it before or after the call the SyncRead.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.
07-28-2005 05:48 PM
07-28-2005 06:42 PM
08-04-2005 04:10 PM
08-05-2005 06:14 PM
Hi KGallagher,
I believe that the one setting that you are missing is to set the AccessMode to ReadBufferedAutoUpdate. Before, if you were just doing a simple read, the data was not being buffered so there was no data to pick up. This way, it will automatically buffer all the data being written. I have put together a small example for you. All I have done is change the datasocket example that ships with MeasurementStudio so that it uses a SyncRead. I made sure to also set the ReadMode to Synchronous and the AccessMode to ReadBufferedAutoUpdate. 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. (I have placed Message Boxes within the code to show whether we have received data. 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. If you were not to select Update on the Writer but then selected Update on the Reader, there would be no data in the buffer thus you will see a timeout.
Try this example out and let me know if you have any more question.