Hello Community,
Why I the port I'm trying to read looking really weired. I'm using an Arduino to produce the port data (It just has two button inputting "BUTTONONE" and "BUTTONTWO" when pressed).

This is the result I'm getting:
BUTTONTWO
BUTTONTWO
BUTTONTWO
BUTTONTWO
BUTTONTWO
BUTTONTWO
BUTTONTWO
BUTTONTWO

BUTTONTWO
BUTTONONE
BUTTONONE
BUTTONONE

BUTTONONE

BUTTONONE
BUTTONONE
BUTTONONE
BUTTONONE

BUTTONONE
BUTTONONE
BUTTONONE
BUTTONONE
BUTTONONE

BUTTONONE
BUTTONONE
BUTTONONE
BUTTONTWO
BUTTONTWO

I don't know why it's got all the gaps bettween the button press inputs.

Are you using an interpreter on your Arduino? If not, then this should be posted in the C++ forum.

Also, you will have to post your code the application if you wish for us to help find your problem! :)

I posted this here because I'm using VB.NET to read the code.and I'll post the code when I get home as I'm away from my computer.

This is the code on the Arduino:

int buttonOnePin = 2;
int buttonTwoPin = 3;

void setup() {
  Serial.begin(9600);
  pinMode(buttonOnePin, INPUT);
  pinMode(buttonTwoPin, INPUT);
}

void loop() {
  if (digitalRead(buttonOnePin) == HIGH) {
    Serial.println("BUTTONONE");
  }
  if (digitalRead(buttonTwoPin) == HIGH) {
    Serial.println("BUTTONTWO");
  }
}

And this is the code from the VB.NET program:

Public Class Main
    Dim WithEvents SerialPort As New IO.Ports.SerialPort

    Private Sub Form1_ForeColorChanged(sender As Object, e As EventArgs) Handles Me.ForeColorChanged
        SerialPort.Close()
    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ConnectSerial()
    End Sub

    Private Sub ConnectSerial()
        Try
            SerialPort.BaudRate = 9600
            SerialPort.PortName = "COM3"
            SerialPort.Open()
        Catch
            SerialPort.Close()
        End Try
    End Sub

    Delegate Sub myMethodDelegate(ByVal [text] As String)
    Dim myD1 As New myMethodDelegate(AddressOf myShowStringMethod)

    'Private Sub myShowStringMethod(ByVal myString As String)
    '    Text = myString
    '    If myString = "BUTTONONE" & System.Environment.NewLine Then
    '        BUTTONONE()
    '    End If
    '    If myString = "BUTTONTWO" & System.Environment.NewLine Then
    '        BUTTONTWO()
    '    End If
    'End Sub

    'Private Sub BUTTONONE()
    '    ListBox1.Items.Add("Button one was pressed.")
    'End Sub

    'Private Sub BUTTONTWO()
    '    ListBox1.Items.Add("Button two was pressed.")
    'End Sub

    Sub myShowStringMethod(ByVal myString As String)
        ListBox1.Items.Add(myString)
    End Sub

    Private Sub SerialPort_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort.DataReceived
        Dim str As String = SerialPort.ReadExisting()
        Invoke(myD1, str)
    End Sub
End Class

Sorry for the hiatus.

Have you checked to verify if the correct number of BUTTONX Outputs exists?

For example, press button one 3 times then press button two 3 times.

Or is the output returning empty string on some of the button presses?

No I'm just pressing them once, but the weired thing is it doesn't happen in the Arduino IDE serial monitor, it just seems to happen in VB.NET.

It kind of doesn't matter now because I've just decided to go with another script I found on the internet that seem to work ok but it still is inserting new lines in mid port read eg.

BUTT
ONONE
instead of just
BUTTONONE

But I've just gones with inserting them into a dimed Textbox then just checking if the textbox endwith the button I'm looking for. So it's not what I was hoping for, but at least it's working.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.