I am using BinaryWriter to log data using a Structure in VB NET Compact Framework 3.5 and I do this by appending a block of the individual structure items as follows:
This code works fine but I am unable to figure out why Binary writer stores this in 63 bytes?
The first item mdat.rtime is a DateTime and I assume it is stored as a string using binary writer because I recover it OK with BinaryReader when the read variable as a string? All the other 10 items are 4 byte Singles variables?
When I check the length of mdat.rtime it tells me that it is 8 bytes long so I assume that BinaryWriter should write this block of data as 48bytes in total but checking the filestream length tell me it is 63 bytes long - why?
I have noticed that this length changes from 60 - 63 bytes depending on what format the regional settings are ? - but the mdat.rtime length always remains 8 bytes?
I need to know how BinaryWriter stores DateTime and exactly how many bytes are stored so that I can recover my data into arrays of equal size (when more data is logged) - and also this needs to be known for whatever the regional setting are set to?
Any assistance would be most appreciated?
Colin
Code:
Dim filestream As FileStream = New FileStream("mlog.bin", FileMode.Append)
Dim fwrite As BinaryWriter = New BinaryWriter(filestream)
mdat.rtime = Now 'load the present time'
fwrite.Write(mdat.rtime)
fwrite.Write(mdat.Ax4)
fwrite.Write(mdat.Ax3)
fwrite.Write(mdat.Ax2)
fwrite.Write(mdat.Ax1)
fwrite.Write(mdat.KWHA)
fwrite.Write(mdat.KWHB)
fwrite.Write(mdat.KWHC)
fwrite.Write(mdat.Stat)
fwrite.Write(mdat.AN1)
fwrite.Write(mdat.AN2)
fwrite.Close()
filestream.Close()
The first item mdat.rtime is a DateTime and I assume it is stored as a string using binary writer because I recover it OK with BinaryReader when the read variable as a string? All the other 10 items are 4 byte Singles variables?
When I check the length of mdat.rtime it tells me that it is 8 bytes long so I assume that BinaryWriter should write this block of data as 48bytes in total but checking the filestream length tell me it is 63 bytes long - why?
I have noticed that this length changes from 60 - 63 bytes depending on what format the regional settings are ? - but the mdat.rtime length always remains 8 bytes?
I need to know how BinaryWriter stores DateTime and exactly how many bytes are stored so that I can recover my data into arrays of equal size (when more data is logged) - and also this needs to be known for whatever the regional setting are set to?
Any assistance would be most appreciated?
Colin