The TiltMIF namespace provides functionality for reading, writing, and manipulating Manufacturing Information Files (MIF) for tilt sensor devices. The Tilt_MIF class serves as a data container and serialization handler for device calibration data, sensor coefficients, and configuration parameters. It supports binary serialization with CRC-16 validation and XML export for human-readable storage. The CRC16 static class provides checksum computation using the CRC-16-IBM polynomial (reversed as 0xA001).
2. Public Interface
CRC16 Class (Static)
Member
Signature
Description
ComputeChecksum
public static ushort ComputeChecksum(byte[] bytes)
Computes a CRC-16 checksum over the input byte array using a pre-computed lookup table.
Tilt_MIF Class
Constructors
Signature
Description
public Tilt_MIF()
Default constructor.
public Tilt_MIF(bool hasConfig)
Constructor that sets whether the instance includes configuration data.
public Tilt_MIF(byte[] mifBytes)
Deserializes a MIF from a byte array. Validates CRC-16 checksums and sets ReadError or ReadError_Config flags on failure. Accepts arrays of length 128 (MIF only) or 256 (MIF + config).
Metadata Properties
Property
Type
Description
TimeStamp
DateTime
Timestamp for XML export.
SystemName
string
Machine name for XML export.
UserName
string
User name for XML export.
BuildVersion
string
Assembly version string.
MIF Data Properties
Property
Type
Default/Notes
MIFVersion
uint
MIF format version.
SerialNumber
string
10-character serial number. Getter trims null characters.
Returns all MIF attributes as a list of MIFAttribute objects (contains MIFAttributes enum and string value).
GetTiltAttributeDictionary
public Dictionary<string, object> GetTiltAttributeDictionary()
Returns all MIF attributes as a dictionary keyed by attribute name.
GetMIFAttribute
public object GetMIFAttribute(MIFAttributes attribute)
Returns the value of a specific MIF attribute. Returns null for unrecognized attributes.
SetMIFAttribute
public void SetMIFAttribute(MIFAttributes attribute, string newValue)
Sets a MIF attribute value by parsing the string. Silently ignores unrecognized attributes.
Config Attribute Methods
Method
Signature
Description
GetTiltConfigAttributes
public List<ConfigAttribute> GetTiltConfigAttributes()
Returns all config attributes as a list of ConfigAttribute objects.
GetTiltConfigAttributeDictionary
public Dictionary<string, object> GetTiltConfigAttributeDictionary()
Returns all config attributes as a dictionary keyed by attribute name.
GetConfigAttribute
public object GetConfigAttribute(ConfigAttributes attribute)
Returns the value of a specific config attribute. Returns null for unrecognized attributes.
SetConfigAttribute
public void SetConfigAttribute(ConfigAttributes attribute, string newValue)
Sets a config attribute value by parsing the string. Silently ignores unrecognized attributes.
Calibration Array Methods
Method
Signature
Description
GetTiltCalibrations
public double[] GetTiltCalibrations()
Returns all 18 tilt calibration coefficients as a double[].
SetTiltCalibrations
public void SetTiltCalibrations(float[] calibrations)
Sets calibration coefficients from a float[]. Throws InvalidDataException if length is not 18.
SetTiltCalibrations
public void SetTiltCalibrations(double[] calibrations)
Sets calibration coefficients from a double[] (converted to float). Throws if length is not 18.
Serialization Methods
Method
Signature
Description
GetBytes
public byte[] GetBytes()
Serializes the MIF (and config if _hasConfig is true) to a byte array. Computes and appends CRC-16 values.
WriteXML
public void WriteXML(FileStream file)
Serializes the instance to XML. Sets TimeStamp, SystemName, UserName, and BuildVersion before serialization. Closes the stream in a finally block.
GetVersionString
public string GetVersionString()
Returns the executing assembly version in format major.minor.build. Returns "N/A" on exception.
Constants
Constant
Value
Description
MIF_BYTE_LENGTH
128
Fixed byte length for MIF section.
MIF_CONFIG_BYTE_LENGTH
256
Total byte length for MIF + config.
TILTCAL_COUNT
18 (private)
Number of tilt calibration coefficients.
3. Invariants
Fixed byte lengths: MIF data is always 128 bytes; MIF with config is always 256 bytes.
Fixed string field sizes: SerialNumber is exactly 10 characters; SystemID and Location are exactly 16 characters. Longer input strings will be truncated; shorter strings will be padded with null characters.
CRC validation on read: The Tilt_MIF(byte[]) constructor validates CRC-16 checksums. If MIF_CRC16 != ComputedCRC16 or MIF_CRC16 == 0, ReadError is set to true and no further parsing occurs.
Config CRC validation: If config data is present, ReadError_Config is set when Config_CRC16 != ComputedCRC16_Config, but config parsing continues if the MIF section was valid.
In SetConfigAttribute, the cases for ConfigAttributes.PostEventADCAxis2 and ConfigAttributes.PostEventADCAxis3 incorrectly assign to PostEventADCAxis1:
caseConfigAttributes.PostEventADCAxis2:PostEventADCAxis1=short.Parse(newValue);// BUG: should be PostEventADCAxis2break;caseConfigAttributes.PostEventADCAxis3:PostEventADCAxis1=short.Parse(newValue);// BUG: should be PostEventADCAxis3break;