0

I searched online but could not find anything close to my problem. I have an simple application that communicates with a PCB via bluetooth . There is nothing fancy or different about this PCB. Just straight forward read and write to COM. The problem is When I send a command it receives and replies back to me. I can write to port perfectly but i do not receive anything back. COnnection and other things are all set, and good. if i use a terminal application to send/receive thru COM, everything works perfectly. I tried many ways to read from COM but I get 0 byte. please see below. Any idea?

port = new SafeSerialPort(portName, 115200, Parity.None, 8, StopBits.One);

port.Write(data, 0, data.Length);

Once I sent this I can see in the terminal application(realterm) the device receives(I use device's debug port to see it) it and responds back (I can send my data from a terminal application, and get my response back. But not from my application). I even increased write/read timesouts still did not work out.

I tried various things as seen below. still no hope. I set even a delay. still nothing returns. all these returns null:

port.Read(dataBuffer, 0, dataBuffer.Length);
char b = (char)port.ReadChar();
byte be = (Byte)port.ReadByte();
var response = port.ReadExisting();//nothing
int dataLengt = port.BytesToRead;//returns 0
Simon Mourier
  • 132,049
  • 21
  • 248
  • 298
James
  • 441
  • 2
  • 6
  • 9
  • What is that `SafeSerialPort` class? –  Mar 15 '18 at 23:47
  • What is a PCB? How is it connected to your serial port? – NetMage Mar 16 '18 at 00:09
  • SafeSerialPort : SerialPort and pcb is just a board which has COM ports on it. nothing is different than a computer really. straight forward COM read/write logic. Is there any reason why port may be prevented by receiving? by the way, when i close my application and open the port thru terminal application it pukes all of the reply commands. which means i can read them thru terminal but not thru application. – James Mar 16 '18 at 00:33
  • For troubleshooting purposes, replace SafeSerialPort with SerialPort to eliminate an unknown. SerialPort is a known class provided by the framework, whereas SafeSerialPort is...unknown. Second, check whether the terminal application speaks differently to your PCB than your C# app. Look for any additional/missing characters/bytes (such as line breaks, for example) that could cause the code in your controller (on the PCB) to not send data back. Just some ideas... –  Mar 16 '18 at 00:45

0 Answers0