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.Windows.Forms;
- using System.Runtime.InteropServices;
- using System.IO;
- namespace FinalPPl12_11
- {
- public partial class Form1 : Form
- {
- public int t2 = 0;
- public int t3 = 0;
- public int j;
- public int k;
- public int delay;
- //Call OutPut function from DLL file.
- [DllImport("inpout32.dll", EntryPoint = "Out32")]
- public static extern void Output(int adress, int value);
- //Call Input functionfrom DLL file
- [DllImport("inpout32.dll", EntryPoint = "Inp32")]
- public static extern int Input(int adress);
- public Form1()
- {
- InitializeComponent();
- counter3.Checked = true;
- delay1.Checked = true;
- cont.Enabled = false;
- FREEZ.Enabled = false;
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- /*******************************************************************************************/
- /**********************************BUTTONS**********************************/
- private void start_Click(object sender, EventArgs e)
- {
- start.Enabled = false;
- counter.Enabled = false;
- DELAY.Enabled = false;
- FREEZ.Enabled = true;
- j = -1;
- timer1.Interval = delay;
- timer1.Start();
- }
- private void close_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- private void controllow_Click(object sender, EventArgs e)
- {
- Output(0x37a, 0x00);
- }
- private void controlhigh_Click(object sender, EventArgs e)
- {
- Output(0x37a, 0x0f);
- }
- private void FREEZ_Click(object sender, EventArgs e)
- {
- timer1.Stop();
- cont.Enabled = true;
- }
- private void cont_Click(object sender, EventArgs e)
- {
- timer1.Start();
- }
- /****************************BUTTONS_END****************************/
- /*******************************************************************************************/
- /*******************************************************************************************/
- /****************************TIMER_MAIN_PROGRAM****************************/
- private void timer1_Tick(object sender, EventArgs e)
- {
- timer1.Stop();
- string directory = Directory.GetCurrentDirectory();
- int reg;
- int t1, c2;
- string fd = directory + "\\data.txt";
- loop:
- if (j < k)
- {
- reg = Input(0x37a);
- t1 = 0x04 & reg;
- c2 = t1 >> 2;
- if (j != -1)
- {
- if (c2 == 1 && t3 == 0)
- {
- t3 = 1;
- t2 = 1;
- string breach = Convert.ToString(DateTime.Now);
- FileStream f1 = new FileStream(fd, FileMode.Append);
- StreamWriter s1 = new StreamWriter(f1);
- s1.Write("\r\n controlsignal=1 at ");
- s1.Write(breach);
- s1.Write(" and the counter was ");
- s1.Write(Convert.ToString(j));
- //s1.Write(Convert.ToString(t3));
- s1.Close();
- }
- if (c2 == 0 && t2 == 1)
- {
- t2 = 0;
- t3 = 0;
- string breach = Convert.ToString(DateTime.Now);
- FileStream f1 = new FileStream(fd, FileMode.Append);
- StreamWriter s1 = new StreamWriter(f1);
- s1.Write("\r\n controlsignal returned to 0 at ");
- s1.Write(breach);
- s1.Write(" and the counter was ");
- s1.Write(Convert.ToString(j));
- s1.Close();
- }
- }
- j++;
- Output(0x378, j);
- string number = (j).ToString();
- string Binary = Convert.ToString(j, 2);
- DECIMAL.Text = number;
- BINARY.Text = Binary;
- if (j == k)
- {
- j = -1;
- }
- timer1.Start();
- }
- }
- /**********************************TIMER_END**********************************/
- /*******************************************************************************************/
- /*******************************************************************************************/
- /********************************COUNTER_CONTROLLER****************************/
- private void counter1_CheckedChanged(object sender, EventArgs e)
- {
- k = 10;
- }
- private void counter2_CheckedChanged(object sender, EventArgs e)
- {
- k = 128;
- }
- private void counter3_CheckedChanged(object sender, EventArgs e)
- {
- k = 255;
- }
- /****************************COUNTER_CONTROLLER_END****************************/
- /*******************************************************************************************/
- /*******************************************************************************************/
- /*******************************DELAY_CONTROLLER*******************************/
- private void delay1_CheckedChanged(object sender, EventArgs e)
- {
- delay = 300;
- }
- private void delay2_CheckedChanged(object sender, EventArgs e)
- {
- delay = 500;
- }
- private void delay3_CheckedChanged(object sender, EventArgs e)
- {
- delay = 1000;
- }
- /****************************DELAY_CONTROLLER_END****************************/
- /*******************************************************************************************/
- }
- }
Add Comment
Please, Sign In to add comment