public void ReadSlow(SsmInterface ecu) { List <int> addresses = new List <int>(); int reads = ((this.length) / 16); for (int i = 0; i < reads; i++) { for (int offset = 16 * i; (offset < (16 * (i + 1)) && (offset < length)); offset++) { addresses.Add(this.start + offset); } IAsyncResult result = ecu.BeginMultipleRead(addresses, null, null); result.AsyncWaitHandle.WaitOne(); byte[] values = ecu.EndMultipleRead(result); addresses.Clear(); for (int j = 0; j < 16; j++) { this.data[(16 * i) + j] = values[j]; } if (i % 200 == 0) { Console.Write("."); } } }
public void Read(SsmInterface ecu) { const int blockSize = 200; int reads = this.length / blockSize + 1; for (int i = 0; i < reads; i++) { int blockStart = i * blockSize; int thisBlockSize = Math.Min(blockSize, (this.length - blockStart)); if (thisBlockSize < 0) { break; } //IAsyncResult result = ecu.BeginBlockRead(blockStart, blockSize, null, null); //result.AsyncWaitHandle.WaitOne(); //byte[] values = ecu.EndBlockRead(result); byte[] values = ecu.SyncReadBlock(blockStart, blockSize); if (values.Length != thisBlockSize) { Console.Write("Failed at read {0} of {1}, ", i, reads); Console.WriteLine("Values.Length={0}, thisBlockSize={1}", values.Length, thisBlockSize); System.Diagnostics.Debugger.Break(); } for (int j = 0; j < thisBlockSize; j++) { int index = blockStart + j; this.data[index] = values[j]; } if (i % 10 == 0) { Console.Write("Read {0} of {1}, ", i, reads); Console.WriteLine((i * 100 / reads).ToString(CultureInfo.InvariantCulture) + "%"); } } }
/// <summary> /// Conduct all future ECU transactions over the given stream /// </summary> public void SetEcuStream(Stream stream) { Trace.WriteLine("SsmBasicLogger.SetEcuStream"); this.ecu = SsmInterface.GetInstance(stream); }
/// <summary> /// Private constructor - use factory instead /// </summary> private SsmBasicLogger(string configurationDirectory, Stream stream) { this.configurationDirectory = configurationDirectory; this.ecu = SsmInterface.GetInstance(stream); }