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); }
static void Main(string[] args) { SysHelper.SetRemind("输出EXIT 退出"); var listen = new ListenClass(); listen.startListen(); mqbuffer = new Queue(); string exit; timetiff = new Dictionary <EndPoint, Tuple <int, DateTime> >(); while (true) { exit = Console.ReadLine(); if (exit.ToLower() == "exit") { break; } } }
public void Dispose() { if (tcpAsyClient != null) { tcpAsyClient.Close(); tcpAsyClient = null; } if (tcpSynClient != null) { tcpSynClient.Close(); tcpSynClient = null; } if (thrAsyListen != null) { thrAsyListen = null; } if (thrSynListen != null) { thrSynListen = null; } }