Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- namespace USB_GUI_Template_0
- {
- public partial class Form1 : Form
- {
- // alles was hier deklariert kann auf allen Ebenen verwendet werden
- // Simulation Ausgabe
- private Label[] Simulation = new Label[8];
- // Blinklicht
- private Timer TimerBlinklicht = new Timer();
- private int counter = 0;
- private bool blinkStatus = false;
- // Lauflicht
- private Timer TimerLauflicht = new Timer();
- private int LauflichtPosition = 0;
- private bool Lauflichtstatus = false;
- public Form1()
- {
- InitializeComponent();
- //Array für Simulation Items belegen
- Simulation[0] = labDigOut1;
- Simulation[1] = labDigOut2;
- Simulation[2] = labDigOut3;
- Simulation[3] = labDigOut4;
- Simulation[4] = labDigOut5;
- Simulation[5] = labDigOut6;
- Simulation[6] = labDigOut7;
- Simulation[7] = labDigOut8;
- //TimerBlinklicht intervall + timer_tick deklarieren
- TimerBlinklicht.Interval = 500; // in ms
- TimerBlinklicht.Tick += new EventHandler(TimerBlinklicht_Tick); // wird ausgeführt nach ablauf Intervallzeit
- //TimerLauflicht intervall + timer_tick deklarieren
- TimerLauflicht.Interval = 500;
- TimerLauflicht.Tick += new EventHandler(TimerLauflicht_Tick);
- }
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Simulation Ausgabe
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- private void SimClearAllDigital()
- { // Simulation Ausgabe: alle Digitalen Ausgänge löschen
- for (int x = 0; x < Simulation.Length; x++)
- {
- Simulation[x].BackColor = Color.White;
- }
- }
- private void SimSetAllDigital()
- {// Simualtion Ausgabe : alle Digitalen Ausgänge setzten
- for (int x = 0; x < Simulation.Length; x++)
- {
- Simulation[x].BackColor = Color.Yellow;
- }
- }
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- ///
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- private void butVerbinden_Click(object sender, EventArgs e)
- {
- if ( UsbPInvokeWrapper.OpenDevice(0) == 0 )
- {
- MessageBox.Show("Verbindung ok", "USB-Board-Status", MessageBoxButtons.OK);
- }
- else
- {
- MessageBox.Show("Keine Verbindung möglich", "USB-Board-Status", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- ///
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- private void butAn_Click(object sender, EventArgs e)
- {
- //Simulation Ausgabe
- SimSetAllDigital();
- //USB-Board
- UsbPInvokeWrapper.SetAllDigital();
- }
- private void butLöschen_Click(object sender, EventArgs e)
- {
- //Simulation Ausgabe
- SimClearAllDigital();
- //USB-Board
- UsbPInvokeWrapper.ClearAllDigital();
- }
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Blinklicht
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- private void butBlinklicht_Click(object sender, EventArgs e)
- {
- butLauflicht.Enabled = false;
- //Simulation Ausgabe
- SimClearAllDigital();
- //USB-Board
- UsbPInvokeWrapper.ClearAllDigital();
- //
- if (butBlinklicht.Enabled == true)
- {
- TimerBlinklicht.Start(); // startet timer und läuft durchgehend bis timer.stopp()
- }
- else
- {
- // wenn counter == 5 , timer stoppen, Lampe aus, counter=0 setzen;
- TimerBlinklicht.Stop();
- blinkStatus = false;
- //Simulation Ausgabe
- SimClearAllDigital();
- //USB-Board
- UsbPInvokeWrapper.ClearAllDigital();
- counter = 0;
- // Button Lauflicht wieder auf true setzen
- butLauflicht.Enabled = true;
- }
- }
- private void TimerBlinklicht_Tick(object sender, EventArgs e)
- {
- // Zähler für 5 mal Blinken anlegen
- if (counter >= 5)
- {
- // wenn counter == 5 , timer stoppen, Lampe aus, counter=0 setzen;
- TimerBlinklicht.Stop();
- blinkStatus = false;
- //Simulation Ausgabe
- SimClearAllDigital();
- //USB-Board
- UsbPInvokeWrapper.ClearAllDigital();
- counter = 0;
- // Button Lauflicht wieder auf true setzen
- butLauflicht.Enabled = true;
- }
- else if (blinkStatus == false)
- {
- blinkStatus = true;
- //Simulation Ausgabe
- SimSetAllDigital();
- //USB-Board
- UsbPInvokeWrapper.SetAllDigital();
- //
- counter++;
- }
- else
- {
- blinkStatus = false;
- //Simulation Ausgabe
- SimClearAllDigital();
- //USB-Board
- UsbPInvokeWrapper.ClearAllDigital();
- }
- }
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Lauflicht
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- private void butLauflicht_Click(object sender, EventArgs e)
- {
- butBlinklicht.Enabled = false;
- //Simulation Ausgabe
- SimClearAllDigital();
- //USB-Board
- UsbPInvokeWrapper.ClearAllDigital();
- TimerLauflicht.Start();
- }
- private void TimerLauflicht_Tick(object sender, EventArgs e)
- {
- if (LauflichtPosition >= 8)
- {
- // wenn counter == 5 , timer stoppen, Lampe aus, counter=0 setzen;
- TimerLauflicht.Stop();
- Lauflichtstatus = false;
- //Simulation Ausgabe
- SimClearAllDigital();
- //USB-Board
- UsbPInvokeWrapper.ClearAllDigital();
- LauflichtPosition = 0;
- // Button Blinklicht wieder auf true setzen
- butBlinklicht.Enabled = true;
- }
- else if (Lauflichtstatus == false)
- {
- Lauflichtstatus = true;
- Simulation[LauflichtPosition].BackColor = Color.Yellow;
- //USB-Board
- UsbPInvokeWrapper.SetDigitalChannel(LauflichtPosition+1);
- LauflichtPosition++;
- }
- else
- {
- Lauflichtstatus = false;
- //Simulation Ausgabe
- Simulation[LauflichtPosition-1].BackColor = Color.White;
- //USB-Board
- UsbPInvokeWrapper.ClearDigitalChannel(LauflichtPosition);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement