Receiving Serial Monitor Data on PC

I have a Uno controlling a model railway. I'd like to get data that the Uno receives from sensors - train detectors etc - and display the data on my Windows 10 PC using Visual Basic 6. I have looked at numerous posts and found one that seems to work, but I have to stop Arduino using Com3 and set the MsComm control in VB to use Com3. Is there a way that the PC can see whet the UNO is sending to the Serial Monitor?
Here is the VB code I'm using:

Private Sub Form_Load()
Form1.Caption = "App2"
' set arduino com port to 1
         With MSComm1
         .CommPort = 3
            .Handshaking = 2 - comRTS
            .RThreshold = 1
            .RTSEnable = True
            .Settings = "9600,n,8,1"
            .SThreshold = 1
          
            .PortOpen = True
            ' Leave all other settings as default values.
         End With
         Text1.Text = ""
End Sub

  Private Sub Form_Unload(Cancel As Integer)
         MSComm1.PortOpen = False
      End Sub

Private Sub MSComm1_OnComm()
 Dim InBuff As String

         Select Case MSComm1.CommEvent
         ' Handle each event or error by placing
         ' code below each case statement.

         ' This template is found in the Example
         ' section of the OnComm event Help topic
         ' in VB Help.

         ' Errors
            Case comEventBreak   ' A Break was received.
            Case comEventCDTO    ' CD (RLSD) Timeout.
            Case comEventCTSTO   ' CTS Timeout.
            Case comEventDSRTO   ' DSR Timeout.
            Case comEventFrame   ' Framing Error.
            Case comEventOverrun ' Data Lost.
            Case comEventRxOver  ' Receive buffer overflow.
            Case comEventRxParity   ' Parity Error.
            Case comEventTxFull  ' Transmit buffer full.
            Case comEventDCB     ' Unexpected error retrieving DCB]

         ' Events
            Case comEvCD   ' Change in the CD line.
            Case comEvCTS  ' Change in the CTS line.
            Case comEvDSR  ' Change in the DSR line.
            Case comEvRing ' Change in the Ring Indicator.
            Case comEvReceive ' Received RThreshold # of chars.
               InBuff = MSComm1.Input
               Call HandleInput(InBuff)
            Case comEvSend ' There are SThreshold number of
                           ' characters in the transmit buffer.
            Case comEvEOF  ' An EOF character was found in the
                           ' input stream.
         End Select

      End Sub

      Sub HandleInput(InBuff As String)
         ' This is where you will process your input. This
         ' includes trapping characters, parsing strings,
         ' separating data fields, etc. For this case, you
         ' are simply going to display the data in the TextBox.
         Text1.SelStart = Len(Text1.Text)
         Text1.SelText = InBuff
End Sub

If I don't stop Arduino using Com3, the code fails when it executes
.PortOpen = True
because it says the port is already open.
Any help would be appreciated.
Thanks

Please tell us what you mean with "stop Arduino".
I suspect you're referring to Arduino IDE and its Serial monitor, right? In this case you can't open the COM port on more than one application: either use the Serial Monitor or Visual Basic (or any other application used to open serial ports).
Close the Serial Monitor when running your VB application.

PS: are you really still working with VB6? I'm old enough to know it (I'm 65...), but why don't you switch to VB.NET or C#?

You are aware that you don't need to have the Arduino IDE open when using your VB application. Once you have loaded a program to your Arduino board using the Arduino IDE, it will live there forever (till you overwrite it).

So if your Arduino code is completed, that is your first option.

Only one application at a time can use a serial port. If you want to split the received data to different applications you need an application that listens to the ports and sends it to virtual ports; the other applications need to connect to one of those virtual ports. That's the second option.

I'm aware of one such application for Windows for splitting and that is com0com; never used it myself.

Thanks for your quick replies. I was hoping VB could read the data in "parallel" with the IDE during development. I suppose I could just use VB to 'talk' to the Uno - send commands to start and stop trains etc. But I know what to do now. I'm using VB6 because I've being using VB for 30+ years and I don't see the need to go through the process of learning another language - I looked at converting to VB studio but that's like learning Chinese if you already know German! :grinning_face:Thanks again.

You can leave the IDE connected and use software serial on the Uno to communicate with your PC VB terminal. So you can do it in parallel.

You can always implement a simple terminal in your VB application. Data received by your app can be displayed in text boxes, control check boxes etc as well as in a multi-line text box to show the actual received "raw" data.

Note
Not familiar with VB6 so the terminology used above might not apply.

You can also, with a bit of wiring, use a separate serial port and a simple terminal app to eavesdrop on the communications.
I do this to monitor my RS485 CMRI communications between Arduino nodes and JMRI, if you're familiar with those acronyms.

1 Like

All OK now. Thanks.

USB to TTL UART RS232 Serial Converter Module PL2303HXA - if I connect this to two pins on the UNO, I should be able to use a separate USB port on the PC to send data to VB and from VB to the UNO - presumably there's some software somewhere to generate the necessary serial data? Thanks

Take a look at using the SoftwareSerial library on two pins of your choice other than 0 and 1

Thanks. Just one question - how do I get the data from the two pins on the board to a USB port on the PC? Presumably the UNO has hardware to do that for the built-in USB port. Is a UART what I need? My knowledge of UARTs is a bit rusty but I thought you loaded a character into an 8-bit buffer in the UART then raised a SEND bit.

see post #5

Thanks Jim. The issue now is how to get the data from the UNO pins to the USB/COM port on the PC. I see the UNO has a chip that does the conversion for its built-in USB port. So I need hardware to do the same. My PC doesn't have a serial port, only USB ports.

You need a USB to TTL converter/adaptor
Like this one or similar

I have this one but you need to solder on the headers

Thanks Jim. I've sourced the FTDI locally (I live in Sydney, Australia).

So you just need to connect the RX, TX and GND pins.

FTDI      Uno
RX   <--  TX (software serial pin)
TX   -->  RX (software serial pin)
GND  --   GND

Thanks Jim.

I have purchased an FT232RL board. Is this OK to connect a UNO to a PC COM port via USB so the Uno can send data to, and receive data from, a PC running Visual Basic? I think I have to install some software on the PC, and presumably the Uno will need some code to send and receive with its new serial port. Thanks

Use the Uno's USB to communicate with the IDE.

If you only want to receive data in your VB application you can connect the Tx of the Uno to the FTDI and connect the FTDI to the PC; you will use the FTDI's USB port in your VB application. No software changes needed.

If your VB application needs to be able to talk (send) to the Arduino as well you can use SoftwareSerial (on two other pins), connect the FTDI's Tx and Rx to those specified pins) and your VB application can both receive and send on the FTDI's USB port. In that case you need software modifications in the Arduino code.

You don't need additional software except for the FTDI driver.

Note:
SoftwareSerial is not reliable above 19200 baud.

Thanks. I'll give it a try. Do I set the 2 pins I use to connect to the FTDI as pinMode(12, INPUT_PULLUP) , pinMode(13, OUTPUT)?