2

I am trying to make a program that allows me to control the Arduino to send out a HIGH signal to turn my motor and there will be a feedback through serial that tells me that the motor has been moved.

My problem is that I am unable to get any feedback from the Arduino. These are my code snippets.

SerialPort serialComms;
Select_Arduino.IsEnabled = false;
serialComms = new SerialPort(Port_Name.SelectedItem.ToString(), Convert.ToInt32(Baud_Rate.SelectedItem.ToString()));
serialComms.DtrEnable = true;
serialComms.DataReceived += serialComms_DataReceived;

void serialComms_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
    SamsungTV.Text = SamsungTV.Text + "\n" + e.ToString();
}

The program totally does not enter serialComms_DataReceived. Is there any way for me to receive the feedback?

The feedback is as so "The motor has been moved 15 degrees counter-clockwise."

3 Answers 3

2

You need to call serialComms.Open()

Sign up to request clarification or add additional context in comments.

1 Comment

I did that, just in a seperate function. I realised it works only once cause my serialComms automatically stops by itself when it completes a single turn.
1

Usually when I use the event handler for recieving messages through the Serial port I do something like this...

void serialComms_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
     String testing = serialComs.ReadLine(); // Also, I use the Serial.println(arg) command from the arduino in order to simplify the syntax a little bit..
     SamsungTV.Text = testing + "\n";
}

I hope that this helps in some way!

Comments

0

Here is my solution:

using System.IO.Ports;

private void Read()
{
   SerialPort myport = new SerialPort();

   myport = new SerialPort();
   myport.BaudRate = 9600;
   myport.PortName = "COM3";

   myport.Open();
   string data = myport.ReadLine();

   myport.Close();
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.