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
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
It seems that getbyte start always with the second byte in the buffer , it mean with buffer position 1 instead of 0
thx
Circularbuffer Getbyte get out wrong data position
-
- 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
-
- Matrix Staff
- Posts: 1464
- Joined: Wed Dec 02, 2020 11:07 pm
- Has thanked: 514 times
- Been thanked: 474 times
Re: Circularbuffer Getbyte get out wrong data position
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: 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.
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: 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
-
- 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
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 ! Flushbuffer was already used.
thx
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 ! Flushbuffer was already used.
No as you can see the first data was 54 instead of 70It could be the case of a bug and the index is not initialised as 0?
thx
Seb
-
- Valued Contributor
- Posts: 991
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 106 times
- Been thanked: 517 times
Re: Circularbuffer Getbyte get out wrong data position
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
I posted a bit about it at https://www.matrixtsl.com/mmforums/view ... lar+buffer
Martin
-
- 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
Hi,
I tried with buffer size= 11 for 10 data to store and it work's. (store last X value)
I made another test with size 10 for 10 data to store. (store first X value)
9 data was stored and 1 lost 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.
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
I tried with buffer size= 11 for 10 data to store and it work's. (store last X value)
I made another test with size 10 for 10 data to store. (store first X value)
9 data was stored and 1 lost 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.
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).I posted a bit about it at https://www.matrixtsl.com/mmforums/view ... lar+buffer
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
-
- Matrix Staff
- Posts: 1269
- Joined: Sat Dec 05, 2020 10:32 am
- Has thanked: 169 times
- Been thanked: 285 times
Re: Circularbuffer Getbyte get out wrong data position
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.
-
- Matrix Staff
- Posts: 1269
- Joined: Sat Dec 05, 2020 10:32 am
- Has thanked: 169 times
- Been thanked: 285 times
Re: Circularbuffer Getbyte get out wrong data position
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.
-
- 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
Hi Steve
Thx
yes this what I'm doing in the meantime of investigation.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.
Thx
Seb
-
- 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
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!!!
(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 102 times
Seb