//constructor public Transfer(ActiveSerialPort currentConnection) { this.serialPort = currentConnection.activeSerial; Console.WriteLine(serialPort.ReadTimeout); Console.WriteLine(serialPort.WriteTimeout); serialPort.ReadTimeout = 10000; Console.WriteLine(serialPort.ReadTimeout); }
private void findPortWithLoopBack() { //close the current port closePortAction(); //make a generic port for this test ActiveSerialPort testport = new ActiveSerialPort(); toolStripProgressBar1.Visible = true; //cycle through the serial ports and find one that returns the same thing that was sent for (int openPort = 0; openPort < comboBoxPortName.Items.Count; openPort++) { toolStripProgressBar1.Value = (int)(((float)(openPort + 1) / (float)comboBoxPortName.Items.Count) * 100); try { comboBoxPortName.SelectedIndex = openPort; testport.createBasicSerialPort(currentPortName, currentBaudRate, ASCII); //send the port name as a string and check the response testport.sendData(currentPortName, endline); safeSleep(this.timeoutMS); String response = testport.readData(); if (response.Contains(currentPortName)) {//port found MessageBox.Show("Loopback on: " + currentPortName, "Port Found", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk); testport.closeSerialPort(); openPortAction(); break; } else { testport.closeSerialPort(); } } catch (Exception) { //throw; } } toolStripProgressBar1.Visible = false; }
private Boolean openPortBasic() { try { currentConnection = new ActiveSerialPort(); if (currentConnection.createBasicSerialPort(currentPortName, currentBaudRate, ASCII)) { currentConnection.DataReadyToRead += serialPortDataReadyToRead; Console.Write("\n" + currentPortName + "\n"); Console.Write(currentBaudRate + "\n"); return portOpen = true; } else { return portOpen = false; } } catch (Exception) { return portOpen; } }
private Boolean openPort() { try { currentConnection = new ActiveSerialPort(); if (currentConnection.openSerialPort(currentPortName, currentBaudRate, currentParity, currentDataBits, currentStopBits, timeoutMS, ASCII, portReadTimeout)) { currentConnection.DataReadyToRead += serialPortDataReadyToRead; Console.Write("\n" + currentPortName + "\n"); Console.Write(currentBaudRate + "\n"); return portOpen = true; } else { return portOpen = false; } } catch (Exception) { return portOpen; } }