TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Nishikant Tayade
NA
22
8.4k
Serial port data into RIng Buffer
Jun 8 2018 12:48 AM
I am developing a desktop application for serial port communication.The hardware connected to serial port sends the data in packet.
But the numbers of bytes in that packet is unknown,hence use of ring buffer.
there is no default implementation of circular/Ring Buffer in C#,that's why i am using one provided on GitHub
https://github.com/xorxornop/RingBuffer/blob/master/PartiallyConcurrent/RingBuffer.cs
I want to save data into Ring Buffer as received and then parse it(like checking for header bytes,for device id,for status byte etc) and if it's not there then discard it.
I have tried various implementation but was unable to have a correct implementation.
Below is the code :
public
class
DataReceiveHandle
{
public
static
int
MAX_PACKET_LENGTH = ChannelDataCount.count;
public
static
bool
newData =
false
;
public
static
int
rxOffset = 0;
public
static
int
rxWrite = 0;
public
static
int
rxRead = 0;
public
static
byte
[] rxBuffer =
new
byte
[MAX_PACKET_LENGTH];
public
static
byte
[] rxPackage =
new
byte
[MAX_PACKET_LENGTH];
public
static
void
DataReceivedHandler(
object
sender, SerialDataReceivedEventArgs e)
{
if
(e.EventType != SerialData.Chars)
return
;
SerialPort port = (SerialPort)sender;
int
bytesCount = port.BytesToRead;
port.Read(rxBuffer, rxOffset, bytesCount);
SequentialRingBuffer rBuffer =
new
SequentialRingBuffer(4096, rxBuffer,
true
);
rxWrite=rBuffer.CurrentLength;
// rxOffset = rxOffset + bytesCount;
byte
[] tempArray =
new
byte
[256];
tempArray=rBuffer.ToArray();
foreach
(
byte
item
in
tempArray)
{
Console.WriteLine(item);
}
}
Can someone please provide an pseudo implementation of what should i do?
Reply
Answers (
0
)
crystal Report in Asp.Net
fill selectcommand.connection property has not beeninitializ