private void ReadDataRecieved(bool DataOk, ushort[] ParamRTU, object param)
 {
     if (InvokeRequired)
     {
         Invoke(new AsynchSerialPort.DataRecievedRTU(ReadDataRecieved), DataOk, ParamRTU);
     }
     else
     {
         try
         {
             if (!DataOk)
             {
                 ErrorMessage(texts[8]);
             }
             else
             {
                 FloatStruct f = new FloatStruct();
                 f.Word1           = ParamRTU[0];
                 f.Word2           = ParamRTU[1];
                 nowReading        = true;
                 floatTextBox.Text = f.Float.ToString();
                 longTextBox.Text  = "0x" + f.ULong.ToString("X8");
                 nowReading        = false;
             }
         }
         catch
         {
         }
     }
 }
        private void writeBtn_Click(object sender, EventArgs e)
        {
            ushort w1 = 0;
            ushort w2 = 0;

            try
            {
                ulong       u  = ConvertFuncs.StrToULong(longTextBox.Text);
                FloatStruct fs = new FloatStruct();
                fs.ULong = u;
                w1       = fs.Word1;
                w2       = fs.Word2;
            }
            catch
            {
                ErrorMessage(texts[9]);
                return;
            }

            ushort Addr = 0;

            if (!CheckAddr(out Addr))
            {
                ErrorMessage(texts[6]);
                return;
            }

            serialPort.SetDataRTU(Addr, WriteDataRecieved, RequestPriority.Normal, w1, w2);
        }
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            if ((!floatTextBox.Focused) || nowReading)
            {
                return;
            }
            float f = 0;

            if (float.TryParse(floatTextBox.Text, out f))
            {
                FloatStruct fs = new FloatStruct();
                fs.Float         = f;
                longTextBox.Text = "0x" + fs.ULong.ToString("X8");
            }
        }
 private void textBox2_TextChanged(object sender, EventArgs e)
 {
     if ((!longTextBox.Focused) || nowReading)
     {
         return;
     }
     try
     {
         ulong       u  = ConvertFuncs.StrToULong(longTextBox.Text);
         FloatStruct fs = new FloatStruct();
         fs.ULong          = u;
         floatTextBox.Text = fs.Float.ToString();
     }
     catch
     {
     }
 }
        /// <summary>
        /// write a float struct
        /// </summary>
        /// <param name="data"></param>
        public void Write(ref float data)
        {
            if (Length + 4 > _Buffer.Length)
            {
                _capacity += 4;
                Resize();
            }
            var value = new FloatStruct()
            {
                Value = data
            };

            _Buffer[Length]     = value.Byte0;
            _Buffer[Length + 1] = value.Byte1;
            _Buffer[Length + 2] = value.Byte2;
            _Buffer[Length + 3] = value.Byte3;
            Length += 4;
        }
Exemple #6
0
            internal Texture(BinaryReaderEx br, TPFPlatform platform, byte flag2, byte encoding)
            {
                uint fileOffset = br.ReadUInt32();
                int  fileSize   = br.ReadInt32();

                Format  = br.ReadByte();
                Type    = br.ReadEnum8 <TexType>();
                Mipmaps = br.ReadByte();
                Flags1  = br.AssertByte(0, 1, 2, 3);

                if (platform != TPFPlatform.PC)
                {
                    Header        = new TexHeader();
                    Header.Width  = br.ReadInt16();
                    Header.Height = br.ReadInt16();

                    if (platform == TPFPlatform.Xbox360)
                    {
                        br.AssertInt32(0);
                    }
                    else if (platform == TPFPlatform.PS3)
                    {
                        Header.Unk1 = br.ReadInt32();
                        if (flag2 != 0)
                        {
                            Header.Unk2 = br.AssertInt32(0, 0x69E0, 0xAAE4);
                        }
                    }
                    else if (platform == TPFPlatform.PS4 || platform == TPFPlatform.Xbone)
                    {
                        Header.TextureCount = br.AssertInt32(1, 6);
                        Header.Unk2         = br.AssertInt32(0xD);
                    }
                }

                uint nameOffset     = br.ReadUInt32();
                bool hasFloatStruct = br.AssertInt32(0, 1) == 1;

                if (platform == TPFPlatform.PS4 || platform == TPFPlatform.Xbone)
                {
                    Header.DXGIFormat = br.ReadInt32();
                }

                if (hasFloatStruct)
                {
                    FloatStruct = new FloatStruct(br);
                }

                Bytes = br.GetBytes(fileOffset, fileSize);
                if (Flags1 == 2 || Flags1 == 3)
                {
                    Bytes = DCX.Decompress(Bytes, out DCX.Type type);
                    if (type != DCX.Type.DCP_EDGE)
                    {
                        throw new NotImplementedException($"TPF compression is expected to be DCP_EDGE, but it was {type}");
                    }
                }

                if (encoding == 1)
                {
                    Name = br.GetUTF16(nameOffset);
                }
                else if (encoding == 0 || encoding == 2)
                {
                    Name = br.GetShiftJIS(nameOffset);
                }
            }