//-SUB------------------------------------------------------------------------ // Event : frmMain_Activated //---------------------------------------------------------------------------- private void frmMain_Activated(object sender, EventArgs e) { // Let's have it called only once... if (bFormActivated == false) { bFormActivated = true; if (COMPort.Initialize(-1) != 0) { MessageBox.Show("No COM Port available!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { // Fill the COM combobox for (int nIndex = 0; nIndex < COMPort.nPorts; nIndex++) { cboCOMPort.Items.Add(COMPort.sPorts[nIndex]); } // Select the combobox index cboCOMPort.SelectedIndex = COMPort.nSelPort; // Close the serial port COMPort._serialport.Close(); // Enable the Start button btnStart.Enabled = true; } // end else } // end if } // end frmMain_Activated
} // end frmMain_Activated //-SUB------------------------------------------------------------------------ // Event : frmMain_FormClosing //---------------------------------------------------------------------------- private void frmMain_FormClosing(object sender, FormClosingEventArgs e) { // Make sure the COM port is open to receive the reset command COMPort.Initialize(cboCOMPort.SelectedIndex); // Reset the gateway jCOM1939.RESET_J1939(); // Close the COM port COMPort.Terminate(); }// end frmMain_FormClosing
}// end frmMain_FormClosing //-SUB------------------------------------------------------------------------ // Event : btnStart_Click //---------------------------------------------------------------------------- private void btnStart_Click(object sender, EventArgs e) { String fileName = "logs/JcomData" + DateTime.Now.ToString("MM-dd--hh-mm") + ".csv"; if (COMPort.Initialize(cboCOMPort.SelectedIndex) == 0) { timerLoop.Start(); // Enable/disable start/stop buttons btnStart.Enabled = false; btnStop.Enabled = true; // Enable further buttons btnRequestStatus.Enabled = true; btnClaimAddr.Enabled = true; btnAddFilter.Enabled = true; btnDelFilter.Enabled = true; loadLog.Enabled = true; TrLog.Enabled = true; // Reset the gateway jCOM1939.RESET_J1939(); nSrcAddr = 0; // Set the Request message filter jCOM1939.FA_J1939(PGNRequest); jCOM1939.FA_J1939(jCOM1939.FILTER_PASS_ALL); // Set the gateway mode jCOM1939.MM_J1939(jCOM1939.MSGMODE_GATEWAY2); dataFile = new StreamWriter(fileName); string header = "time , pgn , destination , source , priority , data,\n"; txtGatewayLog.Text = ""; dataFile.WriteLine(header); start = DateTime.Now; cmdFoundCount = 0; cmdsGotten.Text = "0"; foundCmd.Text = "0"; addr.Text = "0"; }// end if else { MessageBox.Show("Sorry! There is a problem with the COM port.", "Attention!"); } }// end btnStart_Click