I am communicating via PC with RS232 cable.
Data received by me: ?\u0011\u0001\u0012?
Sending back this incoming code I need to run the led but when I post the code there is no effect. How can I return this code, which comes in Unicode UTF-8?
private void btnGonder_Click(object sender, EventArgs e) //Send Button
{
try
{
if (serialPort1 == null)
{
MessageBox.Show("Please check your COM port.");
}
else
{
string strToUni = txtSendedCommand.Text;
byte[] buf = System.Text.Encoding.Unicode.GetBytes(strToUni);
serialPort1.Write(buf, 0, buf.Length);
// var decoded = System.Text.Encoding.Unicode.GetString(buf);
// txtReceived.Text = decoded;
txtSendedCommand.Clear();
lstBxDurum.Items.Add("Data is Send.");
}
}
catch
{
lstBxDurum.Items.Add("WARNİNG!Data Not Send.");
}
}
Data Receive Code
private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
string newLine = Environment.NewLine;
string buffer = "";
buffer=serialPort1.ReadExisting();
txtReceived.Text = txtReceived.Text +buffer ;
txtReceived.Text = txtReceived.Text + serialPort1.ReadExisting();
txtReceived.Select(txtReceived.Text.Length, 0);
}