public void AddSerialPort(string portName, int baud, Parity parity, int databits, StopBits stopbits, Handshake hanshake) { SerialPortItem item = new SerialPortItem(); item.portName = portName; item.baud = baud; item.parity = parity; item.databits = databits; item.stopbits = stopbits; item.hanshake = hanshake; if (serialportArray == null) { serialportArray = new List <SerialPortItem>(); } serialportArray.Add(item); }
private bool PrepareTest() { SerialPortItem serialportMain = null; SerialPortItem serialportAUX = null; string goodreadpatt = ""; string noreadpatt = ""; string partialreadpatt = ""; string multiplereadpatt = ""; string phaseanalysispatt = ""; // setup log files if (logConfig.EnableLogging) { logger = new StreamWriter(logConfig.LoggingFolder + "\\" + logConfig.LogFileName, logConfig.AppendLogs); } if (configParams.TestGoodRead) { if (configParams.GoodRead_SerialMain_comPort != "Not used") { if (configParams.serialportArray != null) { serialportMain = configParams.serialportArray.Find(x => x.portName == configParams.GoodRead_SerialMain_comPort); } goodreadpatt = configParams.GoodRead_pattern; } if (configParams.GoodRead_SerialAUX_comPort != "Not used") { if (configParams.serialportArray != null) { serialportAUX = configParams.serialportArray.Find(x => x.portName == configParams.GoodRead_SerialAUX_comPort); } goodreadpatt = configParams.GoodRead_pattern; } } if (configParams.TestNoRead) { if (configParams.NoRead_SerialMain_comPort != "Not used") { if (configParams.serialportArray != null) { serialportMain = configParams.serialportArray.Find(x => x.portName == configParams.NoRead_SerialMain_comPort); } noreadpatt = configParams.NoRead_pattern; } if (configParams.NoRead_SerialAUX_comPort != "Not used") { if (configParams.serialportArray != null) { serialportAUX = configParams.serialportArray.Find(x => x.portName == configParams.NoRead_SerialAUX_comPort); } noreadpatt = configParams.NoRead_pattern; } } if (configParams.TestPartialRead) { if (configParams.PartialRead_SerialMain_comPort != "Not used") { if (configParams.serialportArray != null) { serialportMain = configParams.serialportArray.Find(x => x.portName == configParams.PartialRead_SerialMain_comPort); } partialreadpatt = configParams.PartialRead_pattern; } if (configParams.PartialRead_SerialAUX_comPort != "Not used") { if (configParams.serialportArray != null) { serialportAUX = configParams.serialportArray.Find(x => x.portName == configParams.PartialRead_SerialAUX_comPort); } partialreadpatt = configParams.PartialRead_pattern; } } if (configParams.TestMultipleRead) { if (configParams.MultipleRead_SerialMain_comPort != "Not used") { if (configParams.serialportArray != null) { serialportMain = configParams.serialportArray.Find(x => x.portName == configParams.MultipleRead_SerialMain_comPort); } multiplereadpatt = configParams.MultipleRead_pattern; } if (configParams.MultipleRead_SerialAUX_comPort != "Not used") { if (configParams.serialportArray != null) { serialportAUX = configParams.serialportArray.Find(x => x.portName == configParams.MultipleRead_SerialAUX_comPort); } multiplereadpatt = configParams.MultipleRead_pattern; } } if (configParams.TestPhaseAnalysis) { if (configParams.PhaseAnalysis_SerialMain_comPort != "Not used") { if (configParams.serialportArray != null) { serialportMain = configParams.serialportArray.Find(x => x.portName == configParams.PhaseAnalysis_SerialMain_comPort); } phaseanalysispatt = configParams.PhaseAnalysis_pattern; } if (configParams.PhaseAnalysis_SerialAUX_comPort != "Not used") { if (configParams.serialportArray != null) { serialportAUX = configParams.serialportArray.Find(x => x.portName == configParams.PhaseAnalysis_SerialAUX_comPort); } phaseanalysispatt = configParams.PhaseAnalysis_pattern; } } if (serialportMain != null) { serialPortMain = new SerialPortListener(serialportMain.portName, serialportMain.baud, serialportMain.parity, serialportMain.databits, serialportMain.stopbits, serialportMain.hanshake, logger); serialPortMain.SetPatterns(goodreadpatt, noreadpatt, partialreadpatt, multiplereadpatt, phaseanalysispatt); serialPortMain.GoodReadPatternFound += new EventHandler(OnSerialMainGoodReadPatternFound); serialPortMain.NoReadPatternFound += new EventHandler(OnSerialMainNoReadPatternFound); serialPortMain.PartialReadPatternFound += new EventHandler(OnSerialMainPartialReadPatternFound); serialPortMain.MultipleReadPatternFound += new EventHandler(OnSerialMainMultipleReadPatternFound); serialPortMain.OutOfOrderFound += new EventHandler(OnSerialMainOutOfOrderPhaseFound); serialPortMain.MissingFound += new EventHandler(OnSerialMainMissingPhaseFound); serialPortMainThread = new Thread(serialPortMain.ManageSerialPort); serialPortMainThread.Name = "SerialPortMainThread"; } if (serialportAUX != null) { serialPortAUX = new SerialPortListener(serialportAUX.portName, serialportAUX.baud, serialportAUX.parity, serialportAUX.databits, serialportAUX.stopbits, serialportAUX.hanshake, logger); serialPortAUX.SetPatterns(goodreadpatt, noreadpatt, partialreadpatt, multiplereadpatt, phaseanalysispatt); serialPortAUX.GoodReadPatternFound += new EventHandler(OnSerialAuxGoodReadPatternFound); serialPortAUX.NoReadPatternFound += new EventHandler(OnSerialAuxNoReadPatternFound); serialPortAUX.PartialReadPatternFound += new EventHandler(OnSerialAuxPartialReadPatternFound); serialPortAUX.MultipleReadPatternFound += new EventHandler(OnSerialAuxMultipleReadPatternFound); serialPortMain.OutOfOrderFound += new EventHandler(OnSerialAuxOutOfOrderPhaseFound); serialPortMain.MissingFound += new EventHandler(OnSerialAuxMissingPhaseFound); serialPortAUXThread = new Thread(serialPortAUX.ManageSerialPort); serialPortAUXThread.Name = "SerialPortAUXThread"; } if (configParams.TestGoodRead) { if (configParams.GoodRead_TCPClient_hostPort != 0) { int idx = GetTCPClient(configParams.GoodRead_TCPClient_hostPort); if (idx != -1) { tcpClientArray[idx].GoodreadPattern = configParams.GoodRead_pattern; tcpClientArray[idx].GoodReadPatternFound += new EventHandler(OnTCPClientGoodReadPatternFound); } } if (configParams.GoodRead_TCPServer_hostPort != 0) { int idx = GetTCPServer(configParams.GoodRead_TCPServer_hostPort); if (idx != -1) { tcpServerArray[idx].GoodreadPattern = configParams.GoodRead_pattern; tcpServerArray[idx].GoodReadPatternFound += new EventHandler(OnTCPServerGoodReadPatternFound); } } if (configParams.GoodRead_UDPServer_hostPort != 0) { int idx = GetUDPServer(configParams.GoodRead_UDPServer_hostPort); if (idx != -1) { udpServerArray[idx].GoodreadPattern = configParams.GoodRead_pattern; udpServerArray[idx].GoodReadPatternFound += new EventHandler(OnUDPServerGoodReadPatternFound); } } } if (configParams.TestNoRead) { if (configParams.NoRead_TCPClient_hostPort != 0) { int idx = GetTCPClient(configParams.NoRead_TCPClient_hostPort); if (idx != -1) { tcpClientArray[idx].NoreadPattern = configParams.NoRead_pattern; tcpClientArray[idx].NoReadPatternFound += new EventHandler(OnTCPClientNoReadPatternFound); } } if (configParams.NoRead_TCPServer_hostPort != 0) { int idx = GetTCPServer(configParams.NoRead_TCPServer_hostPort); if (idx != -1) { tcpServerArray[idx].NoreadPattern = configParams.NoRead_pattern; tcpServerArray[idx].NoReadPatternFound += new EventHandler(OnTCPServerNoReadPatternFound); } } if (configParams.NoRead_UDPServer_hostPort != 0) { int idx = GetUDPServer(configParams.NoRead_UDPServer_hostPort); if (idx != -1) { udpServerArray[idx].NoreadPattern = configParams.NoRead_pattern; udpServerArray[idx].NoReadPatternFound += new EventHandler(OnUDPServerNoReadPatternFound); } } } if (configParams.TestPartialRead) { if (configParams.PartialRead_TCPClient_hostPort != 0) { int idx = GetTCPClient(configParams.PartialRead_TCPClient_hostPort); if (idx != -1) { tcpClientArray[idx].PartialreadPattern = configParams.PartialRead_pattern; tcpClientArray[idx].PartialReadPatternFound += new EventHandler(OnTCPClientPartialReadPatternFound); } } if (configParams.PartialRead_TCPServer_hostPort != 0) { int idx = GetTCPServer(configParams.PartialRead_TCPServer_hostPort); if (idx != -1) { tcpServerArray[idx].PartialreadPattern = configParams.PartialRead_pattern; tcpServerArray[idx].PartialReadPatternFound += new EventHandler(OnTCPServerPartialReadPatternFound); } } if (configParams.PartialRead_UDPServer_hostPort != 0) { int idx = GetUDPServer(configParams.PartialRead_UDPServer_hostPort); if (idx != -1) { udpServerArray[idx].PartialreadPattern = configParams.PartialRead_pattern; udpServerArray[idx].PartialReadPatternFound += new EventHandler(OnUDPServerPartialReadPatternFound); } } } if (configParams.TestMultipleRead) { if (configParams.MultipleRead_TCPClient_hostPort != 0) { int idx = GetTCPClient(configParams.MultipleRead_TCPClient_hostPort); if (idx != -1) { tcpClientArray[idx].MultiplereadPattern = configParams.MultipleRead_pattern; tcpClientArray[idx].MultipleReadPatternFound += new EventHandler(OnTCPClientMultipleReadPatternFound); } } if (configParams.MultipleRead_TCPServer_hostPort != 0) { int idx = GetTCPServer(configParams.MultipleRead_TCPServer_hostPort); if (idx != -1) { tcpServerArray[idx].MultiplereadPattern = configParams.MultipleRead_pattern; tcpServerArray[idx].MultipleReadPatternFound += new EventHandler(OnTCPServerMultipleReadPatternFound); } } if (configParams.MultipleRead_UDPServer_hostPort != 0) { int idx = GetUDPServer(configParams.MultipleRead_UDPServer_hostPort); if (idx != -1) { udpServerArray[idx].MultiplereadPattern = configParams.MultipleRead_pattern; udpServerArray[idx].MultipleReadPatternFound += new EventHandler(OnUDPServerMultipleReadPatternFound); } } } if (configParams.TestHeartBeat) { if (configParams.HeartBeat_TCPClient_hostPort != 0) { int idx = GetTCPClient(configParams.HeartBeat_TCPClient_hostPort); if (idx != -1) { tcpClientArray[idx].HeartBeatPattern = configParams.HeartBeat_pattern; tcpClientArray[idx].HeartBeatPatternFound += new EventHandler(OnTCPClientHeartBeatPatternFound); } } if (configParams.HeartBeat_TCPServer_hostPort != 0) { int idx = GetTCPServer(configParams.HeartBeat_TCPServer_hostPort); if (idx != -1) { tcpServerArray[idx].HeartBeatPattern = configParams.HeartBeat_pattern; tcpServerArray[idx].HeartBeatPatternFound += new EventHandler(OnTCPServerHeartBeatPatternFound); } } if (configParams.HeartBeat_UDPServer_hostPort != 0) { int idx = GetUDPServer(configParams.HeartBeat_UDPServer_hostPort); if (idx != -1) { udpServerArray[idx].HeartBeatPattern = configParams.HeartBeat_pattern; udpServerArray[idx].HeartBeatPatternFound += new EventHandler(OnUDPServerHeartBeatPatternFound); } } } if (configParams.TestPhaseAnalysis) { if (configParams.PhaseAnalysis_TCPClient_hostPort != 0) { int idx = GetTCPClient(configParams.PhaseAnalysis_TCPClient_hostPort); if (idx != -1) { tcpClientArray[idx].GoodreadPattern = configParams.PhaseAnalysis_pattern; tcpClientArray[idx].SearchForPhaseIndex(configParams.PhaseAnalysis_pattern); tcpClientArray[idx].OutOfOrderPhaseFound += OnTCPClientOutOfOrderPhaseFound; tcpClientArray[idx].MissingPhaseFound += OnTCPClientMissingPhaseFound; } } } if (serialPortMainThread != null) { serialPortMainThread.Start(); } if (serialPortAUXThread != null) { serialPortAUXThread.Start(); } if (tcpClientPhaseAnalysisThread != null) { tcpClientPhaseAnalysisThread.Start(); } for (int i = 0; i < tcpServerArray.Length; i++) { if (tcpServerArray[i] != null) { tcpServerArray[i].Open(); } } for (int i = 0; i < udpServerArray.Length; i++) { if (udpServerArray[i] != null) { udpServerArray[i].Open(); } } return(true); }