Coding and general discussion relating to the compiler
Moderators: David Barker, Jerry Messina
-
SHughes_Fusion
- Posts: 219
- Joined: Wed Sep 11, 2013 1:27 pm
- Location: Chesterfield
Post
by SHughes_Fusion » Tue Jul 08, 2014 8:05 am
I can't tell if this is a slight compiler problem or if there is something else wrong in my code, but I've got the following set up:
Code: Select all
Public Structure LogEntry // Define a structure for storing a log entry in RAM
EntryTime As Word
ET1 As EntryTime.byte1
ET0 As EntryTime.byte0
Pressure As Word
P1 As Pressure.byte1
P0 As Pressure.byte0
Temperature As Word
T1 As Temperature.byte1
T0 As Temperature.byte0
MachineStatus As Byte
OpenPressed As MachineStatus.booleans(0)
ClosePressed As MachineStatus.booleans(1)
DragSet As MachineStatus.booleans(2)
SoakTimerRunning As MachineStatus.booleans(3)
FusionTimerRunning As MachineStatus.booleans(4)
PressureOutOfRange As MachineStatus.booleans(5)
HeaterOutOfRange As MachineStatus.booleans(6)
HeaterLink As MachineStatus.booleans(7)
EntryCRC As Byte
End Structure
Public Const FlashPageSize = 64
Public Const LogRecordSize = 8
Public Const TempLogSize = FlashPageSize / LogRecordSize // Each entry is 8 bytes, the EEPROM works on 64 byte blocks so we need to store 8 entries in RAM before pushing out to E2
Public Dim WeldLog(TempLogSize) As LogEntry
When I call
it only seems to clear the first element of the array. Is this correct? Do I need to clear each element of the array individually? Clear doesn't seem to be very well documented in the help files so I'm not sure if it clears everything in arrays or just the first element.
-
Jerry Messina
- Swordfish Developer
- Posts: 1473
- Joined: Fri Jan 30, 2009 6:27 pm
- Location: US
Post
by Jerry Messina » Tue Jul 08, 2014 10:30 am
Clear(ArrayName) should clear the entire array.
If you only wanted to clear a single structure in the array you could use something like Clear(ArrayName(2)), which would clear the third structure in the array. The only time it works differently is for string variables, in which case it just sets the first byte to '0' (which is an empty string).
For me, the simple example you posted clears the entire array of 64 bytes in length. I wonder if you're looking at it correctly, or if you need a more complicated example to exhibit the behavior you're seeing.
-
SHughes_Fusion
- Posts: 219
- Joined: Wed Sep 11, 2013 1:27 pm
- Location: Chesterfield
Post
by SHughes_Fusion » Tue Jul 08, 2014 10:36 am
The thing that made me wonder this was a bug elsewhere in the code.
As you can probably guess from what I've posted I've got a system running that logs certain parameters (every second) and once I've got 64 bytes of data I push it out to an external 24xxx EEPROM chip.
The bug came when I ended logging - I'd set it to push the whole buffer even though it might only be partly filled. At the end of the push I use Clear(WeldLog) thinking that this would clear my entire buffer so even if I pushed a partial buffer I'd only get new data and the rest would be zeros.
They aren't, only the first entry in the array is zeroed, the rest retain their previous values.
I'll dig a bit further, it may be something else going odd in my code.
-
Jerry Messina
- Swordfish Developer
- Posts: 1473
- Joined: Fri Jan 30, 2009 6:27 pm
- Location: US
Post
by Jerry Messina » Tue Jul 08, 2014 11:53 am
Dumb question, but the '24xxx EEPROM' you're using does have a page size of 64 bytes, correct?
Not all of them do...
-
SHughes_Fusion
- Posts: 219
- Joined: Wed Sep 11, 2013 1:27 pm
- Location: Chesterfield
Post
by SHughes_Fusion » Tue Jul 08, 2014 12:35 pm
Hi Jerry,
Yes, it's the 24LC256. I'm upgrading to the 512 in the next version which has a 128 byte page. The bulk of the log works, it's just at the end I see this odd behaviour.