void worker_DoWork(object sender, DoWorkEventArgs e) { string line = ""; double signal; try { try { file = new StreamReader(fileName); } catch (Exception) { // vec je otvoren fajl } line = file.ReadLine(); while (!(line.Contains("0.000"))) { if (line == null) { break; } try { line = file.ReadLine(); } catch (Exception) { return; } } do { signal = (double.Parse(line.Split('\t')[channel])); signal = signal / 1000; while (!UlazniBuffer.Write(signal)) { System.Threading.Thread.Sleep(sleepInterval); } } while ((line = file.ReadLine()) != null); while (!UlazniBuffer.Write(double.PositiveInfinity)) { System.Threading.Thread.Sleep(sleepInterval); } } catch { } Stop(); }
void worker_DoWork(object sender, DoWorkEventArgs e) { long fileLength = 0; try { file = new FileStream(fileName, FileMode.Open); reader = new BinaryReader(file); } catch (Exception) { // vec je otvoren fajl, sve je OK } fileLength = file.Length; short flag = 0; long low = 0, high = 0; byte[] buf = { 0, 0, 0 }; for (int i = 0; i < fileLength / 3; i++) { for (short j = 1; j <= 2; j++) { switch (flag) { case 0: try { buf = reader.ReadBytes(3); } catch (Exception) { return; } low = buf[1] & 0x0F; high = buf[1] & 0xF0; if (channel == j) { if (low > 7) { while (!UlazniBuffer.Write(Convert.ToDouble((buf[0] + (low << 8) - 4096)))) { System.Threading.Thread.Sleep(sleepInterval); } } else { while (!UlazniBuffer.Write(Convert.ToDouble((buf[0] + (low << 8))))) { System.Threading.Thread.Sleep(sleepInterval); } } } flag = 1; break; case 1: if (channel == j) { if (high > 127) { while (!UlazniBuffer.Write(Convert.ToDouble(buf[2] + (high << 4) - 4096))) { System.Threading.Thread.Sleep(sleepInterval); } } else { while (!UlazniBuffer.Write(Convert.ToDouble((buf[2] + (high << 4))))) { System.Threading.Thread.Sleep(sleepInterval); } } } flag = 0; break; } } } while (!UlazniBuffer.Write(Double.PositiveInfinity)) { System.Threading.Thread.Sleep(sleepInterval); } Stop(); }