protected ComRrConnection(ComRRRequest request, int requestLength, byte requestHeader, int responseLength, byte responseHeader, int timeout, object info, ComPortWithThreshold port, ComPortWithThresholdSettings portSettings, Action <ComRrConnection> onDone) { Request = request; this.requestLength = requestLength; this.requestHeader = requestHeader; this.responseLength = responseLength; this.responseHeader = responseHeader; Responses = new List <ComRRResponse>(); this.port = port; this.portSettings = portSettings; finished = onDone; Info = info; timeoutTask = new DelayedTask(onTimeout, timeout); State = ComRRConnectionStates.None; ResponsePackets = new List <List <byte> >(); }
public static ComRrConnection Create(Type serialConnectionType, ComRRRequest request, ComPortWithThreshold port, ComPortWithThresholdSettings portSettings, object info, Action <ComRrConnection> onFinished, int requestLength, byte requestHeader, int responseLength, byte responseHeader, int timeout) { var n = serialConnectionType.FullName; var ciObj = cache[n] ?? (cache[n] = serialConnectionType.GetConstructor(new[] { typeof(ComRRRequest), typeof(int), typeof(byte), typeof(int), typeof(byte), typeof(int), typeof(object), typeof(ComPortWithThreshold), typeof(ComPortWithThresholdSettings), typeof(Action <ComRrConnection>) })); var ci = ciObj as ConstructorInfo; if (ci == null) { throw new Exception( $"serial connection wrapper constructor not found!!! conenction type: {serialConnectionType}"); } if (info == null) { throw new Exception($"serial connection info not found!!! conenction type: {serialConnectionType}"); } var res = (ComRrConnection)ci.Invoke(new[] { request, requestLength, requestHeader, responseLength, responseHeader, timeout, info, port, portSettings, onFinished }); return(res); }