Author Topic: PC serial Ports  (Read 1457 times)

larryhts

  • Jr. Member
  • **
  • Posts: 98
    • View Profile
PC serial Ports
« on: October 16, 2019, 07:52:01 AM »
I have a App that needs to read two serial numbers  from the PC serial ports and display in a text box. I am new to VB and can’t seem to get ports to write to the textbox’s. Any ideas on how to do this? I have all but this one machine running the scanners in to the PLC no trouble but PC port's not so sure how.

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: PC serial Ports
« Reply #1 on: October 16, 2019, 02:06:15 PM »
Google is your best friend but for now you can start here:

https://www.advancedhmi.com/forum/index.php?topic=1223.0

larryhts

  • Jr. Member
  • **
  • Posts: 98
    • View Profile
Re: PC serial Ports
« Reply #2 on: October 16, 2019, 03:03:12 PM »
Google is your best friend but for now you can start here:

https://www.advancedhmi.com/forum/index.php?topic=1223.0

Thanks Godra.   I have it working now.

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: PC serial Ports
« Reply #3 on: October 16, 2019, 03:08:05 PM »
Don't ever hesitate to post your working code.

It might inspire others and eventually help them in their projects.

larryhts

  • Jr. Member
  • **
  • Posts: 98
    • View Profile
Re: PC serial Ports
« Reply #4 on: October 17, 2019, 06:22:04 AM »
Godra,  That's a good idea.   
Here is the code I am using.

 Private Sub ReadCom(ByVal ReceiveSerialData() As String)
        ' Receive strings from a serial port.
        Dim returnStr As String = ""
        Dim com1 As IO.Ports.SerialPort

        ' Change this string for the port number
        com1 = My.Computer.Ports.OpenSerialPort("COM27")
        com1.ReadTimeout = 10000
            com1.Open()
        Dim Incoming As String = com1.ReadLine()

        returnStr &= Incoming '& vbCrLf
        If com1 IsNot Nothing Then TextBox1.Text = returnStr

    End Sub