Circularbuffer Getbyte get out wrong data position

Any bugs you encounter with Flowcode should be discussed here.
lucibel
Posts: 172
http://meble-kuchenne.info.pl
Joined: Thu Sep 23, 2021 3:44 pm
Location: France
Has thanked: 29 times
Been thanked: 22 times

Circularbuffer Getbyte get out wrong data position

Post by lucibel »

Hi,
In my current program I already noticed a problem but I thought it was bad programming on my side, so I bypassed the problem.
I was making a small new program to test it before to include it my curent prog.
I saw that there is a problem with Circularbuffer GetByte()
As you can see, there is 10 data in the buffer and the first on is 56
data in buffer.jpg
data in buffer.jpg (13.22 KiB) Viewed 3466 times
graphdat.jpg
graphdat.jpg (11.67 KiB) Viewed 3466 times
The problem is when call Getbyte() the first data to get is always the second one (in this case it will be 24) instead of the 1st one who is 56
data in buffer 1.jpg
data in buffer 1.jpg (35.05 KiB) Viewed 3466 times
It seems that getbyte start always with the second byte in the buffer , it mean with buffer position 1 instead of 0
thx
Seb

lucibel
Posts: 172
Joined: Thu Sep 23, 2021 3:44 pm
Location: France
Has thanked: 29 times
Been thanked: 22 times

Re: Circularbuffer Getbyte get out wrong data position

Post by lucibel »

program
curve.fcfx
(19.85 KiB) Downloaded 118 times
Seb

medelec35
Matrix Staff
Posts: 1432
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 505 times
Been thanked: 468 times

Re: Circularbuffer Getbyte get out wrong data position

Post by medelec35 »

Hi.
The flowchart you posted does not contain the circular buffer component, So I can't tell what you have done.
I don't believe the circular buffer simulation starts at 0 address when first run unless you start with FlushBuffer macro first.
The tool tips for FlushBuffer is:
FlushBuffer.png
FlushBuffer.png (12.23 KiB) Viewed 3458 times
Try that at the start and then see if it does as expected?
It could be the case of a bug and the index is not initialised as 0?
This can be looked into in the new year when we are back at work.
So long as the buffer returns the correct values since indexing is automatic.
Martin

lucibel
Posts: 172
Joined: Thu Sep 23, 2021 3:44 pm
Location: France
Has thanked: 29 times
Been thanked: 22 times

Re: Circularbuffer Getbyte get out wrong data position

Post by lucibel »

hi,
Of course there is a Circular buffer BUT , I used only the debug mode and simulation so the prog sent to you was not current prog saved but only the base! Sorry
please find below after been saved !
curve.fcfx
(14.48 KiB) Downloaded 106 times
Flushbuffer was already used.
It could be the case of a bug and the index is not initialised as 0?
No
Before to getbyte 1st time.jpg
Before to getbyte 1st time.jpg (120.31 KiB) Viewed 3454 times
After getbyte 1st time.jpg
After getbyte 1st time.jpg (116.89 KiB) Viewed 3454 times
as you can see the first data was 54 instead of 70
thx
Seb

mnfisher
Valued Contributor
Posts: 938
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 502 times

Re: Circularbuffer Getbyte get out wrong data position

Post by mnfisher »

I think this is connected to the fact that the circular buffer can only hold buffer size - 1 data bytes..

I posted a bit about it at https://www.matrixtsl.com/mmforums/view ... lar+buffer

Martin

lucibel
Posts: 172
Joined: Thu Sep 23, 2021 3:44 pm
Location: France
Has thanked: 29 times
Been thanked: 22 times

Re: Circularbuffer Getbyte get out wrong data position

Post by lucibel »

Hi,
I tried with buffer size= 11 for 10 data to store and it work's. (store last X value)
data to store.jpg
data to store.jpg (63.58 KiB) Viewed 3446 times

I made another test with size 10 for 10 data to store. (store first X value)
9 data was stored and 1 lost
9 stored.jpg
9 stored.jpg (61.43 KiB) Viewed 3446 times
The second point is that the Circular buffer on the Console do not reflect the buffer.
10 data sent, only 9 in buffer but 10 in console. This is unsettling to be oblige to use buffer and simulation like this.
10 console.jpg
10 console.jpg (63.04 KiB) Viewed 3446 times
I understand but a FIFO buffer of 10 bytes must be able to store 10 bytes so if it need to calibrate the buffer to 10+1 bytes (in background) instead of 10 to be able to store 10 data, this must be transparent for user (programmer).

Of course I understand well that need 1 more Byte (empty byte) to be able to rotate previous byte ,second byte, etc... But like I said, this must be done in background.

For a buffer of 128 byte, 0 to 127=128 bytes but need 1 more byte (background byte) to store the data during the shift of the register.

I used many FIFO of LIFO in Industrial Automation and the size is always the exact qty of data to store. Because we do not allocate the memory for the Buffer, so it will be better to be able to store X bytes in a X byte buffer.
This is my point of view

This can not be solved by CAL modification ?
Thx
Seb

Steve-Matrix
Matrix Staff
Posts: 1234
Joined: Sat Dec 05, 2020 10:32 am
Has thanked: 167 times
Been thanked: 277 times

Re: Circularbuffer Getbyte get out wrong data position

Post by Steve-Matrix »

It does look to me like a bug - the first 10 positions of the buffer are correctly initialised in your first loop starting at index 0, but reading back starts at index 1 and so the first value in your buffer is ignored and only 9 bytes are read back before the buffer thinks it is empty. We'll look into this.

Steve-Matrix
Matrix Staff
Posts: 1234
Joined: Sat Dec 05, 2020 10:32 am
Has thanked: 167 times
Been thanked: 277 times

Re: Circularbuffer Getbyte get out wrong data position

Post by Steve-Matrix »

Having played with the example on the wiki and with your program, this problem seems to disappear when the size of the buffer is set to one more than the quantity you are wishing to store. So I suggest using that workaround for now.

lucibel
Posts: 172
Joined: Thu Sep 23, 2021 3:44 pm
Location: France
Has thanked: 29 times
Been thanked: 22 times

Re: Circularbuffer Getbyte get out wrong data position

Post by lucibel »

Hi Steve
Having played with the example on the wiki and with your program, this problem seems to disappear when the size of the buffer is set to one more than the quantity you are wishing to store. So I suggest using that workaround for now.
yes this what I'm doing in the meantime of investigation.
Thx
Seb

lucibel
Posts: 172
Joined: Thu Sep 23, 2021 3:44 pm
Location: France
Has thanked: 29 times
Been thanked: 22 times

Re: Circularbuffer Getbyte get out wrong data position

Post by lucibel »

Hi, what are the news about buffer problem, still no news since end of December?
(Need to setup the buffer size to nbr data to store+1)

This causes another issue :
When discard buffer with get array, oldest entered value is never discarded !
1st test
- Buffer size5, 8 bytes to enter in buffer, 4 Bytes to discard with GetArray --> the oldest byte value who is 4 in the simulation stay in the buffer
2nd test
- Buffer size5, 8 bytes to enter in buffer, 3 Bytes to discard with GetArray --> the oldest byte value who is 4 in the simulation stay in the buffer

then at the next first Buffer PutByte, the oldest byte is overwrite !!!

Please check ASAP, it's already difficult to work with data so if in addition, the buffer doesn't work, it's a nightmare!!!
Attachments
Buffer.fcfx
(9.8 KiB) Downloaded 98 times
Seb

Post Reply