

You C# software cannot access the same serial port the the hyperterminal is using so you would need a 2nd serial port on teh PC and a Null Modem whichwoould connect The hyperterminal in COMM mode is hard wired to the serial port connector on the PC. RtxtDataArea.AppendText(receivedData + "\n") RtxtDataArea.ForeColor = Color.Green //write text data in green String receivedData = serialPort1.ReadExisting() //read all available data in the receiving buffer Private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e) If (ComPort.IsOpen) ComPort.Close() //close the port if open when existing the application Private void Form1_FormClosing(object sender, FormClosingEventArgs e) this event will be raised when the form is closing. Private void btnSend_Click(object sender, EventArgs e) StringBuilder sb = new StringBuilder(data.Length * 3)

Private string ByteArrayToHexString(byte data) Returns a well formatted string of hex digits with spacing. The array of bytes to be translated into a string of hex didgits. Converts an array of bytes into a formatted string of hex digits (example: E1 FF 1B) Private byte HexStringToByteArray(string s)īuffer = (byte)Convert.ToByte(s.Substring(i, 2), 16) The string containing the hex digits (with or without spaces) convert a string of hex digits (example: E1 FF 1B) to a byte array. If (error) MessageBox.Show(this, "Not properly formatted hex string: " + txtSend.Text + "\n", "Format Error", MessageBoxButtons.OK, MessageBoxIcon.Stop) if there is an error yuor program will not display a message instead of freezing.Ĭatch (UnauthorizedAccessException) Try //always try to use this try and catch method to open your port. If (cmbPortName.SelectedIndex != -1 & cmbBaudeRate.SelectedIndex != -1 & cmbParity.SelectedIndex != -1 &ĬmbDataBits.SelectedIndex != -1 & cmbStopBits.SelectedIndex != -1)ĬomPort.BaudRate = int.Parse(cmbBaudeRate.Text) //convert Text to integerĬomPort.Parity = (Parity)Enum.Parse(typeof(Parity), cmbParity.Text) //convert text to parityĬomPort.DataBits = int.Parse(cmbDataBits.Text) //convert text to stop bitsĬomPort.StopBits = (StopBits)Enum.Parse(typeof(StopBits), cmbStopBits.Text) //convert text to stopbits check if all settings have been selected Private SerialPort ComPort = new SerialPort() //Initialise ComPort Variable as SerialPort String ports = SerialPort.GetPortNames() Retrieve the list of all COM ports on your computer UpdatePorts() //Call this function everytime the page load Private void Form1_Load(object sender, EventArgs e) I tried searching but to no avail, really need this help. Thanks!

I have these C# codes, but I want to let the C# to read through the HyperTerminal and send/receive data to the circuit.
