I am new to C # and am trying to develop a draft window shape for the RS-485 water pressure sensor. From my code, when I write only one sensor command and read, it works correctly. But when I write the whole command and try to execute it, it does not work correctly. In my code, DatafromCOM is a global variable with a string value, and in Timer I wrote code for the write sensor command. Can you give me some solution for this, I try to do it in one week, and I can not find a 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;
}
source
share