Example #1
0
        private void btnCrc_Click(object sender, EventArgs e)
        {
            var value = tbIn.Text;

            byte[] data = cbIsAscii.Checked ? Encoding.Default.GetBytes(value) : StringByteUtils.StringToBytes(value);

            tbCrc16.Text     = StringByteUtils.BytesToString(CRC.Crc16(data, data.Length));
            tbCrcc.Text      = StringByteUtils.BytesToString(CRC.CRC16_C(data));
            tbUpdateCRC.Text = StringByteUtils.BytesToString(StringByteUtils.GetBytes(CRC.UpdateCRC(data, data.Length), true));
            tbGBcrc16.Text   = $"##{value.Length.ToString().PadLeft(4, '0')}{value}{StringByteUtils.BytesToString(CRC.GBcrc16(data, data.Length)).Replace(" ", "")}";
            tbHBcrc16.Text   = $"##{value.Length.ToString().PadLeft(4, '0')}{value}{StringByteUtils.BytesToString(CRC.HBcrc16(data, data.Length)).Replace(" ", "")}";
        }
Example #2
0
 private async void AutoReply_LoadAsync(object sender, EventArgs e)
 {
     foreach (var item in await Global.AutoReplyConfig !.GetAsync())
     {
         DataGridViewRow         row = new DataGridViewRow();
         DataGridViewTextBoxCell key = new DataGridViewTextBoxCell();
         key.Value = item.Key;
         row.Cells.Add(key);
         DataGridViewTextBoxCell value = new DataGridViewTextBoxCell();
         value.Value = StringByteUtils.BytesToString(item.Value.value);
         row.Cells.Add(value);
         DataGridViewTextBoxCell delay = new DataGridViewTextBoxCell();
         delay.Value = item.Value.delayTime;
         row.Cells.Add(delay);
         dataGridView1.Rows.Add(row);
     }
 }
Example #3
0
        private void BtnFloatToHex_Click(object sender, EventArgs e)
        {
            rtbOutput.Text = string.Empty;
            if (string.IsNullOrEmpty(rtbInput.Text))
            {
                return;
            }
            btnFloatToHex.Enabled = false;

            string[] splitStr = rtbInput.Text.Split('\n');

            _ = Task.Run(async() =>
            {
                var stringBuilder = new StringBuilder();
                for (int j = 0; j < splitStr.Length; j++)
                {
                    string[] items = splitStr[j].Split(new string[] { tbSplit.Text }, StringSplitOptions.RemoveEmptyEntries);
                    for (int i = 0; i < items.Length; i++)
                    {
                        try
                        {
                            float tempf  = float.Parse(items[i]);
                            byte[] tempb = BitConverter.GetBytes(tempf);
                            if (cbHB.Checked)
                            {
                                Array.Reverse(tempb);
                            }
                            stringBuilder.Append(StringByteUtils.BytesToString(tempb));
                        }
                        catch
                        {
                            MessageBox.Show("请输入正确要转换的数[第" + (j + 1) + "行,第" + (i + 1) + "个]");
                        }
                    }
                    stringBuilder.Append('\n');
                }
                await Task.Factory.FromAsync(BeginInvoke(new Action(() =>
                {
                    rtbOutput.AppendText(stringBuilder.ToString());
                    btnFloatToHex.Enabled = true;
                })), EndInvoke);
            });
        }
Example #4
0
        private void BtnAsciiToHex_Click(object sender, EventArgs e)
        {
            rtbOutput.Text = string.Empty;
            if (string.IsNullOrEmpty(rtbInput.Text))
            {
                return;
            }
            btnAsciiToHex.Enabled = false;

            var content = rtbInput.Text;

            _ = Task.Run(async() =>
            {
                string hexStr = StringByteUtils.BytesToString(Encoding.ASCII.GetBytes(content));
                await Task.Factory.FromAsync(BeginInvoke(new Action(() =>
                {
                    rtbOutput.AppendText(hexStr);
                    btnAsciiToHex.Enabled = true;
                })), EndInvoke);
            });
        }