Hyperterminal and SerialPort comms problems

Have been through all the discussions about these 2 talking to each other, copied and played with code but cannot get any text sent to hyperterminal via the Serialport code in my form. Hyperterminal to Hyperterminal works ok and both have the same settings as shown with Serialport (COM1,9600,8,1,none) .

Code used is below : -

Imports System.Text

Imports System.IO.Ports

Public Class Form1

Dim WithEvents serial As New System.IO.Ports.SerialPort

Dim strtext As String = "&H1234"

Dim buffer As String

----------------------------------------------------------------------------------------------------------------------------

Private Sub cmdSend_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdStart.Click

Try

serial.Encoding = System.Text.Encoding.Default

'otherwise if you happen to send charcter above 127 ($7f) they will show up as

If Not serial.IsOpen Then serial.Open()

serial.DtrEnable = True

serial.PortName = "COM1"

serial.BaudRate = 9600

serial.Parity = IO.Ports.Parity.None

serial.StopBits = IO.Ports.StopBits.One

serial.DataBits = 8

serial.Handshake = IO.Ports.Handshake.None

serial.WriteLine(strText)

Catch ex As Exception

buffer = ex.Message

If serial.IsOpen Then serial.Close()

End Try

End Sub

Any advice (besides giving up) more than welcome.

Cheers,

steve



Answer this question

Hyperterminal and SerialPort comms problems

  • EyalMSDN

    When I attempt to send a .txt from hyperterminal to the vb app it appears to hang on the serial.readline statement.

    Questions I think I need answering are :-

    When sending the text file, should the vb app already be waiting for input in the do loop(action on a button click event)

    Is a serial.newline statement required to determine data being sent

    If it is and the data changes, do I need a different newline statement to mimic the last character sent

    I have tried readExisting etc as well with no luck.

    Any thoughts please.


  • Brian Seekford

    Have your tried setting all of the serial port parameters BEFORE you open it

    Ed


  • Srimurugan G

    Sure have, makes no difference, wish it was that simple to solve. Have tried different combinations of reading and writing text files from/to hyperterminal all to no avail.

    Does anyone have an idiots guide to connecting between the two apps perphaps I.m expecting things to happen in the wrong sequence

    I have hyperterminal set to zmodem with crash recovery is this correct

    I have also tried sending a text file from hyperterminal with the following code in my vb app as :-

    Private Sub cmdSend_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdStart.Click

    Try

    serial.Encoding = System.Text.Encoding.Default

    'otherwise if you happen to send charcter above 127 ($7f) they will show up as

    serial.DtrEnable = True

    serial.PortName = "COM1"

    serial.BaudRate = 9600

    serial.Parity = IO.Ports.Parity.None

    serial.StopBits = IO.Ports.StopBits.One

    serial.DataBits = 8

    serial.Handshake = IO.Ports.Handshake.None

    If Not serial.IsOpen Then serial.Open()

    ' serial.Open()

    Do

    Dim Incoming As String = serial.ReadLine()

    If Incoming Is Nothing Then

    Exit Do

    Else

    MessageBox.Show(Incoming)

    End If

    Loop

    Catch ex As Exception

    buffer = ex.Message

    If serial.IsOpen Then serial.Close()

    End Try


  • Hyperterminal and SerialPort comms problems