Circularbuffer Using Mathod?

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

Post Reply
seokgi
Posts: 164
Joined: Fri Jan 13, 2012 4:21 am
Location: South KOREA
Has thanked: 18 times
Been thanked: 16 times
Contact:

Circularbuffer Using Mathod?

Post by seokgi »

I am working on a project to receive data from an electronic scale. Data is output via RS-232. I transmit through MODBUS.
Receive RS-232 data using CIRCULARBUFFER.
When I get on the PC

"ST, NT, -0010.30kg"

It comes out this way repeatedly. However, if the data rate is over 100ms, the data will be broken. I want to search Circularbuffer and accept only numbers before "kg". I tried Circularbuffer's LookForValue function but it did not work well.

Waiting for help.
Thank you.
Attachments
20190509_200748.png
(20.72 KiB) Downloaded 995 times
20190509_200941.png
(78.15 KiB) Downloaded 995 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Circularbuffer Using Mathod?

Post by Benj »

Hello,

Please can you attach your program, screenshots are useful but it means if someone wants to help you they basically have to start again from scratch rather than simply editing your file.

seokgi
Posts: 164
Joined: Fri Jan 13, 2012 4:21 am
Location: South KOREA
Has thanked: 18 times
Been thanked: 16 times
Contact:

Re: Circularbuffer Using Mathod?

Post by seokgi »

My Program

seokgi
Posts: 164
Joined: Fri Jan 13, 2012 4:21 am
Location: South KOREA
Has thanked: 18 times
Been thanked: 16 times
Contact:

Re: Circularbuffer Using Mathod?

Post by seokgi »

Thank you for your attention.

My Program
Attachments
PRT2COM.fcfx
(49.87 KiB) Downloaded 184 times

chipfryer27
Valued Contributor
Valued Contributor
Posts: 657
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 184 times
Been thanked: 203 times
Contact:

Re: Circularbuffer Using Mathod?

Post by chipfryer27 »

Hi

Sorry, still on my travels so I can't see your FC file nor do I have access to my own files regarding receiving from RS-232 and storing in the CB.

However from your .png I am a bit confused.

I assume that the first is your interrupt handling routine for an interrupt on RxInt and that you wish to store the incoming byte(s) in the CB.

The first component macro assigns the variable Recive_Char to the value of the byte received. The second component macro then stores the value of Recive_Char in the next available space in the CB (and increments pointer). You now have the value of Recive_Char in the CB (but at this point you don't know where in the CB).

You then have a decision based on a counter(?) OR the value of Recive_Char but I can't comment on this as I can't download your program to see the whole picture, however in the "No" branch you have a comment "Store the byte into the circular buffer". Now the confusion. The byte has already been stored in the CB before the decision. You then appear to read the contents of the CB and store it in another array called Buffer1 then increment a counter so perhaps the comment is a "typo" and you wish to store Recive_Char in Buffer1?

I don't know your entire circuit nor program but the GetByte command retrieves the value at the next available location within the CB. How do you know where the pointer is and that the next byte is the one your require? If another interrupt came in (for example) would it handle that before completing this or what?

I don't know your application but can you ensure that only valid data can be received over the RS232? Do you need to capture a single byte and act upon it or do you need to capture a number of bytes and act upon them?

Late last year I received help on something that may be of some small help to you.

I needed to transmit three individual bytes of data (using the UART component). These bytes were not of fixed value and could be of any reasonable value but importantly were a sequence that meant something. Therefore I could not look for any specific byte using the LookForValue component of the circular buffer by itself. The solution that worked for me was to send a "packet" of information. This packet contained a keyword immediately followed by the three bytes of interest before a terminating byte. The keyword and termination byte were of fixed values and would not change but the data between would (think start byte(s), data, stop byte).

In my RxInt handling routine I limited it to purely receiving incoming data and storing it in the buffer. In the routine (if memory serves me well) I had:-

Loop
Rx=Uart1::ReceiveChar(15)
CirculerBuffer1::PutByte(Rx)
Loop (until Rx=0)

When called the macro looped filling the buffer with the received data until the transmission completed (please note that the timeout value of 15 used in my example is just an example value).

In my Main body I would use the CB LookForValue to test the buffer to determine if my packet was present or not. Of course my packet would not be the same every time as the data within would vary so I would test for the presence of both my "keyword" string and the termination byte before processing. Testing for both ensures that you don't process before a transmission completes nor if an accidental "termination byte" was received (possibly by corrupted transmission).

The LookForValue doesn't tell you where in the buffer it finds the value, just that it is present, so I created a loop using the CB GetByte.

If my keyword was "key", and my data was D1, D2 and D3 followed by a CR then I would test for both the presence of "key" and "CR". If found I would loop progressing through the buffer using GetByte until "k", "e" and "y" were found (in that order). After "y" I assumed the next three bytes would be my D1, D2 and D3 values. These were obtained by assigning the value returned in the next three GetByte iterations to the variables. After "D3", If the next GetByte returned "CR" then I would commit the D1,D2 and D3 values.

I appreciate a Flowchart would be easier to understand but hopefully you might find the above of interest. Once my travels complete I will download your file to a machine running FC and see if I can be of any help.

Regards

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Circularbuffer Using Mathod?

Post by Benj »

Hello,

You seem to be calling Flush Buffer a lot in your program.

Also inside the comms RX interrupt you add the data byte to the circular buffer and then almost immediatley in the same macro you pull the value out again. This will stop the LookForValue working correctly.

Post Reply