public void WriteFloat(float v) { byte[] temp = BitConverter.GetBytes(v); Array.Reverse(temp); writer.Write(BitConverter.ToSingle(temp, 0)); }
public override void SendIdentifier(SteamAudioSource steamAudioSource, int identifier) { var identifierFloat = BitConverter.ToSingle(BitConverter.GetBytes(identifier), 0); audioSource.SetSpatializerFloat(13, identifierFloat); }
public float GetZ() { return(BitConverter.ToSingle(Datas, 16)); }
// Token: 0x06000CB2 RID: 3250 RVA: 0x0003FCE4 File Offset: 0x0003DEE4 public float ReadFloat(uint offset) { byte[] bytes = this.GetBytes(offset, 4u, this.CurrentAPI); Array.Reverse(bytes, 0, 4); return(BitConverter.ToSingle(bytes, 0)); }
public static float ReadSingle(int address) { return(BitConverter.ToSingle(Read(new IntPtr(address), 4), 0)); }
public float ReadFloat(int j) => BitConverter.ToSingle(new byte[] { MiscSettings[j + 3], MiscSettings[j + 2], MiscSettings[j + 1], MiscSettings[j] }, 0);
public static float ReadFloat(IntPtr pointer) { return(BitConverter.ToSingle(BitConverter.GetBytes(Marshal.ReadInt32(pointer)), 0)); }
public void Read <T>(out T data) where T : struct { byte[] dataByte; if (typeof(T) == typeof(bool)) { dataByte = new byte[sizeof(bool)]; Array.Copy(buffer, head, dataByte, 0, sizeof(bool)); if (BitConverter.IsLittleEndian) { Array.Reverse(dataByte); } data = (T)(object)BitConverter.ToBoolean(dataByte, 0); head += sizeof(bool); } else if (typeof(T) == typeof(char)) { dataByte = new byte[sizeof(char)]; Array.Copy(buffer, head, dataByte, 0, sizeof(char)); if (BitConverter.IsLittleEndian) { Array.Reverse(dataByte); } data = (T)(object)BitConverter.ToChar(dataByte, 0); head += sizeof(char); } else if (typeof(T) == typeof(byte)) { data = (T)(object)buffer[head]; head += sizeof(byte); } else if (typeof(T) == typeof(sbyte)) { data = (T)(object)buffer[head]; head += sizeof(sbyte); } else if (typeof(T) == typeof(short)) { dataByte = new byte[sizeof(short)]; Array.Copy(buffer, head, dataByte, 0, sizeof(short)); if (BitConverter.IsLittleEndian) { Array.Reverse(dataByte); } data = (T)(object)BitConverter.ToInt16(dataByte, 0); head += sizeof(short); } else if (typeof(T) == typeof(ushort)) { dataByte = new byte[sizeof(ushort)]; Array.Copy(buffer, head, dataByte, 0, sizeof(ushort)); if (BitConverter.IsLittleEndian) { Array.Reverse(dataByte); } data = (T)(object)BitConverter.ToUInt16(dataByte, 0); head += sizeof(ushort); } else if (typeof(T) == typeof(int)) { dataByte = new byte[sizeof(int)]; Array.Copy(buffer, head, dataByte, 0, sizeof(int)); if (BitConverter.IsLittleEndian) { Array.Reverse(dataByte); } data = (T)(object)BitConverter.ToInt32(dataByte, 0); head += sizeof(int); } else if (typeof(T) == typeof(uint)) { dataByte = new byte[sizeof(uint)]; Array.Copy(buffer, head, dataByte, 0, sizeof(uint)); if (BitConverter.IsLittleEndian) { Array.Reverse(dataByte); } data = (T)(object)BitConverter.ToUInt32(dataByte, 0); head += sizeof(uint); } else if (typeof(T) == typeof(long)) { dataByte = new byte[sizeof(long)]; Array.Copy(buffer, head, dataByte, 0, sizeof(long)); if (BitConverter.IsLittleEndian) { Array.Reverse(dataByte); } data = (T)(object)BitConverter.ToInt64(dataByte, 0); head += sizeof(long); } else if (typeof(T) == typeof(ulong)) { dataByte = new byte[sizeof(ulong)]; Array.Copy(buffer, head, dataByte, 0, sizeof(ulong)); if (BitConverter.IsLittleEndian) { Array.Reverse(dataByte); } data = (T)(object)BitConverter.ToUInt64(dataByte, 0); head += sizeof(ulong); } else if (typeof(T) == typeof(float)) { dataByte = new byte[sizeof(float)]; Array.Copy(buffer, head, dataByte, 0, sizeof(float)); if (BitConverter.IsLittleEndian) { Array.Reverse(dataByte); } data = (T)(object)BitConverter.ToSingle(dataByte, 0); head += sizeof(float); } else if (typeof(T) == typeof(double)) { dataByte = new byte[sizeof(double)]; Array.Copy(buffer, head, dataByte, 0, sizeof(double)); if (BitConverter.IsLittleEndian) { Array.Reverse(dataByte); } data = (T)(object)BitConverter.ToDouble(dataByte, 0); head += sizeof(double); } else { throw new ArgumentException("InputMemoryStream.Read parameter can be only primitive type except decimal"); } }
private int _ReadCalibrationConstants() { byte[] data = new byte[36]; byte[] bATmp = new byte[4]; byte[] reverseData; float fTmp; int tmp; if (i2cReadCB == null) return -1; if (i2cReadCB(81, 56, 36, data) != 36) return -1; try { Buffer.BlockCopy(data, 0, bATmp, 0, 4); } catch (Exception eBC) { MessageBox.Show(eBC.ToString()); return -1; } reverseData = bATmp.Reverse().ToArray(); fTmp = BitConverter.ToSingle(reverseData, 0); tbCalibrationRxPower4.Text = fTmp.ToString(); try { Buffer.BlockCopy(data, 4, bATmp, 0, 4); } catch (Exception eBC) { MessageBox.Show(eBC.ToString()); return -1; } reverseData = bATmp.Reverse().ToArray(); fTmp = BitConverter.ToSingle(reverseData, 0); tbCalibrationRxPower3.Text = fTmp.ToString(); try { Buffer.BlockCopy(data, 8, bATmp, 0, 4); } catch (Exception eBC) { MessageBox.Show(eBC.ToString()); return -1; } reverseData = bATmp.Reverse().ToArray(); fTmp = BitConverter.ToSingle(reverseData, 0); tbCalibrationRxPower2.Text = fTmp.ToString(); try { Buffer.BlockCopy(data, 12, bATmp, 0, 4); } catch (Exception eBC) { MessageBox.Show(eBC.ToString()); return -1; } reverseData = bATmp.Reverse().ToArray(); fTmp = BitConverter.ToSingle(reverseData, 0); tbCalibrationRxPower1.Text = fTmp.ToString(); try { Buffer.BlockCopy(data, 16, bATmp, 0, 4); } catch (Exception eBC) { MessageBox.Show(eBC.ToString()); return -1; } reverseData = bATmp.Reverse().ToArray(); fTmp = BitConverter.ToSingle(reverseData, 0); tbCalibrationRxPower0.Text = fTmp.ToString(); fTmp = data[20]; fTmp += data[21] / 256; tbCalibrationTxISlope.Text = fTmp.ToString(); try { Buffer.BlockCopy(data, 22, bATmp, 0, 2); } catch (Exception eBC) { MessageBox.Show(eBC.ToString()); return -1; } reverseData = bATmp.Reverse().ToArray(); tmp = BitConverter.ToInt16(reverseData, 0); tbCalibrationTxIOffset.Text = tmp.ToString(); fTmp = data[24]; fTmp += data[25] / 256; tbCalibrationTxPwrSlope.Text = fTmp.ToString(); try { Buffer.BlockCopy(data, 26, bATmp, 0, 2); } catch (Exception eBC) { MessageBox.Show(eBC.ToString()); return -1; } reverseData = bATmp.Reverse().ToArray(); tmp = BitConverter.ToInt16(reverseData, 0); tbCalibrationTxPwrOffset.Text = tmp.ToString(); fTmp = data[28]; fTmp += data[29] / 256; tbCalibrationTSlope.Text = fTmp.ToString(); try { Buffer.BlockCopy(data, 30, bATmp, 0, 2); } catch (Exception eBC) { MessageBox.Show(eBC.ToString()); return -1; } reverseData = bATmp.Reverse().ToArray(); tmp = BitConverter.ToInt16(reverseData, 0); tbCalibrationTOffset.Text = tmp.ToString(); fTmp = data[32]; fTmp += data[33] / 256; tbCalibrationVSlope.Text = fTmp.ToString(); try { Buffer.BlockCopy(data, 34, bATmp, 0, 2); } catch (Exception eBC) { MessageBox.Show(eBC.ToString()); return -1; } reverseData = bATmp.Reverse().ToArray(); tmp = BitConverter.ToInt16(reverseData, 0); tbCalibrationVOffset.Text = tmp.ToString(); return 0; }
public static object GetResult(MosaType type, List <byte> data) { if (type.IsI1) { return((sbyte)data[0]); } else if (type.IsI2) { return((short)(data[0] | (data[1] << 8))); } else if (type.IsI4) { return(data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24)); } else if (type.IsI8) { ulong low = (uint)(data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24)); ulong high = (uint)(data[4] | (data[5] << 8) | (data[6] << 16) | (data[7] << 24)); return((long)(low | (high << 32))); } else if (type.IsU1) { return(data[0]); } else if (type.IsU2) { return((ushort)(data[0] | (data[1] << 8))); } else if (type.IsU4) { return((uint)(data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24))); } else if (type.IsU8) { ulong low = (uint)(data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24)); ulong high = (uint)(data[4] | (data[5] << 8) | (data[6] << 16) | (data[7] << 24)); return(low | (high << 32)); } else if (type.IsChar) { return((char)(data[0] | (data[1] << 8))); } else if (type.IsBoolean) { return(data[0] != 0); } else if (type.IsR4) { var value = new byte[8]; for (int i = 0; i < 8; i++) { value[i] = data[i]; } return(BitConverter.ToSingle(value, 0)); } else if (type.IsR8) { var value = new byte[8]; for (int i = 0; i < 8; i++) { value[i] = data[i]; } return(BitConverter.ToDouble(value, 0)); } else if (type.IsVoid) { return(null); } return(null); }
// write unsigned 64-bit LE // write unsigned 64-bit BE // write signed 64-bit LE // write signed 64-bit BE #endregion #region Read Floats public float ReadSingleBE(int offset = 0) { return(BitConverter.ToSingle(_bytes, offset)); }
public PlayerInfo(byte[] data) { playerState = (PlayerState)data[0]; playerScore = BitConverter.ToUInt32(data, 1); playerCutBlocks = BitConverter.ToUInt32(data, 5); playerComboBlocks = BitConverter.ToUInt32(data, 9); playerTotalBlocks = BitConverter.ToUInt32(data, 13); playerEnergy = BitConverter.ToSingle(data, 17); playerProgress = BitConverter.ToSingle(data, 21); rightHandPos = new Vector3(BitConverter.ToSingle(data, 25), BitConverter.ToSingle(data, 29), BitConverter.ToSingle(data, 33)); leftHandPos = new Vector3(BitConverter.ToSingle(data, 37), BitConverter.ToSingle(data, 41), BitConverter.ToSingle(data, 45)); headPos = new Vector3(BitConverter.ToSingle(data, 49), BitConverter.ToSingle(data, 53), BitConverter.ToSingle(data, 57)); rightHandRot = new Quaternion(BitConverter.ToSingle(data, 61), BitConverter.ToSingle(data, 65), BitConverter.ToSingle(data, 69), BitConverter.ToSingle(data, 73)); leftHandRot = new Quaternion(BitConverter.ToSingle(data, 77), BitConverter.ToSingle(data, 81), BitConverter.ToSingle(data, 85), BitConverter.ToSingle(data, 89)); headRot = new Quaternion(BitConverter.ToSingle(data, 93), BitConverter.ToSingle(data, 97), BitConverter.ToSingle(data, 101), BitConverter.ToSingle(data, 105)); hitsLastUpdate.Clear(); byte hitsCount = data[109]; if (hitsCount > 0) { MemoryStream stream = new MemoryStream(data, 110, hitsCount * 5); for (int i = 0; i < hitsCount; i++) { byte[] hit = new byte[5]; stream.Read(hit, 0, 5); hitsLastUpdate.Add(new HitData(hit)); } } }
public void SetValue(byte[] buffer) { if (buffer == null || this.NullFlag == -1) { this.Value = System.DBNull.Value; } else { switch (this.SqlType) { case IscCodes.SQL_TEXT: case IscCodes.SQL_VARYING: if (this.DbDataType == DbDataType.Guid) { this.Value = new Guid(buffer); } else { if (this.Charset.IsOctetsCharset) { this.Value = buffer; } else { string s = this.Charset.GetString(buffer, 0, buffer.Length); if ((this.Length % this.Charset.BytesPerCharacter) == 0 && s.Length > this.CharCount) { s = s.Substring(0, this.CharCount); } this.Value = s; } } break; case IscCodes.SQL_SHORT: if (this.numericScale < 0) { this.Value = TypeDecoder.DecodeDecimal( BitConverter.ToInt16(buffer, 0), this.numericScale, this.dataType); } else { this.Value = BitConverter.ToInt16(buffer, 0); } break; case IscCodes.SQL_LONG: if (this.NumericScale < 0) { this.Value = TypeDecoder.DecodeDecimal( BitConverter.ToInt32(buffer, 0), this.numericScale, this.dataType); } else { this.Value = BitConverter.ToInt32(buffer, 0); } break; case IscCodes.SQL_FLOAT: this.Value = BitConverter.ToSingle(buffer, 0); break; case IscCodes.SQL_DOUBLE: case IscCodes.SQL_D_FLOAT: this.Value = BitConverter.ToDouble(buffer, 0); break; case IscCodes.SQL_QUAD: case IscCodes.SQL_INT64: case IscCodes.SQL_BLOB: case IscCodes.SQL_ARRAY: if (this.NumericScale < 0) { this.Value = TypeDecoder.DecodeDecimal( BitConverter.ToInt64(buffer, 0), this.numericScale, this.dataType); } else { this.Value = BitConverter.ToInt64(buffer, 0); } break; case IscCodes.SQL_TIMESTAMP: DateTime date = TypeDecoder.DecodeDate(BitConverter.ToInt32(buffer, 0)); TimeSpan time = TypeDecoder.DecodeTime(BitConverter.ToInt32(buffer, 4)); this.Value = new System.DateTime( date.Year, date.Month, date.Day, time.Hours, time.Minutes, time.Seconds, time.Milliseconds); break; case IscCodes.SQL_TYPE_TIME: this.Value = TypeDecoder.DecodeTime(BitConverter.ToInt32(buffer, 0)); break; case IscCodes.SQL_TYPE_DATE: this.Value = TypeDecoder.DecodeDate(BitConverter.ToInt32(buffer, 0)); break; default: throw new NotSupportedException("Unknown data type"); } } }
public byte[] GetServerData(byte[] clientData) { serverTime = DateTime.Now.TimeOfDay; byte[] data, buffer; #region deserialize clientData PlayerInfo player; string name; float x, y, z; int playerNameLength = 0; int nextIndex = 0; ConnectionState playerState = (ConnectionState)BitConverter.ToUInt16(clientData, nextIndex); nextIndex += 2; // Set player information player = players[0]; playerNameLength = BitConverter.ToInt32(clientData, nextIndex); nextIndex += 4; name = Encoding.ASCII.GetString(clientData, nextIndex, playerNameLength); nextIndex += playerNameLength; x = BitConverter.ToSingle(clientData, nextIndex); nextIndex += 4; y = BitConverter.ToSingle(clientData, nextIndex); nextIndex += 4; z = BitConverter.ToSingle(clientData, nextIndex); nextIndex += 4; player.name = name; player.position = new Position(x, y, z); #endregion using (MemoryStream stream = new MemoryStream()) { buffer = BitConverter.GetBytes(serverTime.Ticks); stream.Write(buffer, 0, buffer.Length); buffer = BitConverter.GetBytes((ushort)ConnectionState.Connected); stream.Write(buffer, 0, buffer.Length); for (int i = 0; i < 3; i++) { player = players[i]; Position pos = player.position; byte[] nameBuffer = Encoding.ASCII.GetBytes(player.name); buffer = BitConverter.GetBytes(nameBuffer.Length); stream.Write(buffer, 0, buffer.Length); stream.Write(nameBuffer, 0, nameBuffer.Length); buffer = BitConverter.GetBytes(pos.x); stream.Write(buffer, 0, buffer.Length); buffer = BitConverter.GetBytes(pos.y); stream.Write(buffer, 0, buffer.Length); buffer = BitConverter.GetBytes(pos.z); stream.Write(buffer, 0, buffer.Length); } data = stream.GetBuffer(); } return(data); }
public void Pop(out float data) { data = BitConverter.ToSingle(buffer, read); MoveReadPos(sizeof(float)); }
private static float ToSingle(int value) { return(BitConverter.ToSingle(BitConverter.GetBytes(value), 0)); }
public bool SetThrottles(byte[] throttleData) { byte[] adjData; int pos = 0; if (!BitConverter.IsLittleEndian) { byte[] newData = new byte[7 * 4]; Buffer.BlockCopy(throttleData, 0, newData, 0, 7 * 4); for (int i = 0; i < 7; i++) { Array.Reverse(newData, i * 4, 4); } adjData = newData; } else { adjData = throttleData; } // These adjData values come in from the viewer in bits. (Not Kbits, not bytes, not Kbytes.) int resend = (int)(BitConverter.ToSingle(adjData, pos)); pos += 4; int land = (int)(BitConverter.ToSingle(adjData, pos)); pos += 4; int wind = (int)(BitConverter.ToSingle(adjData, pos)); pos += 4; int cloud = (int)(BitConverter.ToSingle(adjData, pos)); pos += 4; int task = (int)(BitConverter.ToSingle(adjData, pos)); pos += 4; int texture = (int)(BitConverter.ToSingle(adjData, pos)); pos += 4; int asset = (int)(BitConverter.ToSingle(adjData, pos)); // m_log.DebugFormat("[LLUDPCLIENT]: throttles: Resend={0}, Land={1}, Wind={2}, Cloud={3}, Task={4}, Texture={5}, Asset={6}, Total={7}", resend, land, wind, cloud, task, texture, asset, resend + land + wind + cloud + task + texture + asset); // undo LL's 50% hack first, this yields original bps rates (from viewer preferences). resend = (int)(resend / 1.5f); land = (int)(land / 1.5f); wind = (int)(wind / 1.5f); cloud = (int)(cloud / 1.5f); task = (int)(task / 1.5f); texture = (int)(texture / 1.5f); asset = (int)(asset / 1.5f); // convert from bits to bytes (sometimes not multiples of 8) resend = (resend + 7) / 8; land = (land + 7) / 8; wind = (wind + 7) / 8; cloud = (cloud + 7) / 8; task = (task + 7) / 8; texture = (texture + 7) / 8; asset = (asset + 7) / 8; // Now these category sizes are in bytes, for server use, including matching units for MTU check. // State is a subcategory of task that we allocate a percentage to int state = (int)((float)task * STATE_TASK_PERCENTAGE); task -= state; // Make sure none of the throttles are set below our packet MTU, // otherwise a throttle could become permanently clogged resend = Math.Max(resend, LLUDPServer.MTU); land = Math.Max(land, LLUDPServer.MTU); wind = Math.Max(wind, LLUDPServer.MTU); cloud = Math.Max(cloud, LLUDPServer.MTU); task = Math.Max(task, LLUDPServer.MTU); texture = Math.Max(texture, LLUDPServer.MTU); asset = Math.Max(asset, LLUDPServer.MTU); state = Math.Max(state, LLUDPServer.MTU); // Let's calculate some convenience totals. int totalBytes = resend + land + wind + cloud + task + texture + asset + state; int totalBits = totalBytes * 8; int totalKBits = totalBits / 1024; // m_log.DebugFormat("[UDP]: Throttle task={0} of {1} Kbps", (task * 8) / 1024, totalKBits); //m_log.InfoFormat("[LLUDP] Client {0} throttle {1}", AgentID, total); //m_log.DebugFormat("[LLUDPCLIENT]: {0} is setting throttles. Resend={1}, Land={2}, Wind={3}, Cloud={4}, Task={5}, Texture={6}, Asset={7}, State={8}, Total={9}", // AgentID, resend, land, wind, cloud, task+state, texture, asset, state, total); // Update the token buckets with new throttle values TokenBucket bucket; int oldRate = m_throttle.DripRate; // DripRates are in bytes per second, throttles for encoding to viewer are in bits per second. int oldKBits = (oldRate * 8) / 1024; // convert to bits then KBits bool throttleChanged = (m_throttle.DripRate != m_throttle.NormalizedDripRate(totalBytes)); if (throttleChanged) { m_log.InfoFormat("[LLUDPCLIENT]: Viewer agent bandwidth throttle request {0} kbps -> {1} kbps.", oldKBits, totalKBits); } // Bucket drip/burst rates are in bytes per second (stored internally as bytes per millisecond) bucket = m_throttle; bucket.DripRate = totalBytes; bucket.MaxBurst = totalBytes; bucket = m_throttleCategories[(int)ThrottleOutPacketType.Resend]; bucket.DripRate = resend; bucket.MaxBurst = resend; bucket = m_throttleCategories[(int)ThrottleOutPacketType.Land]; bucket.DripRate = land; bucket.MaxBurst = land; bucket = m_throttleCategories[(int)ThrottleOutPacketType.Wind]; bucket.DripRate = wind; bucket.MaxBurst = wind; bucket = m_throttleCategories[(int)ThrottleOutPacketType.Cloud]; bucket.DripRate = cloud; bucket.MaxBurst = cloud; bucket = m_throttleCategories[(int)ThrottleOutPacketType.Asset]; bucket.DripRate = asset; bucket.MaxBurst = asset; bucket = m_throttleCategories[(int)ThrottleOutPacketType.Task]; bucket.DripRate = task + state; bucket.MaxBurst = task + state; bucket = m_throttleCategories[(int)ThrottleOutPacketType.State]; bucket.DripRate = state; bucket.MaxBurst = state; bucket = m_throttleCategories[(int)ThrottleOutPacketType.Texture]; bucket.DripRate = texture; bucket.MaxBurst = texture; // Reset the packed throttles cached data m_unpackedThrottles = null; return(throttleChanged); }
//* public static Network Deserialize(uint[] flat) { Network output = new Network(); List <Tuple <int, int, float> > incidence = new List <Tuple <int, int, float> >(); for (int i = 0; i < flat[0]; i++) { output.AddInputNeuron(); } for (int i = 0; i < flat[1]; i++) { output.AddOutputNeuron(); } for (int i = 0; i < flat[2]; i++) { output.AddHiddenNeuron(); } for (int i = 1; i < flat.Length / 3; i++) { incidence.Add(new Tuple <int, int, float>((int)flat[i * 3], (int)flat[i * 3 + 1], BitConverter.ToSingle(BitConverter.GetBytes(flat[i * 3 + 2]), 0))); } output.IncidenceToNetwork(incidence); return(output); }
public float ReadFloat(ByteOrder order = ByteOrder.Big) { return(BitConverter.ToSingle(Reverse(ReadBytes(4), order), 0)); }
public void Sys2_(byte[] byteArray, string path) { f_sys2new.rmk = new sys2[2]; f_sys2new.count_ALL = new COUNT_F_ALL[2]; //заносим полученные данные в структуру sys2 f_sys2new.cnt = BitConverter.ToUInt32(byteArray, 14 - 14); f_sys2new.rmk[0].count.O1 = byteArray[18 - 14]; f_sys2new.rmk[0].count.O2 = byteArray[19 - 14]; f_sys2new.rmk[0].count.T1 = BitConverter.ToUInt16(byteArray, 20 - 14); f_sys2new.rmk[0].count.T2 = BitConverter.ToUInt16(byteArray, 22 - 14); f_sys2new.rmk[0].count.O31 = byteArray[24 - 14]; f_sys2new.rmk[0].count.O32 = byteArray[25 - 14]; f_sys2new.rmk[0].count.T31 = BitConverter.ToUInt16(byteArray, 26 - 14); f_sys2new.rmk[0].count.T32 = BitConverter.ToUInt16(byteArray, 28 - 14); f_sys2new.rmk[0].Sr_skz_d1 = BitConverter.ToSingle(byteArray, 30 - 14); f_sys2new.rmk[0].Sr_skz_d2 = BitConverter.ToSingle(byteArray, 34 - 14); f_sys2new.rmk[0].Sr_pik_d1 = BitConverter.ToSingle(byteArray, 38 - 14); f_sys2new.rmk[0].Sr_pik_d2 = BitConverter.ToSingle(byteArray, 42 - 14); f_sys2new.rmk[0].pred_skz_d1 = BitConverter.ToSingle(byteArray, 46 - 14); f_sys2new.rmk[0].pred_skz_d2 = BitConverter.ToSingle(byteArray, 50 - 14); f_sys2new.rmk[0].pred_pik_d1 = BitConverter.ToSingle(byteArray, 54 - 14); f_sys2new.rmk[0].pred_pik_d2 = BitConverter.ToSingle(byteArray, 58 - 14); f_sys2new.rmk[0].Sr_M_d1 = BitConverter.ToSingle(byteArray, 62 - 14); f_sys2new.rmk[0].Sr_M_d2 = BitConverter.ToSingle(byteArray, 66 - 14); f_sys2new.rmk[0].Cnt_Bad_red = BitConverter.ToUInt32(byteArray, 70 - 14); f_sys2new.rmk[0].Cnt_Bad_yel = BitConverter.ToUInt32(byteArray, 74 - 14); f_sys2new.rmk[0].Sum_skz_d1 = BitConverter.ToSingle(byteArray, 78 - 14); f_sys2new.rmk[0].Sum_pik_d1 = BitConverter.ToSingle(byteArray, 82 - 14); f_sys2new.rmk[0].Sum_skz_d2 = BitConverter.ToSingle(byteArray, 86 - 14); f_sys2new.rmk[0].Sum_pik_d2 = BitConverter.ToSingle(byteArray, 90 - 14); f_sys2new.rmk[0].Prozent_yel = BitConverter.ToSingle(byteArray, 94 - 14); f_sys2new.rmk[0].Prozent_red = BitConverter.ToSingle(byteArray, 98 - 14); f_sys2new.rmk[0].cnt_d1 = BitConverter.ToUInt16(byteArray, 102 - 14); f_sys2new.rmk[0].cnt_d2 = BitConverter.ToUInt16(byteArray, 104 - 14); f_sys2new.rmk[0].defect_file = BitConverter.ToUInt16(byteArray, 106 - 14); f_sys2new.rmk[1].count.O1 = byteArray[108 - 14]; f_sys2new.rmk[1].count.O2 = byteArray[109 - 14]; f_sys2new.rmk[1].count.T1 = BitConverter.ToUInt16(byteArray, 110 - 14); f_sys2new.rmk[1].count.T2 = BitConverter.ToUInt16(byteArray, 112 - 14); f_sys2new.rmk[1].count.O31 = byteArray[114 - 14]; f_sys2new.rmk[1].count.O32 = byteArray[115 - 14]; f_sys2new.rmk[1].count.T31 = BitConverter.ToUInt16(byteArray, 116 - 14); f_sys2new.rmk[1].count.T32 = BitConverter.ToUInt16(byteArray, 118 - 14); f_sys2new.rmk[1].Sr_skz_d1 = BitConverter.ToSingle(byteArray, 120 - 14); f_sys2new.rmk[1].Sr_skz_d2 = BitConverter.ToSingle(byteArray, 124 - 14); f_sys2new.rmk[1].Sr_pik_d1 = BitConverter.ToSingle(byteArray, 128 - 14); f_sys2new.rmk[1].Sr_pik_d2 = BitConverter.ToSingle(byteArray, 132 - 14); f_sys2new.rmk[1].pred_skz_d1 = BitConverter.ToSingle(byteArray, 136 - 14); f_sys2new.rmk[1].pred_skz_d2 = BitConverter.ToSingle(byteArray, 140 - 14); f_sys2new.rmk[1].pred_pik_d1 = BitConverter.ToSingle(byteArray, 144 - 14); f_sys2new.rmk[1].pred_pik_d2 = BitConverter.ToSingle(byteArray, 148 - 14); f_sys2new.rmk[1].Sr_M_d1 = BitConverter.ToSingle(byteArray, 152 - 14); f_sys2new.rmk[1].Sr_M_d2 = BitConverter.ToSingle(byteArray, 156 - 14); f_sys2new.rmk[1].Cnt_Bad_red = BitConverter.ToUInt32(byteArray, 160 - 14); f_sys2new.rmk[1].Cnt_Bad_yel = BitConverter.ToUInt32(byteArray, 164 - 14); f_sys2new.rmk[1].Sum_skz_d1 = BitConverter.ToSingle(byteArray, 168 - 14); f_sys2new.rmk[1].Sum_pik_d1 = BitConverter.ToSingle(byteArray, 172 - 14); f_sys2new.rmk[1].Sum_skz_d2 = BitConverter.ToSingle(byteArray, 176 - 14); f_sys2new.rmk[1].Sum_pik_d2 = BitConverter.ToSingle(byteArray, 180 - 14); f_sys2new.rmk[1].Prozent_yel = BitConverter.ToSingle(byteArray, 184 - 14); f_sys2new.rmk[1].Prozent_red = BitConverter.ToSingle(byteArray, 188 - 14); f_sys2new.rmk[1].cnt_d1 = BitConverter.ToUInt16(byteArray, 192 - 14); f_sys2new.rmk[1].cnt_d2 = BitConverter.ToUInt16(byteArray, 194 - 14); f_sys2new.rmk[1].defect_file = BitConverter.ToUInt16(byteArray, 196 - 14); f_sys2new.nomer_rmk = BitConverter.ToUInt16(byteArray, 198 - 14); f_sys2new.regim_work_tek = BitConverter.ToUInt16(byteArray, 200 - 14); f_sys2new.count_ALL[0].O1 = BitConverter.ToUInt32(byteArray, 202 - 14); f_sys2new.count_ALL[0].O2 = BitConverter.ToUInt32(byteArray, 206 - 14); f_sys2new.count_ALL[0].T1 = BitConverter.ToUInt32(byteArray, 210 - 14); f_sys2new.count_ALL[0].T2 = BitConverter.ToUInt32(byteArray, 214 - 14); f_sys2new.count_ALL[0].O31 = BitConverter.ToUInt32(byteArray, 218 - 14); f_sys2new.count_ALL[0].O32 = BitConverter.ToUInt32(byteArray, 222 - 14); f_sys2new.count_ALL[0].T31 = BitConverter.ToUInt32(byteArray, 226 - 14); f_sys2new.count_ALL[0].T32 = BitConverter.ToUInt32(byteArray, 230 - 14); //2 f_sys2new.count_ALL[1].O1 = BitConverter.ToUInt32(byteArray, 234 - 14); f_sys2new.count_ALL[1].O2 = BitConverter.ToUInt32(byteArray, 238 - 14); f_sys2new.count_ALL[1].T1 = BitConverter.ToUInt32(byteArray, 242 - 14); f_sys2new.count_ALL[1].T2 = BitConverter.ToUInt32(byteArray, 246 - 14); f_sys2new.count_ALL[1].O31 = BitConverter.ToUInt32(byteArray, 250 - 14); f_sys2new.count_ALL[1].O32 = BitConverter.ToUInt32(byteArray, 254 - 14); f_sys2new.count_ALL[1].T31 = BitConverter.ToUInt32(byteArray, 258 - 14); f_sys2new.count_ALL[1].T32 = BitConverter.ToUInt32(byteArray, 262 - 14); //достаём данные с структуры Sys2 BitConverter.GetBytes(f_sys2new.cnt).CopyTo(byteArray, 14 - 14);//8 BitConverter.GetBytes(f_sys2new.rmk[0].count.O1).CopyTo(byteArray, 18 - 4); BitConverter.GetBytes(f_sys2new.rmk[0].count.O2).CopyTo(byteArray, 19 - 14); BitConverter.GetBytes(f_sys2new.rmk[0].count.T1).CopyTo(byteArray, 20 - 14); BitConverter.GetBytes(f_sys2new.rmk[0].count.T2).CopyTo(byteArray, 22 - 14); BitConverter.GetBytes(f_sys2new.rmk[0].count.O31).CopyTo(byteArray, 24 - 14); BitConverter.GetBytes(f_sys2new.rmk[0].count.O32).CopyTo(byteArray, 25 - 14); BitConverter.GetBytes(f_sys2new.rmk[0].count.T31).CopyTo(byteArray, 26 - 14); BitConverter.GetBytes(f_sys2new.rmk[0].count.T32).CopyTo(byteArray, 28 - 14); BitConverter.GetBytes(f_sys2new.rmk[0].Sr_skz_d1).CopyTo(byteArray, 30 - 14); BitConverter.GetBytes(f_sys2new.rmk[0].Sr_skz_d2).CopyTo(byteArray, 34 - 14); BitConverter.GetBytes(f_sys2new.rmk[0].Sr_pik_d1).CopyTo(byteArray, 38 - 14); BitConverter.GetBytes(f_sys2new.rmk[0].Sr_pik_d2).CopyTo(byteArray, 42 - 14); BitConverter.GetBytes(f_sys2new.rmk[0].pred_skz_d1).CopyTo(byteArray, 46 - 14); BitConverter.GetBytes(f_sys2new.rmk[0].pred_skz_d2).CopyTo(byteArray, 50 - 14); BitConverter.GetBytes(f_sys2new.rmk[0].pred_pik_d1).CopyTo(byteArray, 54 - 14); BitConverter.GetBytes(f_sys2new.rmk[0].pred_pik_d2).CopyTo(byteArray, 58 - 14); BitConverter.GetBytes(f_sys2new.rmk[0].Sr_M_d1).CopyTo(byteArray, 62 - 14); BitConverter.GetBytes(f_sys2new.rmk[0].Sr_M_d2).CopyTo(byteArray, 66 - 14); BitConverter.GetBytes(f_sys2new.rmk[0].Cnt_Bad_red).CopyTo(byteArray, 70 - 14); BitConverter.GetBytes(f_sys2new.rmk[0].Cnt_Bad_yel).CopyTo(byteArray, 76 - 14); BitConverter.GetBytes(f_sys2new.rmk[0].Sum_skz_d1).CopyTo(byteArray, 78 - 14); BitConverter.GetBytes(f_sys2new.rmk[0].Sum_pik_d1).CopyTo(byteArray, 82 - 14); BitConverter.GetBytes(f_sys2new.rmk[0].Sum_skz_d2).CopyTo(byteArray, 86 - 14); BitConverter.GetBytes(f_sys2new.rmk[0].Sum_pik_d2).CopyTo(byteArray, 90 - 14); BitConverter.GetBytes(f_sys2new.rmk[0].Prozent_yel).CopyTo(byteArray, 94 - 14); BitConverter.GetBytes(f_sys2new.rmk[0].Prozent_red).CopyTo(byteArray, 98 - 14); BitConverter.GetBytes(f_sys2new.rmk[0].cnt_d1).CopyTo(byteArray, 102 - 14); BitConverter.GetBytes(f_sys2new.rmk[0].cnt_d2).CopyTo(byteArray, 104 - 14); BitConverter.GetBytes(f_sys2new.rmk[0].defect_file).CopyTo(byteArray, 106 - 14); BitConverter.GetBytes(f_sys2new.nomer_rmk).CopyTo(byteArray, 108 - 14); BitConverter.GetBytes(f_sys2new.regim_work_tek).CopyTo(byteArray, 110 - 14); BitConverter.GetBytes(f_sys2new.count_ALL[0].O1).CopyTo(byteArray, 112 - 14); BitConverter.GetBytes(f_sys2new.count_ALL[0].O2).CopyTo(byteArray, 116 - 14); BitConverter.GetBytes(f_sys2new.count_ALL[0].T1).CopyTo(byteArray, 120 - 14); BitConverter.GetBytes(f_sys2new.count_ALL[0].T2).CopyTo(byteArray, 124 - 14); BitConverter.GetBytes(f_sys2new.count_ALL[0].O31).CopyTo(byteArray, 128 - 14); BitConverter.GetBytes(f_sys2new.count_ALL[0].O32).CopyTo(byteArray, 132 - 14); BitConverter.GetBytes(f_sys2new.count_ALL[0].T31).CopyTo(byteArray, 136 - 14); BitConverter.GetBytes(f_sys2new.count_ALL[0].T32).CopyTo(byteArray, 140 - 14); //2 BitConverter.GetBytes(f_sys2new.rmk[1].count.O1).CopyTo(byteArray, 144 - 14); BitConverter.GetBytes(f_sys2new.rmk[1].count.O2).CopyTo(byteArray, 145 - 14); BitConverter.GetBytes(f_sys2new.rmk[1].count.T1).CopyTo(byteArray, 146 - 14); BitConverter.GetBytes(f_sys2new.rmk[1].count.T2).CopyTo(byteArray, 148 - 14); BitConverter.GetBytes(f_sys2new.rmk[1].count.O31).CopyTo(byteArray, 150 - 14); BitConverter.GetBytes(f_sys2new.rmk[1].count.O32).CopyTo(byteArray, 151 - 14); BitConverter.GetBytes(f_sys2new.rmk[1].count.T31).CopyTo(byteArray, 152 - 14); BitConverter.GetBytes(f_sys2new.rmk[1].count.T32).CopyTo(byteArray, 154 - 14); BitConverter.GetBytes(f_sys2new.rmk[1].Sr_skz_d1).CopyTo(byteArray, 156 - 14); BitConverter.GetBytes(f_sys2new.rmk[1].Sr_skz_d2).CopyTo(byteArray, 160 - 14); BitConverter.GetBytes(f_sys2new.rmk[1].Sr_pik_d1).CopyTo(byteArray, 164 - 14); BitConverter.GetBytes(f_sys2new.rmk[1].Sr_pik_d2).CopyTo(byteArray, 168 - 14); BitConverter.GetBytes(f_sys2new.rmk[1].pred_skz_d1).CopyTo(byteArray, 172 - 14); BitConverter.GetBytes(f_sys2new.rmk[1].pred_skz_d2).CopyTo(byteArray, 176 - 14); BitConverter.GetBytes(f_sys2new.rmk[1].pred_pik_d1).CopyTo(byteArray, 180 - 14); BitConverter.GetBytes(f_sys2new.rmk[1].pred_pik_d2).CopyTo(byteArray, 184 - 14); BitConverter.GetBytes(f_sys2new.rmk[1].Sr_M_d1).CopyTo(byteArray, 188 - 14); BitConverter.GetBytes(f_sys2new.rmk[1].Sr_M_d2).CopyTo(byteArray, 192 - 14); BitConverter.GetBytes(f_sys2new.rmk[1].Cnt_Bad_red).CopyTo(byteArray, 196 - 14); BitConverter.GetBytes(f_sys2new.rmk[1].Cnt_Bad_yel).CopyTo(byteArray, 200 - 14); BitConverter.GetBytes(f_sys2new.rmk[1].Sum_skz_d1).CopyTo(byteArray, 204 - 14); BitConverter.GetBytes(f_sys2new.rmk[1].Sum_pik_d1).CopyTo(byteArray, 208 - 14); BitConverter.GetBytes(f_sys2new.rmk[1].Sum_skz_d2).CopyTo(byteArray, 212 - 14); BitConverter.GetBytes(f_sys2new.rmk[1].Sum_pik_d2).CopyTo(byteArray, 216 - 14); BitConverter.GetBytes(f_sys2new.rmk[1].Prozent_yel).CopyTo(byteArray, 220 - 14); BitConverter.GetBytes(f_sys2new.rmk[1].Prozent_red).CopyTo(byteArray, 224 - 14); BitConverter.GetBytes(f_sys2new.rmk[1].cnt_d1).CopyTo(byteArray, 228 - 14); BitConverter.GetBytes(f_sys2new.rmk[1].cnt_d2).CopyTo(byteArray, 230 - 14); BitConverter.GetBytes(f_sys2new.rmk[1].defect_file).CopyTo(byteArray, 232 - 14); BitConverter.GetBytes(f_sys2new.count_ALL[1].O1).CopyTo(byteArray, 234 - 14); BitConverter.GetBytes(f_sys2new.count_ALL[1].O2).CopyTo(byteArray, 238 - 14); BitConverter.GetBytes(f_sys2new.count_ALL[1].T1).CopyTo(byteArray, 242 - 14); BitConverter.GetBytes(f_sys2new.count_ALL[1].T2).CopyTo(byteArray, 246 - 14); BitConverter.GetBytes(f_sys2new.count_ALL[1].O31).CopyTo(byteArray, 250 - 14); BitConverter.GetBytes(f_sys2new.count_ALL[1].O32).CopyTo(byteArray, 254 - 14); BitConverter.GetBytes(f_sys2new.count_ALL[1].T31).CopyTo(byteArray, 258 - 14); BitConverter.GetBytes(f_sys2new.count_ALL[1].T32).CopyTo(byteArray, 262 - 14); using (var stream = new System.IO.FileStream(path, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write))//запись в файл { //Перемещаемся в файле на 100 байт от начала //stream.Seek(0, System.IO.SeekOrigin.Begin); //Записываем буфер stream.Write(byteArray, 0, byteArray.Length); } }
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType) { Blob bl = (Blob)value; bl.Align(); if (bl.fOwn == true) { if (bl.Length == 0L) { if (destinationType == typeof(string)) { return(""); } else { return(null); } } } else if (destinationType == typeof(string)) { return(bl.GrabString((IntPtr)0)); } if (ReferenceEquals(destinationType, typeof(InstanceDescriptor))) { // ' See the next class converter for details on // ' InstanceDescriptor conversion System.Reflection.ConstructorInfo objC; // objC = objT.GetType.GetConstructor(New Type() {GetType(Single), GetType(Single), GetType(Single), GetType(Single), GetType(Ruler.RulerUnits)}) // Return New InstanceDescriptor(objC, New Object() {objT.Left, objT.Top, objT.Width, objT.Height, objT.Units()}) objC = bl.GetType().GetConstructor(new Type[] { typeof(byte[]), typeof(Type) }); return(new InstanceDescriptor(objC, new object[] { (Blob)value, ((Blob)value).Type })); } if (destinationType.IsEnum == true) { return(BlobUtil.BytesToEnum(bl, destinationType)); } else if (destinationType.IsArray == true && destinationType.GetElementType().IsEnum == true) { return(BlobUtil.BytesToEnum(bl, destinationType.GetElementType())); } if (destinationType.IsClass && (destinationType.BaseType == Blob.Types[(int)BlobTypes.Image] || destinationType == Blob.Types[(int)BlobTypes.Image])) { return(BytesToImage(bl.GrabBytes())); } switch (destinationType) { case var @case when @case == typeof(bool): { return(bl.get_ByteAt(0L) != 0); } case var case1 when case1 == typeof(BigInteger): { return(new BigInteger((byte[])bl)); } case var case2 when case2 == typeof(DateTime): { return(BytesToDate(bl)); } case var case3 when case3 == typeof(DateTime[]): { return(BytesToDateArray(bl)); } case var case4 when case4 == typeof(byte[]): { byte[] a; a = new byte[(int)(bl.Length - 1L + 1)]; Array.Copy((byte[])bl, a, bl.Length); return(a); } case var case5 when case5 == typeof(sbyte[]): { return(ToSByteArray(bl)); } case var case6 when case6 == typeof(Guid[]): case var case7 when case7 == typeof(Guid): { if (destinationType == typeof(Guid)) { return(new Guid(bl.GrabBytes((IntPtr)0, 16))); } int l = 16; int e = (int)(bl.Length / (double)l); int i; int c = (int)(bl.Length - 1L); Guid[] gs; gs = new Guid[e]; e = 0; var loopTo = c; for (i = 0; l >= 0 ? i <= loopTo : i >= loopTo; i += l) { gs[e] = new Guid(bl.GrabBytes((IntPtr)i, l)); e += 1; } return(gs); } case var case8 when case8 == typeof(Color[]): case var case9 when case9 == typeof(Color): { if (destinationType == typeof(Color)) { Color cc; cc = Color.FromArgb(bl); return(cc); } int l = 4; int e = (int)(bl.Length / (double)l); int i; int c = (int)(bl.Length - 1L); Color[] cs; cs = new Color[e]; e = 0; var ptr = bl.DangerousGetHandle(); var loopTo1 = c; for (i = 0; l >= 0 ? i <= loopTo1 : i >= loopTo1; i += l) { Native.CopyMemory(ref l, ptr, (IntPtr)4); cs[e] = Color.FromArgb(l); ptr = ptr + l; e += 1; } return(cs); } case var case10 when case10 == typeof(string): { if (bl.Length == 0L) { return(""); } return(bl.ToString()); } case var case11 when case11 == typeof(decimal[]): case var case12 when case12 == typeof(decimal): { decimal[] d; int[] ints = bl; if (Conversions.ToBoolean(ints.Length % 4)) { throw new ArgumentException("Byte array is not aligned for the Decimal data type."); return(null); } if (destinationType == typeof(decimal)) { if (ints.Length != 4) { Array.Resize(ref ints, 4); } return(new decimal(ints)); } var dec = new int[4]; int e = bl.Count - 1; int i; d = new decimal[e + 1]; var loopTo2 = e; for (i = 0; i <= loopTo2; i++) { Array.Copy(ints, i, dec, 0, 4); d[i] = new decimal(dec); } return(d); } case var case13 when case13 == typeof(double): { return(BitConverter.ToDouble(bl, 0)); } case var case14 when case14 == typeof(float): { return(BitConverter.ToSingle(bl, 0)); } case var case15 when case15 == typeof(ulong): { var u = ToULongArray(new[] { BitConverter.ToInt64(bl, 0) }); return(u[0]); } case var case16 when case16 == typeof(long): { return(BitConverter.ToInt64(bl, 0)); } case var case17 when case17 == typeof(uint): { var u = ToUIntegerArray(new[] { BitConverter.ToInt32(bl, 0) }); return(u[0]); } case var case18 when case18 == typeof(int): { return(BitConverter.ToInt32(bl, 0)); } case var case19 when case19 == typeof(ushort): { var u = ToUShortArray(new[] { BitConverter.ToInt16(bl, 0) }); return(u[0]); } case var case20 when case20 == typeof(short): { return(BitConverter.ToInt16(bl, 0)); } case var case21 when case21 == typeof(char): { return(BitConverter.ToChar(bl, 0)); } case var case22 when case22 == typeof(byte): { return(bl.get_ByteAt(0L)); } case var case23 when case23 == typeof(sbyte): { var u = ToSByteArray(bl); return(u[0]); } case var case24 when case24 == typeof(double[]): case var case25 when case25 == typeof(float[]): case var case26 when case26 == typeof(long[]): case var case27 when case27 == typeof(ulong[]): case var case28 when case28 == typeof(int[]): case var case29 when case29 == typeof(uint[]): case var case30 when case30 == typeof(short[]): case var case31 when case31 == typeof(ushort[]): case var case32 when case32 == typeof(char[]): { object a = Array.CreateInstance(destinationType.GetElementType(), 1); int l; int e; int f = 0; IntPtr ptr; byte[] b = bl; l = Marshal.SizeOf(a((object)0)); e = (int)(b.Length / (double)l); l = b.Length; switch (destinationType.GetElementType()) { case var case33 when case33 == typeof(sbyte): { a = Array.CreateInstance(typeof(byte), e); break; } case var case34 when case34 == typeof(ushort): { a = Array.CreateInstance(typeof(short), e); break; } case var case35 when case35 == typeof(uint): { a = Array.CreateInstance(typeof(int), e); break; } case var case36 when case36 == typeof(ulong): { a = Array.CreateInstance(typeof(long), e); break; } default: { a = Array.CreateInstance(destinationType.GetElementType(), e); break; } } ptr = Marshal.AllocCoTaskMem(l); Marshal.Copy(b, 0, ptr, l); Marshal.Copy(ptr, a, (object)0, e); Marshal.FreeCoTaskMem(ptr); switch (destinationType.GetElementType()) { case var case37 when case37 == typeof(sbyte): { a = ToSByteArray((byte[])a); break; } case var case38 when case38 == typeof(ushort): { a = ToUShortArray((short[])a); break; } case var case39 when case39 == typeof(uint): { a = ToUIntegerArray((int[])a); break; } case var case40 when case40 == typeof(ulong): { a = ToULongArray((long[])a); break; } } return(a); } } if (destinationType.IsValueType) { object o = null; BlobToStructure(bl, ref o); return(o); } return(base.ConvertTo(context, culture, value, destinationType)); }
// public int dimensionToIndex(string dimension) // { // int id = -1; // for (int i = 0; i < identifiers.Length; i++) // { // // if (dimension == identifiers[i]) // { // id = i; // } // } // return id; // } // // public string indexToDimension(int dimensionIndex) // { // return identifiers.ElementAt(dimensionIndex); // } float stringToFloat(string value) { return BitConverter.ToSingle(Encoding.UTF8.GetBytes(value), 0); }
public static float BytesToFloat(byte[] bytes) { return(BitConverter.ToSingle(bytes, 0)); }
public static float ToSingle(byte[] data, int startIndex) { return(BitConverter.ToSingle(Reverse(data, startIndex, 4), 0)); }
public float PeakFloat() { return(BitConverter.ToSingle(bytes, index)); }
public float GetFloat() => BitConverter.ToSingle(GetBytes(4), 0);
public float GetX() { return(BitConverter.ToSingle(Datas, 8)); }
void ReadModbusData(modbusrtu ModbusRtu, byte SlaveAddr, ushort ModbusAddr, DataType datatype, ushort nNumber, ref string[] sValue) { ushort ntype = (ushort)((ModbusAddr / 10000)); ushort naddr = (ushort)((ModbusAddr % 10000)); naddr = (ushort)(naddr - 1); switch (ntype) { case 0: //DO ushort[] coils = new ushort[nNumber]; bool bcoils = ModbusRtu.SendFc1(SlaveAddr, naddr, nNumber, ref coils); if (bcoils) { for (int i = 0; i < nNumber; i++) { sValue[i] = coils[i].ToString(); } } else { for (int i = 0; i < nNumber; i++) { sValue[i] = "0"; } } break; case 1: //DI ushort[] dis = new ushort[nNumber]; bool bdis = ModbusRtu.SendFc2(SlaveAddr, naddr, nNumber, ref dis); if (bdis) { for (int i = 0; i < nNumber; i++) { sValue[i] = dis[i].ToString(); } } else { for (int i = 0; i < nNumber; i++) { sValue[i] = "0"; } } break; case 4: //AO if (datatype.Equals("uint16")) { ushort[] registerhold = new ushort[nNumber]; bool bhold = ModbusRtu.SendFc3(SlaveAddr, naddr, nNumber, ref registerhold); if (bhold) { for (int i = 0; i < nNumber; i++) { sValue[i] = registerhold[i].ToString(); } } else { for (int i = 0; i < nNumber; i++) { sValue[i] = "0"; } } } else if (datatype.Equals("int16")) { ushort[] registerhold = new ushort[nNumber]; bool bhold = ModbusRtu.SendFc3(SlaveAddr, naddr, nNumber, ref registerhold); if (bhold) { for (int i = 0; i < nNumber; i++) { sValue[i] = ((short)registerhold[i]).ToString(); } } else { for (int i = 0; i < nNumber; i++) { sValue[i] = "0"; } } } else if (datatype.Equals("float")) { ushort[] registerhold = new ushort[2 * nNumber]; bool bhold = ModbusRtu.SendFc3(SlaveAddr, naddr, (ushort)(2 * nNumber), ref registerhold); if (bhold) { for (int i = 0; i < nNumber; i++) { int intValue = (int)registerhold[i * 2 + 1]; intValue <<= 16; intValue += (int)registerhold[i * 2 + 0]; sValue[i] = BitConverter.ToSingle(BitConverter.GetBytes(intValue), 0).ToString(); } } else { for (int i = 0; i < nNumber; i++) { sValue[i] = "0"; } } } else if (datatype.Equals("int32")) { ushort[] registerhold = new ushort[2 * nNumber]; bool bhold = ModbusRtu.SendFc3(SlaveAddr, naddr, (ushort)(2 * nNumber), ref registerhold); if (bhold) { for (int i = 0; i < nNumber; i++) { int intValue = (int)registerhold[2 * i + 1]; intValue <<= 16; intValue += (int)registerhold[2 * i + 0]; sValue[i] = intValue.ToString(); } } else { for (int i = 0; i < nNumber; i++) { sValue[i] = "0"; } } } else if (datatype.Equals("uint32")) { ushort[] registerhold = new ushort[2 * nNumber]; bool bhold = ModbusRtu.SendFc3(SlaveAddr, naddr, (ushort)(2 * nNumber), ref registerhold); if (bhold) { for (int i = 0; i < nNumber; i++) { UInt32 intValue = (UInt32)registerhold[2 * i + 1]; intValue <<= 16; intValue += (UInt32)registerhold[2 * i + 0]; sValue[i] = intValue.ToString(); } } else { for (int i = 0; i < nNumber; i++) { sValue[i] = "0"; } } } break; case 3: //AI if (datatype.Equals("uint16")) { ushort[] registerinput = new ushort[nNumber]; bool binput = ModbusRtu.SendFc4(SlaveAddr, naddr, nNumber, ref registerinput); if (binput) { for (int i = 0; i < nNumber; i++) { sValue[i] = registerinput[i].ToString(); } } else { for (int i = 0; i < nNumber; i++) { sValue[i] = "0"; } } } else if (datatype.Equals("int16")) { ushort[] registerinput = new ushort[nNumber]; bool binput = ModbusRtu.SendFc4(SlaveAddr, naddr, nNumber, ref registerinput); if (binput) { for (int i = 0; i < nNumber; i++) { sValue[i] = ((short)registerinput[i]).ToString(); } } else { for (int i = 0; i < nNumber; i++) { sValue[i] = "0"; } } } else if (datatype.Equals("float")) { ushort[] registerinput = new ushort[2 * nNumber]; bool binput = ModbusRtu.SendFc4(SlaveAddr, naddr, (ushort)(2 * nNumber), ref registerinput); if (binput) { for (int i = 0; i < nNumber; i++) { int intValue = (int)registerinput[2 * i + 1]; intValue <<= 16; intValue += (int)registerinput[2 * i + 0]; sValue[i] = BitConverter.ToSingle(BitConverter.GetBytes(intValue), 0).ToString(); } } else { for (int i = 0; i < nNumber; i++) { sValue[i] = "0"; } } } else if (datatype.Equals("int32")) { ushort[] registerinput = new ushort[2 * nNumber]; bool binput = ModbusRtu.SendFc4(SlaveAddr, naddr, (ushort)(2 * nNumber), ref registerinput); if (binput) { for (int i = 0; i < nNumber; i++) { int intValue = (int)registerinput[2 * i + 1]; intValue <<= 16; intValue += (int)registerinput[2 * i + 0]; sValue[i] = intValue.ToString(); } } else { for (int i = 0; i < nNumber; i++) { sValue[i] = "0"; } } } else if (datatype.Equals("uint32")) { ushort[] registerinput = new ushort[2 * nNumber]; bool binput = ModbusRtu.SendFc4(SlaveAddr, naddr, (ushort)(2 * nNumber), ref registerinput); if (binput) { for (int i = 0; i < nNumber; i++) { UInt32 intValue = (UInt32)registerinput[2 * i + 1]; intValue <<= 16; intValue += (UInt32)registerinput[2 * i + 0]; sValue[i] = intValue.ToString(); } } else { for (int i = 0; i < nNumber; i++) { sValue[i] = "0"; } } } break; } Invoke(showInfo, new object[] { ModbusRtu.modbusStatus, 1 }); }
private void convertCharacterByteStream() { m_characterList = new List <CharacterPackage>(); int dataIdx = 0; while (dataIdx < m_characterByteData.Length - 1) { CharacterPackage characterPack = new CharacterPackage(); // get bone Mapping size int intValue = BitConverter.ToInt32(m_characterByteData, dataIdx); dataIdx += size_int; characterPack.bMSize = intValue; // get bone Mapping size intValue = BitConverter.ToInt32(m_characterByteData, dataIdx); dataIdx += size_int; characterPack.sSize = intValue; // get root dag size intValue = BitConverter.ToInt32(m_characterByteData, dataIdx); dataIdx += size_int; characterPack.rootDagSize = intValue; // get root dag path byte[] rootDagByte = new byte[intValue]; Buffer.BlockCopy(m_characterByteData, dataIdx, rootDagByte, 0, intValue); dataIdx += intValue; characterPack.rootDag = Encoding.ASCII.GetString(rootDagByte); // get dag sizes characterPack.dagSizes = new int[characterPack.bMSize]; for (int i = 0; i < characterPack.bMSize; i++) { characterPack.dagSizes[i] = BitConverter.ToInt32(m_characterByteData, dataIdx); dataIdx += size_int; } // get bone mapping characterPack.boneMapping = new string[characterPack.bMSize]; for (int i = 0; i < characterPack.bMSize; i++) { int stringSize = characterPack.dagSizes[i]; byte[] dagByte = new byte[stringSize]; Buffer.BlockCopy(m_characterByteData, dataIdx, dagByte, 0, stringSize); dataIdx += stringSize; characterPack.boneMapping[i] = Encoding.ASCII.GetString(dagByte); } // get dag skeleton sizes characterPack.sdagSizes = new int[characterPack.sSize]; for (int i = 0; i < characterPack.sSize; i++) { characterPack.sdagSizes[i] = BitConverter.ToInt32(m_characterByteData, dataIdx); dataIdx += size_int; } //get skeleton mapping characterPack.skeletonMapping = new string[characterPack.sSize]; for (int i = 0; i < characterPack.sSize; i++) { int stringSize = characterPack.sdagSizes[i]; byte[] sdagByte = new byte[stringSize]; Buffer.BlockCopy(m_characterByteData, dataIdx, sdagByte, 0, stringSize); dataIdx += stringSize; characterPack.skeletonMapping[i] = Encoding.ASCII.GetString(sdagByte); } //get skeleton bone postions characterPack.bonePosition = new float[characterPack.sSize * 3]; for (int i = 0; i < characterPack.sSize; i++) { characterPack.bonePosition[i * 3] = BitConverter.ToSingle(m_characterByteData, dataIdx); dataIdx += size_float; characterPack.bonePosition[i * 3 + 1] = BitConverter.ToSingle(m_characterByteData, dataIdx); dataIdx += size_float; characterPack.bonePosition[i * 3 + 2] = BitConverter.ToSingle(m_characterByteData, dataIdx); dataIdx += size_float; } //get skeleton bone rotations characterPack.boneRotation = new float[characterPack.sSize * 4]; for (int i = 0; i < characterPack.sSize; i++) { characterPack.boneRotation[i * 4] = BitConverter.ToSingle(m_characterByteData, dataIdx); dataIdx += size_float; characterPack.boneRotation[i * 4 + 1] = BitConverter.ToSingle(m_characterByteData, dataIdx); dataIdx += size_float; characterPack.boneRotation[i * 4 + 2] = BitConverter.ToSingle(m_characterByteData, dataIdx); dataIdx += size_float; characterPack.boneRotation[i * 4 + 3] = BitConverter.ToSingle(m_characterByteData, dataIdx); dataIdx += size_float; } //get skeleton bone scales characterPack.boneScale = new float[characterPack.sSize * 3]; for (int i = 0; i < characterPack.sSize; i++) { characterPack.boneScale[i * 3] = BitConverter.ToSingle(m_characterByteData, dataIdx); dataIdx += size_float; characterPack.boneScale[i * 3 + 1] = BitConverter.ToSingle(m_characterByteData, dataIdx); dataIdx += size_float; characterPack.boneScale[i * 3 + 2] = BitConverter.ToSingle(m_characterByteData, dataIdx); dataIdx += size_float; } m_characterList.Add(characterPack); } Array.Clear(m_characterByteData, 0, m_characterByteData.Length); m_characterByteData = null; GC.Collect(); }
public float ReadFloat() { byte[] temp = BitConverter.GetBytes(reader.ReadSingle()); Array.Reverse(temp); return(BitConverter.ToSingle(temp, 0)); }