added new class files

git-svn-id: file:///srv/dev-disk-by-uuid-17e88007-4d0c-45e0-8757-cacfcc458630/repositories/svn/Diplomarbeit@102 9fe90eed-be63-e94b-8204-d34ff4c2ff93
This commit is contained in:
Matthias
2009-01-09 16:15:13 +00:00
parent 45ebac0bd5
commit 7921d3bb2a
3 changed files with 586 additions and 0 deletions
@@ -0,0 +1,176 @@
/* ---------------------------------------------------------------------------
* Master.cs (c) 2009 Micro-key bv
* ---------------------------------------------------------------------------
* Micro-key bv
* Industrieweg 28, 9804 TG Noordhorn
* Postbus 92, 9800 AB Zuidhorn
* The Netherlands
* Tel: +31 594 503020
* Fax: +31 594 505825
* Email: support@microkey.nl
* Web: www.microkey.nl
* ---------------------------------------------------------------------------
* Description: This file handles all Actions of the "Test" Group
* ---------------------------------------------------------------------------
* Version(s): 0.1, Jan 08, 2009, MMi
* Creation.
* ---------------------------------------------------------------------------
*/
/* ---------------------------------------------------------------------------
* System use files
* ---------------------------------------------------------------------------
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.IO.Ports;
using System.Threading;
/* ---------------------------------------------------------------------------
* Local function definitions
* ---------------------------------------------------------------------------
*/
namespace QUA_2475_designtest
{
public partial class mainWindow
{
private void T_MasterInput_TextChanged(object sender, EventArgs e)
{
/* Copy input text from textbox to string */
MasterInputString = T_MasterInput.Text;
}
private void T_MasterInput_KeyDown(object sender, KeyEventArgs e)
{
/* if ENTER is pressed, then */
if (e.KeyCode == Keys.Enter)
{
/* Attach CR to String and send it to Device */
com1.Write(MasterInputString + "\r");
T_MasterInput.Text = ""; /* reset TextBox */
}
}
private void B_master_send_Click(object sender, EventArgs e)
{
/* Attach CR to String and send it to Device */
com1.Write(MasterInputString + "\r");
T_MasterInput.Text = ""; /* reset Textbox */
}
delegate void CheckForSlaveKeywordCallback(string text);
private void CheckForSlaveKeyword(string text)
{
/* Check if calling function is in same Thread as T_SlaveOutput */
if (this.T_MasterOutput.InvokeRequired)
{
/* Calling Function is in different Thread
* Handle Parameter to Slave Thread
*/
CheckForSlaveKeywordCallback d = new CheckForSlaveKeywordCallback(CheckForSlaveKeyword);
this.Invoke(d, new object[] { text });
}
else
{
/* Calling Function is in same Thread */
/* Search for Text fragments in Input String */
if (text.LastIndexOf("test: PASSED") != -1)
{
/* "test: PASSED" indecates that Device successfully
* finished a Test Script or Routine
*/
activeTest = false;
TestResult[actualTest] = true;
TestIsPassed(actualTest);
}
if (text.LastIndexOf("test: FAILED") != -1)
{
/* "test: FAILED" indecates that Device finished
* a Test Script or Routine with Errors
*/
activeTest = false;
TestResult[actualTest] = false;
TestIsFailed(actualTest);
}
}
}
delegate void AddSlaveTextCallback(string text);
private void AddSlaveText(string text)
{
/* Check if calling function is in same Thread as T_SlaveOutput */
if (this.T_MasterOutput.InvokeRequired)
{
/* Calling Function is in different Thread
* Handle Parameter to Slave Thread
*/
AddSlaveTextCallback d = new AddSlaveTextCallback(AddSlaveText);
this.Invoke(d, new object[] { text });
}
else
{
/* Calling Function is in same Thread */
/* Attach incoming Text to T_SlaveOutput and scroll
* to bottom End of TextBox
*/
text = text.Replace("\n\r", Environment.NewLine);
T_MasterOutput.Text += text;
T_MasterOutput.Select(T_MasterOutput.Text.Length, 0);
T_MasterOutput.ScrollToCaret();
}
}
private void com1_DataReceived()
{
/* This function runs in an own Thread.
* Slave_receiveMessages is type boolean and initialised as
* TRUE. With setting it to FALSE, the Stream Input can be
* stopped
*/
while (Master_receiveMessages)
{
/* Read out length of current Input Stream */
int nrOfBytes;
nrOfBytes = com1.BytesToRead;
/* as long as there is active Input Stream */
while (nrOfBytes > 0)
{
/* Attach every incoming CHAR to char-Array */
char[] buffer = new char[nrOfBytes];
com1.Read(buffer, 0, nrOfBytes);
/* Send Array to TextBox handle */
this.AddSlaveText(new string(buffer));
/* If a test is active, then */
if (activeTest == true)
{
/* Copy all incoming Data to TestMessage of
* corresponding Test and send the String afterwards
* to CehckForKeyword to find specific Keyword
*/
CheckForSlaveKeyword(new string(buffer));
//TestMessage[actualTest] += new string(buffer);
//CheckForSlaveKeyword(TestMessage[actualTest]);
}
nrOfBytes = com1.BytesToRead; /* Actualise Inputlength*/
}
/* Set Thread to Sleep as long as possible (managed by System)
* to give parallel Threads calculation Time
*/
Thread.Sleep(10);
}
}
}
}
@@ -0,0 +1,164 @@
/* ---------------------------------------------------------------------------
* Initialisation.cs (c) 2009 Micro-key bv
* ---------------------------------------------------------------------------
* Micro-key bv
* Industrieweg 28, 9804 TG Noordhorn
* Postbus 92, 9800 AB Zuidhorn
* The Netherlands
* Tel: +31 594 503020
* Fax: +31 594 505825
* Email: support@microkey.nl
* Web: www.microkey.nl
* ---------------------------------------------------------------------------
* Description: This file handles all Inits, variable definitions and start
* Values of arrays.
* ---------------------------------------------------------------------------
* Version(s): 0.1, Jan 08, 2009, MMi
* Creation.
* ---------------------------------------------------------------------------
*/
/* ---------------------------------------------------------------------------
* System use files
* ---------------------------------------------------------------------------
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.IO.Ports;
using System.Threading;
/* ---------------------------------------------------------------------------
* Local function definitions
* ---------------------------------------------------------------------------
*/
namespace QUA_2475_designtest
{
public partial class mainWindow
{
/* PORT DEFINITION */
private SerialPort com1 = new SerialPort(); /* Define type COM1 */
/* THREAD DEFINITION */
Thread com1GetMessage; /* COM1 Read Thread */
//Thread com6GetMessage; /* COM2 Read Thread */
Thread TestTimeoutThread; /* Test Timeout Thread */
/* INTEGER DEFINITION */
const int NrOfTests = 15; /* Indicates number of single Test */
uint actualTest = 0; /* Indicates number of actual Test */
uint TotalTestNumber = 1; /* Number of total Tests */
uint TotalPassedNumber = 1; /* Number of passed Tests */
uint TotalFailedNumber = 1; /* Number of failed Tests */
uint testcnt = 0;
/* BOOLEAN DEFINITION */
private bool Master_receiveMessages = true; /* Allow COM2 to read */
private bool activeTest = false; /* Indicates an active Test */
private bool activeAutomatictest = false; /* autoTest is active */
/* ARRAY DEFINITION */
/* Array of all available Textboxes for Tests */
public TextBox[] TestTextBoxes = new TextBox[NrOfTests];
/* Array for all single Test call commands */
public string[] TestCallCommands = new string[NrOfTests];
/* Array for absolut path and file names of Tests */
public string[] Testfiles = new string[NrOfTests];
/* Array to contain each Test Result */
public bool[] TestResult = new bool[NrOfTests];
private string MasterInputString; /* bound to T_MasterInput */
/* ENUM TYPE DEFINITION */
/* Enumeration for single Tests. With these numbers, all information
* for each test is callable. Usable e.g. as ArrayIndex for Arrays
* listed above.
*/
public enum TestType
{
MB_LED = 0,
MB_EEPROM = 1,
ETH1 = 2,
ETH0 = 3,
CF = 4,
USB = 5,
MB_DIO = 6,
MB_AIO = 7,
MB_RLY = 8,
CAN = 9,
EB_LED = 10,
EB_EEPROM = 11,
EB_DIO = 12,
EB_AIO = 13,
EB_RLY = 14
};
public void initialise()
{
com1.PortName = "COM1"; /* Bind com1 to COM1 */
com1.Open(); /* Open com1 */
com1.BaudRate = 115200; /* Set com1 Baudrate */
/* Capture corresponding Textboxes to TextBox Array */
TestTextBoxes[(int)TestType.MB_LED] = T_test_MB_LED;
TestTextBoxes[(int)TestType.MB_EEPROM] = T_test_MB_EEPROM;
TestTextBoxes[(int)TestType.ETH1] = T_test_eth1;
TestTextBoxes[(int)TestType.ETH0] = T_test_eth0;
TestTextBoxes[(int)TestType.CF] = T_test_CF;
TestTextBoxes[(int)TestType.USB] = T_test_USB;
TestTextBoxes[(int)TestType.MB_DIO] = T_test_MB_DIO;
TestTextBoxes[(int)TestType.MB_AIO] = T_test_MB_AIO;
TestTextBoxes[(int)TestType.MB_RLY] = T_test_MB_RLY;
TestTextBoxes[(int)TestType.CAN] = T_test_CAN;
TestTextBoxes[(int)TestType.EB_LED] = T_test_EB_LED;
TestTextBoxes[(int)TestType.EB_EEPROM] = T_test_EB_EEPROM;
TestTextBoxes[(int)TestType.EB_DIO] = T_test_EB_DIO;
TestTextBoxes[(int)TestType.EB_AIO] = T_test_EB_AIO;
TestTextBoxes[(int)TestType.EB_RLY] = T_test_EB_RLY;
/* Reset all Test Results */
TestResult[0] = false;
TestResult[1] = false;
TestResult[2] = false;
TestResult[3] = false;
TestResult[4] = false;
TestResult[5] = false;
TestResult[6] = false;
TestResult[7] = false;
TestResult[8] = false;
TestResult[9] = false;
TestResult[10] = false;
TestResult[11] = false;
TestResult[12] = false;
TestResult[13] = false;
TestResult[14] = false;
/* Define Commands (path and filename) for test-script calls */
TestCallCommands[0] = "ledtest 2\r";
TestCallCommands[1] = "eeprom 2\r";
TestCallCommands[2] = "\r";
TestCallCommands[3] = "\r";
TestCallCommands[4] = "\r";
TestCallCommands[5] = "\r";
TestCallCommands[6] = "dio 2\r";
TestCallCommands[7] = "\r";
TestCallCommands[8] = "\r";
TestCallCommands[9] = "\r";
TestCallCommands[10] = "\r";
TestCallCommands[11] = "\r";
TestCallCommands[12] = "\r";
TestCallCommands[13] = "\r";
TestCallCommands[14] = "\r";
/* Define and start com1 reading Thread */
com1GetMessage = new Thread(new ThreadStart(com1_DataReceived));
com1GetMessage.Start();
}
}
}
@@ -0,0 +1,246 @@
/* ---------------------------------------------------------------------------
* test_control.cs (c) 2009 Micro-key bv
* ---------------------------------------------------------------------------
* Micro-key bv
* Industrieweg 28, 9804 TG Noordhorn
* Postbus 92, 9800 AB Zuidhorn
* The Netherlands
* Tel: +31 594 503020
* Fax: +31 594 505825
* Email: support@microkey.nl
* Web: www.microkey.nl
* ---------------------------------------------------------------------------
* Description: This file handles all Actions of the "Test" Group
* ---------------------------------------------------------------------------
* Version(s): 0.1, Jan 08, 2009, MMi
* Creation.
* ---------------------------------------------------------------------------
*/
/* ---------------------------------------------------------------------------
* System use files
* ---------------------------------------------------------------------------
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.IO.Ports;
using System.Threading;
/* ---------------------------------------------------------------------------
* Local function definitions
* ---------------------------------------------------------------------------
*/
namespace QUA_2475_designtest
{
public partial class mainWindow
{
private void TestIsUntested(System.UInt32 TestID)
{
/* Resets the to the parameter corresponding Textbox */
TestTextBoxes[TestID].Text = "untested";
TestTextBoxes[TestID].BackColor = System.Drawing.Color.White;
}
private void TestIsActive(System.UInt32 TestID)
{
/* Sets status of the corresponding TextBox to active */
TestTextBoxes[TestID].Text = "Active";
TestTextBoxes[TestID].BackColor = System.Drawing.Color.Yellow;
}
private void TestIsPassed(System.UInt32 TestID)
{
/* Sets status of the corresponding TextBox to a passed test */
TestTimeoutThread.Abort(); /* Abort Timeout Thread */
TestTextBoxes[TestID].Text = "Passed";
TestTextBoxes[TestID].BackColor = System.Drawing.Color.Green;
/* If Test was called by automatic test routine, go back there */
if (activeAutomatictest == true)
{
//automaticTest();
}
}
private void TestIsFailed(System.UInt32 TestID)
{
/* Sets status of the corresponding TextBox to a failed test */
TestTimeoutThread.Abort(); /* Abort Timeout Thread */
TestTextBoxes[TestID].Text = "Failed";
TestTextBoxes[TestID].BackColor = System.Drawing.Color.Red;
/* If Test was called by automatic test routine, go back there */
if (activeAutomatictest == true)
{
//automaticTest();
}
}
private void TestIsUnavailable(System.UInt32 TestID)
{
/* Sets status of the corresponding TextBox to unreachable test */
TestTimeoutThread.Abort(); /* Abort Timeout Thread */
TestTextBoxes[TestID].Text = "unavailable";
TestTextBoxes[TestID].BackColor = System.Drawing.Color.CornflowerBlue;
/* If Test was called by automatic test routine, go back there */
if (activeAutomatictest == true)
{
//automaticTest();
}
}
delegate void TestIsTimeoutCallback(System.UInt32 TestID);
private void TestIsTimeout(System.UInt32 TestID)
{
/* Check if Application is called from a subThread */
if (this.TestTextBoxes[TestID].InvokeRequired)
{
/* Handle Parameters to main Thread */
TestIsTimeoutCallback d = new TestIsTimeoutCallback(TestIsTimeout);
this.Invoke(d, new object[] { TestID });
}
else
{
/* Set corresponding TextBox to Timeout Status */
TestTextBoxes[TestID].Text = "Timeout";
TestTextBoxes[TestID].BackColor = System.Drawing.Color.DarkOrange;
activeTest = false;
/* If Test was called by automatic test routine, go there */
if (activeAutomatictest == true)
{
//automaticTest();
}
}
}
private void B_test_MB_LED_Click(object sender, EventArgs e)
{
/* CallTestRoutine corresponding TestResult with Parameter */
CallTestRoutine((int)TestType.MB_LED);
}
private void B_test_MB_EEPROM_Click(object sender, EventArgs e)
{
/* CallTestRoutine corresponding TestResult with Parameter */
CallTestRoutine((int)TestType.MB_EEPROM);
}
private void B_test_eth0_Click(object sender, EventArgs e)
{
/* CallTestRoutine corresponding TestResult with Parameter */
CallTestRoutine((int)TestType.ETH0);
}
private void B_test_eth1_Click(object sender, EventArgs e)
{
/* CallTestRoutine corresponding TestResult with Parameter */
CallTestRoutine((int)TestType.ETH1);
}
private void B_test_CF_Click(object sender, EventArgs e)
{
/* CallTestRoutine corresponding TestResult with Parameter */
CallTestRoutine((int)TestType.CF);
}
private void B_test_USB_Click(object sender, EventArgs e)
{
/* CallTestRoutine corresponding TestResult with Parameter */
CallTestRoutine((int)TestType.USB);
}
private void B_test_MB_DIO_Click(object sender, EventArgs e)
{
/* CallTestRoutine corresponding TestResult with Parameter */
CallTestRoutine((int)TestType.MB_DIO);
}
private void B_test_MB_AIO_Click(object sender, EventArgs e)
{
/* CallTestRoutine corresponding TestResult with Parameter */
CallTestRoutine((int)TestType.MB_AIO);
}
private void B_test_MB_RLY_Click(object sender, EventArgs e)
{
/* CallTestRoutine corresponding TestResult with Parameter */
CallTestRoutine((int)TestType.MB_RLY);
}
private void B_test_CAN_Click(object sender, EventArgs e)
{
/* CallTestRoutine corresponding TestResult with Parameter */
CallTestRoutine((int)TestType.CAN);
}
private void B_test_EB_LED_Click(object sender, EventArgs e)
{
/* CallTestRoutine corresponding TestResult with Parameter */
CallTestRoutine((int)TestType.EB_LED);
}
private void B_test_EB_EEPROM_Click(object sender, EventArgs e)
{
/* CallTestRoutine corresponding TestResult with Parameter */
CallTestRoutine((int)TestType.EB_EEPROM);
}
private void B_test_EB_DIO_Click(object sender, EventArgs e)
{
/* CallTestRoutine corresponding TestResult with Parameter */
CallTestRoutine((int)TestType.EB_DIO);
}
private void B_test_EB_AIO_Click(object sender, EventArgs e)
{
/* CallTestRoutine corresponding TestResult with Parameter */
CallTestRoutine((int)TestType.EB_AIO);
}
private void B_test_EB_RLY_Click(object sender, EventArgs e)
{
/* CallTestRoutine corresponding TestResult with Parameter */
CallTestRoutine((int)TestType.EB_RLY);
}
private void B_test_clear_Click(object sender, EventArgs e)
{
/* If no Test is Active: */
if (activeTest == false)
{
/* Reset all Test TextBoxes to untested status */
for (uint loopcnt = 0; loopcnt < NrOfTests; loopcnt++)
{
T_MasterOutput.BackColor = System.Drawing.Color.White;
TestIsUntested(loopcnt);
}
}
}
private void CallTestRoutine(uint TestID)
{
/* Call Test just if no other Test is active */
if (activeTest == false)
{
actualTest = TestID; /* Set actual Test ID to active Test*/
/* Define and Start Timeout Thread */
TestTimeoutThread = new Thread(new ThreadStart(TimeoutThread));
TestTimeoutThread.Start();
activeTest = true; /* Set Test to global active */
com1.Write(TestCallCommands[actualTest]); /* Call Test */
TestIsActive(actualTest); /* Set Test TextBox */
}
}
}
}