public static void GetHistory(TimeSeriesBlock tsb) { Console.WriteLine("Read OPC UA Historical Data:"); try { ErrorMessage = ""; startTime = tsb.opcLastTimeStamp; endTime = DateTime.UtcNow + TimeSpan.FromMinutes(120); tsb.opcLastTimeStamp = endTime; if (session == null) { Connect(tsb); } GetData(tsb); } catch (Exception ex) { ErrorMessage = ex.Message; session?.Close(); session?.Dispose(); session = null; opc = null; } /* * session?.Close(); * session?.Dispose(); * session = null; */ }
public static void Connect(TimeSeriesBlock tsb) { if (opc == null) { opc = new UASampleClient(tsb.sourceAddress, true, 10000, tsb.username, tsb.password); } opc.ConsoleSampleClient().Wait(); session = opc.session; }