Exemplo n.º 1
0
 private void GetVarHeaders()
 {
     VarHeaders.Clear();
     for (int i = 0; i < Header.VarCount; i++)
     {
         int    type   = FileMapView.ReadInt32(Header.VarHeaderOffset + ((i * VarHeaderSize)));
         int    offset = FileMapView.ReadInt32(Header.VarHeaderOffset + ((i * VarHeaderSize) + VarOffsetOffset));
         int    count  = FileMapView.ReadInt32(Header.VarHeaderOffset + ((i * VarHeaderSize) + VarCountOffset));
         byte[] name   = new byte[Defines.MaxString];
         byte[] desc   = new byte[Defines.MaxDesc];
         byte[] unit   = new byte[Defines.MaxString];
         FileMapView.ReadArray <byte>(Header.VarHeaderOffset + ((i * VarHeaderSize) + VarNameOffset), name, 0, Defines.MaxString);
         FileMapView.ReadArray <byte>(Header.VarHeaderOffset + ((i * VarHeaderSize) + VarDescOffset), desc, 0, Defines.MaxDesc);
         FileMapView.ReadArray <byte>(Header.VarHeaderOffset + ((i * VarHeaderSize) + VarUnitOffset), unit, 0, Defines.MaxString);
         string nameStr = System.Text.Encoding.Default.GetString(name).TrimEnd(new char[] { '\0' });
         string descStr = System.Text.Encoding.Default.GetString(desc).TrimEnd(new char[] { '\0' });
         string unitStr = System.Text.Encoding.Default.GetString(unit).TrimEnd(new char[] { '\0' });
         VarHeaders[nameStr] = new CVarHeader(type, offset, count, nameStr, descStr, unitStr);
     }
 }
Exemplo n.º 2
0
 public object GetData(string name)
 {
     if (IsInitialized && Header != null)
     {
         CVarHeader header = null;
         if (VarHeaders.TryGetValue(name, out header))
         {
             int varOffset = header.Offset;
             int count     = header.Count;
             if (header.Type == CVarHeader.VarType.irChar)
             {
                 byte[] data = new byte[count];
                 FileMapView.ReadArray <byte>(Header.Buffer + varOffset, data, 0, count);
                 return(System.Text.Encoding.Default.GetString(data).TrimEnd(new char[] { '\0' }));
             }
             else if (header.Type == CVarHeader.VarType.irBool)
             {
                 if (count > 1)
                 {
                     bool[] data = new bool[count];
                     FileMapView.ReadArray <bool>(Header.Buffer + varOffset, data, 0, count);
                     return(data);
                 }
                 else
                 {
                     return(FileMapView.ReadBoolean(Header.Buffer + varOffset));
                 }
             }
             else if (header.Type == CVarHeader.VarType.irInt || header.Type == CVarHeader.VarType.irBitField)
             {
                 if (count > 1)
                 {
                     int[] data = new int[count];
                     FileMapView.ReadArray <int>(Header.Buffer + varOffset, data, 0, count);
                     return(data);
                 }
                 else
                 {
                     return(FileMapView.ReadInt32(Header.Buffer + varOffset));
                 }
             }
             else if (header.Type == CVarHeader.VarType.irFloat)
             {
                 if (count > 1)
                 {
                     float[] data = new float[count];
                     FileMapView.ReadArray <float>(Header.Buffer + varOffset, data, 0, count);
                     return(data);
                 }
                 else
                 {
                     return(FileMapView.ReadSingle(Header.Buffer + varOffset));
                 }
             }
             else if (header.Type == CVarHeader.VarType.irDouble)
             {
                 if (count > 1)
                 {
                     double[] data = new double[count];
                     FileMapView.ReadArray <double>(Header.Buffer + varOffset, data, 0, count);
                     return(data);
                 }
                 else
                 {
                     return(FileMapView.ReadDouble(Header.Buffer + varOffset));
                 }
             }
         }
     }
     return(null);
 }
Exemplo n.º 3
0
 private void GetVarHeaders()
 {
     VarHeaders.Clear();
     for (int i = 0; i < Header.VarCount; i++)
     {
         int type = FileMapView.ReadInt32(Header.VarHeaderOffset + ((i * VarHeaderSize)));
         int offset = FileMapView.ReadInt32(Header.VarHeaderOffset + ((i * VarHeaderSize) + VarOffsetOffset));
         int count = FileMapView.ReadInt32(Header.VarHeaderOffset + ((i * VarHeaderSize) + VarCountOffset));
         byte[] name = new byte[Defines.MaxString];
         byte[] desc = new byte[Defines.MaxDesc];
         byte[] unit = new byte[Defines.MaxString];
         FileMapView.ReadArray<byte>(Header.VarHeaderOffset + ((i * VarHeaderSize) + VarNameOffset), name, 0, Defines.MaxString);
         FileMapView.ReadArray<byte>(Header.VarHeaderOffset + ((i * VarHeaderSize) + VarDescOffset), desc, 0, Defines.MaxDesc);
         FileMapView.ReadArray<byte>(Header.VarHeaderOffset + ((i * VarHeaderSize) + VarUnitOffset), unit, 0, Defines.MaxString);
         string nameStr = System.Text.Encoding.Default.GetString(name).TrimEnd(new char[] { '\0' });
         string descStr = System.Text.Encoding.Default.GetString(desc).TrimEnd(new char[] { '\0' });
         string unitStr = System.Text.Encoding.Default.GetString(unit).TrimEnd(new char[] { '\0' });
         VarHeaders[nameStr] = new CVarHeader(type, offset, count, nameStr, descStr, unitStr);
     }
 }