i am trying to connect with a temp sensor that use ASCII commands ... when i use arduino serial monitor to test commands the sensor respond well, but when i try to use C# i get different ressult.
Through arduino serial monitor (all great):
The command that i use: ?2T
The sensor Respond: !2T0501.3
where "!2T" is a response confirmation and "0501.3" is the actual temperature meassure.
But when i use C# (problem):
The command that i use: ?2T\r "because i need the carriage return"
The sensor Respond: i??X?Y?K5
i think that is a very basic format problem but i kind of new in C# and i don't know how to fix it.
What I have tried:
public Form1()
{
InitializeComponent();
serialPort1.Open();
serialPort1.ReadTimeout = 500;
timer1.Interval = 1000;
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
if (!serialPort1.IsOpen)
serialPort1.Open();
serialPort1.Write("?2T\r");
Task.Delay(50);
textBox1.Text = serialPort1.ReadLine();
}
private void button1_Click(object sender, EventArgs e)
{
serialPort1.DiscardOutBuffer();
serialPort1.DiscardInBuffer();
serialPort1.BaseStream.Dispose();
serialPort1.Close();
this.Close();
}