1
votes

I know, someone of you, will give minus to me because of this title. But just listen and help please. If you show me the title same at my title, I will delete this topic. But I don't know how can I find the problem at here. I'm sorry because of my English.

I want to read and do some proccess with my reads from serialport into my circular buffer.

I can read serialport. İt's done at the DataReceived class.

I can set my serialport bytes into my circular buffer which I have downloaded here. But, I can not do any proccess with this buffer. For example, I take bytes from port like that:

0000F9:F0F0003044343A008453240000000F90000F9:F0F0002044789A008098740000000F90000F9:F0F0002114563A008225890000000F90000F9:F0

But I want to see it like that firstly:

0000F9    //discard this, because this data is lacking
:F0F0003044343A008453240000000F90000F9  //take this
:F0F0002044789A008098740000000F90000F9  //take this
:F0F0002114563A008225890000000F90000F9  //take this
:F0     //discard this because of lack

And secondly, I want to parse it like this;

: = start character
F0 = it means start the program
000 = Power of machine 
blablabla

At the end of this section, I want to show theese at my forms. So I want help for theese titles from you. Or anyone can show me the right asked question in this forum.

At first, I don't know how can I do a (global) public the circular buffer at the all of the program. When I define my buffer class at the data_received void like that,

var buffer = CircularBuffer<byte>(256);

I can use the buffer just in to dataReceived void. But I want to use this everywhere at the program. So, when I try to define it top of the my program.cs/main class like this:

var buffer = new CircularBuffer<byte>(256);

It, fails. I do not know how can I define it into my program. This was my first question.

Secondly, If I solve my first question, I must parse and control my buffer. First, I must verify my data stream. My serialport sends me 38 characters at the one data stream. My formulas is simple; every data stream must start with : and, must end with F9. Near the two character of F9 must be equals to sum of the some values of the middle data stream. So, I just want to know this, how can I procces with my circular buffer?

If anyone wants to see my codes, I can mail.

Thanks a lot from now.

1
Define your CircularBuffer as a field. It cannot be var, use the explicit type instead. I do not if you want it to be static. For your stream, being from serial does not make it diffent from handling any other stream. In your case you need to read it in fixed size chunks, append them together until you can verify what to discard and what to keep. I do not know why you want a circular buffer. I did not downvote. - Theraot
When I try define CircularBuffer as a field with this: CircularBuffer<byte>(256) buffer = new CircularBuffer(); it fails. Theese are fail messages: CircularBuffer<byte> is a type, but is used like a variable. fail at buffer word: ; expected - biyro2
Your type specification is incorrect. The type is CircularBuffer<byte> (look, the error message tells you that is the type), 256 is a value you pass to the constructor. Declare like this: CircularBuffer<byte> buffer = new CircularBuffer<byte>(256);. - Theraot
Hey, thans @Theraot! It works! - biyro2

1 Answers

1
votes

Firstly, I changed CircularBuffer class without static;

Secondly, I defined my buffer as global with this:

CircularBuffer<byte> buffer = new CircularBuffer<byte>(256);

Thirdly, I read my data stream into my buffer in a loop. I set a control is_full and is_empty in this loop.

Forthly I create a void which parse and calculate it. And have called into my loop. If anyone wants, I can mail the codes.

Thank you @Theraot for your help.