Click here to Skip to main content
15,919,774 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
What shall i do for serial port communication to receive bytes properly
Posted

Your Question is not Clear.., Give me more details where your exactly getting problem ..,

GO through the below for DataReceive Handler

Here[^]
 
Share this answer
 
Comments
yeshgowda 18-Mar-11 1:14am    
means iam expecting 47 bytes but it receives only 24 bytes in Serial port.BytesToRead.i have added baudrate =9600,databits=8,parity=none,stopbits=one, particular portname.or writing and reading is slow in serial port
Sergey Alexandrovich Kryukov 18-Mar-11 23:28pm    
It simply means that 24 bytes are actually sent. It has nothing to do with baudrate and other parameters (which should of cause match). The remaining bytes might come later, or never, as guided by the logic of the device. Best way is to read all you have in buffer in raw bytes and analyze as you receive them.
--SA
Rajesh Anuhya 18-Mar-11 1:20am    
May your problem with the encoding of your serialport. change your serialport encoding to UTF-8 encoding to receive extended ascii characters.
Rajesh Anuhya 18-Mar-11 1:22am    
use the below code..

SerialPort ser = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);
ser.Encoding = Encoding.UTF8;
yeshgowda 18-Mar-11 2:16am    
i have used encoding.UTF8 but it doesn't work.i have used device and simulator using serial port.device will send 47 bytes but in simulator i have used serialport.BytesToRead to read bytes from device but in simulator it reads only 24 bytes based on tht it performs execution but at nxt time device will send next bytes .but in serialport.BytesToRead the remaining 23bytes+other bytes send will be received and performs operation but it is wrong.how can i do in serialport to read all 47 bytes at one slot and perform operation.and bytes are getting appended how can i clear in serialport.and other thing is bytes 47 is an example not always 47 bytes is received it will vary based on input .i should wait till all bytes received and perform operation how can i accompalish?? -this is through loop back cable.but when i does through virtual com port it is working fine.but i need to do through loopback cable
You can use:

string msg = comPort.ReadExisting();
 
Share this answer
 
I had a similar issue and had to swtich to ReadChar() line below where localSerial is a string.


localSerial += (Char)CommPort.ReadChar();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900