private void BtnConnectPortClick(object sender, EventArgs e) { try { string portName = settings.PLCBoardPortNumber.ToString(); SerialPortCommunicate serialPortCommunicate = new SerialPortCommunicate(); var result = serialPortCommunicate.Connect(portName, BAUD_RATE, PARITY, DATA_BITS, STOP_BITS); if (result) { lblSettingStatus.Text = "Port " + portName + " connected successfully"; lblSettingStatus.ForeColor = Color.Green; FileLogger.Log($"TDClient connected to port successfully"); } else { lblSettingStatus.Text = "Problem connecting to Port " + portName; lblSettingStatus.ForeColor = Color.Red; FileLogger.Log($"Connection of TDClient with port failed"); } serialPortCommunicate.RegisterVehicleEntryCallBack(HandleVehicleEntryData); } catch (Exception exception) { FileLogger.Log($"Connection of TDClient with port failed as : {exception.Message}"); } }
private void BtnConnectPortClick(object sender, EventArgs e) { string portName = txtPLCBoardPortNumber.Text; SerialPortCommunicate serialPortCommunicate = new SerialPortCommunicate(); int baudRate = Convert.ToInt32("9600"); Parity parity = (Parity)Enum.Parse(typeof(Parity), "None"); int dataBits = Convert.ToInt32("8"); StopBits stopBits = (StopBits)Enum.Parse(typeof(StopBits), "One"); serialPortCommunicate.Connect(portName, baudRate, parity, dataBits, stopBits); serialPortCommunicate.RegisterVehicleEntryCallBack(HandleVehicleEntryData); }