Reputation: 23
I am working on making GUI for a Smart Water flow meter whose communication protocol is RS485, as per instructions from Communication Manual i am sending an inquiry packet and i am receiving proper response in serial port terminal. But when i am trying to do it on my C# app. Things are happening oppositely.
string data = "[H201815000081]";
private void button1_Click(object sender, EventArgs e)
{
serialPort1.Write(data);
incoming_data = serialPort1.ReadExisting();
text_reciever.Text = incoming_data;
}
// text_reciver is the text box of my gui where i want to display the
// values from flow meter.Data Type of incoming_data is string
Here is the code, i am sending an inquiry code to the device and in return i am getting garbage values on my text box. Some times it is stream of Question mark symbol (?), some time it shows nothing. But when i revert myself to serial port terminal (Real Term). It is showing proper values as mentioned in communication manual. Please assist in this regards.
Upvotes: 0
Views: 914
Reputation: 23
After looking around i just found the answer to my question. The point is previously i was communicating with serial port teminal, where everything was working fine, but when it comes to interacting with peripherals one need to make sure that Serialport.DTRProperty is enabled. When opening the serial port one must enable the DTR property by:
serialPort1.DtrEnable = true;
Otherwise the windows form will read the garbage value.
Upvotes: 0
Reputation: 1
the incoming data would be serial number of device (ASCII Format) and Water flow values
Upvotes: -1