-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathForm1.cs
59 lines (49 loc) · 1.65 KB
/
Form1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using WaveReader;
namespace Magnetic_Card_Reader
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int yVal;
int lastyVal = 0;
int currSide = 1;
bool currStateHi = false;
MagneticCardReader mcReader = new MagneticCardReader();
Stream inpFile = new StreamReader(textBox1.Text).BaseStream;
WaveData wavData = new WaveData(inpFile);
for (int i = 0; i < wavData.NumberOfFrames; i++)
{
yVal = wavData.Samples[0][i];
if (yVal > 0x7FFF) yVal -= 0xFFFF;
//Call addNewSignalState on zero crossing:
if (((lastyVal < yVal && currSide < 0) || (lastyVal > yVal && currSide > 0)) && (System.Math.Abs(yVal) > 0xFF))
{
currSide = 0;
currStateHi = (yVal > 0xFF);
mcReader.addNewSignalState(i, Convert.ToInt32(currStateHi));
}
if (lastyVal * yVal < 1)
{
currSide = Convert.ToInt32(!currStateHi) * 2 - 1;
}
lastyVal = yVal;
}
textBox2.Text = mcReader.getDataString();
inpFile.Close();
}
}
}