I am trying to read data from optical port of electricity meter. I connect the probe attached to the optical port of the meter to the computer via RS232. I am sending the initial data to the electricity meter as follows. The answer should be the ID of the electricity meter.
SerialPort sp = new SerialPort("COM4");
sp.BaudRate = 9600;
sp.Parity = Parity.None;
sp.StopBits = StopBits.One;
sp.DataBits = 7;
sp.Handshake = Handshake.None;
sp.DtrEnable = true;
sp.RtsEnable = true;
sp.DataReceived += SerialDataReceivedEventHandler;
sp.Open();
sp.WriteLine("/?!");
Console.Read();
sp.Close();
When I try with the ReadExisting() method, I get the following response.
SerialPort seri = (SerialPort)sender;
Console.WriteLine(seri.ReadExisting());
When I try with the Read() method, I get the following response.
SerialPort srlport = (SerialPort)sender;
const int bufSize = 12;
Byte[] buf = new Byte[bufSize];
Console.WriteLine("Data Received!!!");
int bytes_read = srlport.Read(buf, 0, bufSize);
Console.WriteLine("Bytes read: " + bytes_read);
Console.WriteLine("Content:\n" + String.Join(" ", buf));
I need to get an ID like "/MSY5<1>C520.KMY.2556" from the electricity meter. Where am I doing wrong? I would be grateful if you help. Best regards.