Basic program operations [PICProgramm.cs]
This commit is contained in:
@@ -1,173 +1,111 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using System.IO;
|
||||
using PIC_Simulator;
|
||||
|
||||
|
||||
|
||||
namespace PIC_Simulator
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
}
|
||||
// Globale Variablen
|
||||
public int ArrayLaenge =0;
|
||||
public int PCounter = -1;
|
||||
public int time;
|
||||
public int timeIntervall;
|
||||
Einlesen instEinlesen = new Einlesen();
|
||||
|
||||
|
||||
private void label1_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void Form1_Load(object sender, EventArgs e)
|
||||
{
|
||||
box_CodeView.Font = new Font("Consolas", 8);
|
||||
timeIntervall = 1000;
|
||||
}
|
||||
|
||||
private void cmd_Start_Click(object sender, EventArgs e)
|
||||
{
|
||||
timer1.Interval = timeIntervall; // 1 Sekunde
|
||||
timer1.Enabled = true;
|
||||
}
|
||||
|
||||
private void cmd_next_Click(object sender, EventArgs e)
|
||||
|
||||
{
|
||||
// MessageBox.Show("Array laenge übergeben:" + ArrayLaenge);
|
||||
if (PCounter == ArrayLaenge) { MessageBox.Show("Programm ist komplett durchlaufen!"); }
|
||||
else {
|
||||
PCounter = PCounter + 1;
|
||||
try
|
||||
{
|
||||
//Zeilenmarkierung aufheben
|
||||
highLightALine(box_CodeView, PCounter - 1, Color.White);
|
||||
}
|
||||
catch { }
|
||||
//Counter im Label inkrementieren
|
||||
int shownCounter = PCounter;
|
||||
shownCounter++;
|
||||
label3.Text = shownCounter.ToString();
|
||||
}
|
||||
//Aktuelle Zeile markieren
|
||||
highLightALine(box_CodeView, PCounter, Color.Green);
|
||||
|
||||
instEinlesen.readExecCode(PCounter);
|
||||
}
|
||||
|
||||
private int getPCounter() {
|
||||
return PCounter;
|
||||
}
|
||||
|
||||
private void programmÖffnenToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Datei über openFileDialog1 Auswählen und in Anzeige öffnen
|
||||
FileStream fs;
|
||||
StreamReader sr;
|
||||
string zeile;
|
||||
|
||||
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
||||
{
|
||||
sr = new
|
||||
StreamReader(openFileDialog1.FileName);
|
||||
DialogResult = MessageBox.Show(sr.ReadToEnd(), "Programm Vorschau", MessageBoxButtons.OKCancel);
|
||||
sr.Close();
|
||||
// Abfrage von Ergebnis des Dialogs, wenn ja Datei laden
|
||||
if (DialogResult == DialogResult.OK)
|
||||
{
|
||||
fs = new FileStream(openFileDialog1.FileName, FileMode.Open);
|
||||
sr = new StreamReader(fs);
|
||||
|
||||
while (sr.Peek() != -1)
|
||||
{
|
||||
zeile = sr.ReadLine();
|
||||
box_CodeView.Text += zeile + "\n";
|
||||
}
|
||||
sr.Close();
|
||||
lbl_path.Text = openFileDialog1.FileName;
|
||||
|
||||
// StreamReader jede Zeile in Listenelement schreiben über Funktionsaufruf in der Klasse Einlesen
|
||||
|
||||
ArrayLaenge = instEinlesen.writeToArray(sr = new StreamReader(openFileDialog1.FileName));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void cmdOpenDoc_Click(object sender, EventArgs e)
|
||||
{
|
||||
string path = Application.StartupPath;
|
||||
MessageBox.Show( path);
|
||||
System.Diagnostics.Process.Start(@"C:\Users\nicol\Desktop\Projekte\PIC_Simulator\Projektinformationen\DataSheet.pdf");
|
||||
}
|
||||
|
||||
//Funktion um Zeile aktuell ausgeführte Zeile zu markieren
|
||||
void highLightALine(RichTextBox rtb, int line, Color hiLight)
|
||||
{
|
||||
int i1 = rtb.GetFirstCharIndexFromLine(line);
|
||||
int i2 = rtb.GetFirstCharIndexFromLine(line + 1);
|
||||
if (i2 < 0) i2 = rtb.Text.Length;
|
||||
|
||||
rtb.SelectionStart = i1;
|
||||
rtb.SelectionLength = i2 - i1;
|
||||
rtb.SelectionBackColor = hiLight;
|
||||
}
|
||||
|
||||
private void cmdSetClock_Click(object sender, EventArgs e)
|
||||
{
|
||||
timeIntervall = Convert.ToInt32(insertTime.Text);
|
||||
|
||||
}
|
||||
|
||||
private void cmd_reset_Click(object sender, EventArgs e)
|
||||
{ //######################### Muss ergänzt und getestet werden !!!
|
||||
// Hier müssen alle Werte wieder auf den Standard gesetzt werden!
|
||||
highLightALine(box_CodeView, PCounter, Color.White);
|
||||
PCounter = -1;
|
||||
label3.Text = PCounter.ToString();
|
||||
//######################### Muss ergänzt und getestet werden !!!
|
||||
}
|
||||
|
||||
|
||||
private void buildtbl_Register() {
|
||||
|
||||
}
|
||||
|
||||
private void beendenToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
this.Close();
|
||||
}
|
||||
|
||||
private void timer1_Tick(object sender, EventArgs e)
|
||||
{
|
||||
Einlesen QuarzExec = new Einlesen();
|
||||
|
||||
PCounter = PCounter + 1;
|
||||
label3.Text = PCounter.ToString();
|
||||
}
|
||||
|
||||
private void cmd_Stop_Click(object sender, EventArgs e)
|
||||
{
|
||||
timer1.Enabled = false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
using PIC_Simulator.PIC;
|
||||
using PIC_Simulator.Properties;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace PIC_Simulator
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
private PICProgramm programm;
|
||||
|
||||
private Timer quartztimer = new Timer();
|
||||
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
}
|
||||
|
||||
private void Form1_Load(object sender, EventArgs e)
|
||||
{
|
||||
box_CodeView.Font = new Font("Consolas", 8);
|
||||
|
||||
box_CodeView.Text = Resources.TPicSim1;
|
||||
|
||||
programm = new PICProgramm();
|
||||
programm.Laden(Resources.TPicSim1);
|
||||
}
|
||||
|
||||
private void cmd_Start_Click(object sender, EventArgs e)
|
||||
{
|
||||
quartztimer.Stop();
|
||||
quartztimer.Interval = int.Parse(insertTime.Text);
|
||||
quartztimer.Start();
|
||||
}
|
||||
|
||||
private void cmd_next_Click(object sender, EventArgs e)
|
||||
{
|
||||
StepProgramm();
|
||||
}
|
||||
|
||||
private void programmÖffnenToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (openFileDialog1.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
string datei = File.ReadAllText(openFileDialog1.FileName);
|
||||
|
||||
box_CodeView.Text = datei;
|
||||
|
||||
programm = new PICProgramm();
|
||||
programm.Laden(datei);
|
||||
}
|
||||
}
|
||||
|
||||
private void cmdOpenDoc_Click(object sender, EventArgs e)
|
||||
{
|
||||
string path = Path.GetTempFileName() + ".pdf";
|
||||
File.WriteAllBytes(path, Resources.DataSheet);
|
||||
System.Diagnostics.Process.Start(path);
|
||||
}
|
||||
|
||||
//Funktion um Zeile aktuell ausgeführte Zeile zu markieren
|
||||
void Highlight(int line)
|
||||
{
|
||||
int i1 = box_CodeView.GetFirstCharIndexFromLine(line);
|
||||
int i2 = box_CodeView.GetFirstCharIndexFromLine(line + 1);
|
||||
if (i2 < 0 || i1 < 0)
|
||||
{
|
||||
box_CodeView.SelectionColor = Color.Transparent;
|
||||
}
|
||||
else
|
||||
{
|
||||
box_CodeView.SelectionStart = i1;
|
||||
box_CodeView.SelectionLength = i2 - i1;
|
||||
box_CodeView.SelectionBackColor = Color.SteelBlue;
|
||||
}
|
||||
}
|
||||
|
||||
private void cmd_reset_Click(object sender, EventArgs e)
|
||||
{
|
||||
//TODO
|
||||
}
|
||||
|
||||
private void beendenToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
this.Close();
|
||||
}
|
||||
|
||||
private void timer1_Tick(object sender, EventArgs e)
|
||||
{
|
||||
StepProgramm();
|
||||
}
|
||||
|
||||
private void cmd_Stop_Click(object sender, EventArgs e)
|
||||
{
|
||||
quartztimer.Stop();
|
||||
}
|
||||
|
||||
private void StepProgramm()
|
||||
{
|
||||
bool finished = programm.Step();
|
||||
|
||||
if (finished) { quartztimer.Stop(); return; }
|
||||
|
||||
Highlight(programm.befehle[programm.PCCounter].zeilennummer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user