I am new in C# and trying to develop windows form project of RS-485 water pressure sensor. From my code when I Write only one command of sensor and read, it works properly. But when I write all command and try to execute it is not working properly. In my code DatafromCOM is global variable with string value and in Timer I wrote a code for write sensor command. Can you please give me some solution for this I am trying to do this for one week and I can not found solution for this. My code is below
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
while (serialPort1.BytesToRead != 0)
{
DatafromCOM = serialPort1.ReadLine();
}
}
private void timer1_Tick(object sender, EventArgs e)
{
string cmdCurrent = "D0107012A0C";
string cmdCrntTW = "D0107022B4C";
string cmdVer = "D010703EB8D";
string cmdConf = "D01070429CC";
string cmdAdd = "D010705E90D";
string cmdCorr = "D020B10";
string cmdAvg = "D011011";
string cmdLvlCor = "D010B12";
string cmdGrvty = "D010B14";
serialPort1.Write(cmdCrntTW + NewLine);
serialPort1.Write(cmdVer + NewLine);
serialPort1.Write(cmdConf + NewLine);
serialPort1.Write(cmdAdd + NewLine);
serialPort1.Write(cmdCorr + NewLine);
serialPort1.Write(cmdCorr + NewLine);
serialPort1.Write(cmdAvg + NewLine);
serialPort1.Write(cmdAvg + NewLine);
serialPort1.Write(cmdLvlCor + NewLine);
serialPort1.Write(cmdGrvty + NewLine);
txtKQ.Text += DatafromCOM + Environment.NewLine;
}