0

Is that possible? Checking if the port is open is okay but i don't know why i can't receive data/string after i sent a data.

In main Form:

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    connect_btn.Enabled = False
    With com1
        .PortName = "COM2"
        .BaudRate = 9600
        .Parity = Parity.None
        .StopBits = StopBits.One
        .DataBits = 8
        .Handshake = Handshake.RequestToSend
        .RtsEnable = True
        .DtrEnable = True
    End With
    com1.Open()
    AddHandler RFID.DataReceived, SerialDataReceivedEventHandler1
 End Sub

Sending Data:

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    Dim response As String = TextBox1.Text
    If RFID.IsOpen Then
        RFID.WriteLine(response)
    End If
End Sub

Data Receive:

    Private Sub com1_DataReceived(sender As Object, e As IO.Ports.SerialDataReceivedEventArgs)
    If com1.IsOpen = True Then
        read()
    End If
End Sub

Friend Sub DataReceived(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs)
    Dim newReceivedData As String
    newReceivedData = RFID.ReadExisting
    MessageBox.Show(newReceivedData)
End Sub

When i try to run it, There is no error.

EDITED

Using PuTTY and VSPE work to send a data.

mrgx
  • 35
  • 1
  • 7
  • So you are probably not receiving anything. That's [not unusual](https://stackoverflow.com/a/8910167/17034). – Hans Passant Oct 08 '17 at 15:10
  • @HansPassant Thanks for your reply. I used VSPE and i added 2 Serial Port(COM2, COM3). Installed PuTTY and connect in COM3. Then in my code i used COM2 as Serial Port name. I can send a string but when i connect COM1 there is no received or no string display in PuTTY. – mrgx Oct 09 '17 at 09:09
  • If Putty doesn't receive any data then of course your program won't either. Use a telephone, call the device distributor or manufacturer to ask for help. – Hans Passant Oct 09 '17 at 09:17
  • @HansPassant Sorry. My program and PuTTy is not receiving any data when i connet COM1 in PuTTy and in my program i use COM2. – mrgx Oct 09 '17 at 09:34
  • Can you show the code for `SerialDataReceivedEventHandler1`? That is the Sub that should be called if you receive data. The two that you posted don't seem to be wired up. Place a breakpoint in the code to see if they get called. – Chris Dunaway Oct 09 '17 at 14:05

0 Answers0