private byte[] WriteSyncData(byte[] write_data, int id) { // -------------------------------------------------------------------- // Wait until sync thread is free int time = 0; while ((thrSynListen != null) && (time < _timeout)) { Thread.Sleep(10); time += 10; } // -------------------------------------------------------------------- // Create new synchronous task thrSynListen = new ListenClass(); thrSynListen.OnException += thrListen_OnException; // -------------------------------------------------------------------- // Response result if write request was ok if (thrSynListen.WriteData(tcpSynClient, write_data, id, true)) { byte[] resp_data = thrSynListen.resp_data; thrSynListen = null; return(resp_data); } // -------------------------------------------------------------------- // Response null if write request was not ok thrSynListen = null; return(null); }
private void WriteAsyncData(byte[] write_data, int id) { // -------------------------------------------------------------------- // Create new asynchronous class thrAsyListen = new ListenClass(); thrAsyListen.OnException += thrListen_OnException; thrAsyListen.OnResponseData += thrListen_OnResponseData; thrAsyListen.WriteData(tcpAsyClient, write_data, id, false); }
// ------------------------------------------------------------------------ // Write data and create new asynchronous response thread private void WriteAsyncData(byte[] write_data, int id) { // -------------------------------------------------------------------- // Create new asynchronous class thrAsyListen = new ListenClass(); thrAsyListen.OnException += new ModbusTcpLib.Master.ListenClass.ExceptionData(thrListen_OnException); thrAsyListen.OnResponseData += new ModbusTcpLib.Master.ListenClass.ResponseData(thrListen_OnResponseData); thrAsyListen.WriteData(tcpAsyClient, write_data, id, false); }