Problem with Baudrate change-over after establishing connecting

1 viestiä / 0 new
Uusin kirjoitus
SisyB
Problem with Baudrate change-over after establishing connecting

I am new to C#Sharp and i am developing a program to read or program energy meter via serial port.I connect to the meter at 300 baudrate and do initial handshake
At this stage i can connect to the meter after initial /?!<CR>LF> command.The problem i have is when i am attempting to send the ACK command together with baudrate change-over.
I am suppose to send this command(to the meter) withing 1.5s of receiving identification message from the meter and i can 'ACK' within the set limits but struggling with changing form 300 read mode(00) to 9600 (051) mode....."<ACK>051<CR>LF>"
i have tried to close the port (Comport.Close) and set new baud rate(Comport.Baudrate=9600) but it doesn't work.My code looks as below
ComPort.DiscardInBuffer(); // clearing buffer form Dump Mode
ComPort.RtsEnable = false;
ComPort.DtrEnable = false;
ComPort.Close();
await UseDelay();
//then set new settings
ComPort.BaudRate = 9600;// new baudrate
if (ComPort.IsOpen==false)
{
ComPort.DataReceived += new SerialDataReceivedEventHandler(DataReceived);
ComPort.Open(); }

await UseDelay();
ComPort.RtsEnable = true;
ComPort.DtrEnable = true;
byte[] ack = new byte[] {0X06,0X30,0X35,0x30,0X0D,0X0A};
//MessageBox.Show(DataReceived);
ComPort.Write(ack, 0, ack.Length);
}
Can you help me please.
Thank you in advance.

SisyB