예제 #1
0
        private void Button_auto_Click(object sender, EventArgs e)
        {
            File.WriteAllText(SourceFile + ".escpos", "");
            File.WriteAllText(SourceFile + ".list", "");
            textBox_code.Select(0, 0);
            var asciiString = new StringBuilder();

            while (textBox_code.SelectionStart < textBox_code.TextLength)
            {
                var saveStr = new StringBuilder();
                //run "Find" button event as "Auto"
                Button_find_Click(button_auto, EventArgs.Empty);
                if (ParseEscPos.commandName != "")
                {
                    ParseEscPos.FindCommandParameter();
                    //Save ASCII string if collected till now
                    if (asciiString.Length != 0)
                    {
                        saveStr.Append("#" + ParseEscPos.commandFramePosition + " RAW data [" + asciiString + "]\r\n");
                        if (Accessory.PrintableHex(asciiString.ToString()))
                        {
                            saveStr.Append("ASCII string: \"" + Encoding.GetEncoding(Settings.Default.CodePage)
                                           .GetString(Accessory.ConvertHexToByteArray(asciiString.ToString())) + "\"\r\n");
                        }
                        saveStr.Append("\r\n");
                        File.AppendAllText(SourceFile + ".list", asciiString + "\r\n",
                                           Encoding.GetEncoding(Settings.Default.CodePage));
                        asciiString.Clear();
                    }

                    //collect command into file

                    /* RAW [12 34]
                     *  Command: "12 34" - "Description"
                     *  Printer model: "VKP80II-SX"
                     *  Parameter: "n" = "1234"[Word] - "Description"
                     *  Parameter: ...
                     */
                    saveStr.Append("#" + ParseEscPos.commandFramePosition + " RAW data [" + textBox_code.SelectedText +
                                   "]\r\n");
                    if (ParseEscPos.itIsReply)
                    {
                        saveStr.Append("Reply: [" + ParseEscPos.commandName + "] - \"" + ParseEscPos.commandDesc +
                                       "\"\r\n");
                    }
                    else
                    {
                        saveStr.Append("Command: [" + ParseEscPos.commandName + "] - \"" + ParseEscPos.commandDesc +
                                       "\"\r\n");
                    }
                    for (var i = 0; i < ParseEscPos.commandParamSize.Count; i++)
                    {
                        saveStr.Append("\tParameter = ");
                        saveStr.Append("\"" + ParseEscPos.commandParamValue[i] + "\"");

                        saveStr.Append("[" + ParseEscPos.commandParamType[i] + "] - \"" + ParseEscPos
                                       .commandParamDesc[i].TrimStart('\r').TrimStart('\n').TrimStart('\r').TrimStart('\n')
                                       .TrimEnd('\r').TrimEnd('\n').TrimEnd('\r').TrimEnd('\n').Replace("\n", "\n\t\t\t\t"));
                        if (ParseEscPos.commandParamType[i].ToLower() == ParseEscPos.DataTypes.Error)
                        {
                            saveStr.Append(": " + GetErrorDesc(int.Parse(ParseEscPos.commandParamValue[i])));
                        }
                        saveStr.Append("\", RAW [" +
                                       Accessory.ConvertByteArrayToHex(ParseEscPos.commandParamRAWValue[i].ToArray()) +
                                       "]\r\n");

                        if (ParseEscPos.commandParamType[i].ToLower() == ParseEscPos.DataTypes.Bitfield)
                        {
                            var b = byte.Parse(ParseEscPos.commandParamValue[i]);
                            for (var i1 = 0; i1 < 8; i1++)
                            {
                                saveStr.Append("\t\t[bit" + i1 + "]\" = \"");
                                saveStr.Append((Accessory.GetBit(b, (byte)i1) ? (byte)1 : (byte)0) + "\" - \"");
                                saveStr.Append(dataGridView_commands.Rows[ParseEscPos.commandParamDbLineNum[i] + i1 + 1]
                                               .Cells[ParseEscPos.CSVColumns.CommandDescription].Value.ToString()
                                               .Replace("\n", "\n\t\t\t\t"));
                                saveStr.Append("\"\r\n");
                            }
                        }
                    }

                    saveStr.Append("\r\n");
                    File.AppendAllText(SourceFile + ".list", textBox_code.SelectedText + "\r\n",
                                       Encoding.GetEncoding(Settings.Default.CodePage));
                    File.AppendAllText(SourceFile + ".escpos", saveStr.ToString(),
                                       Encoding.GetEncoding(Settings.Default.CodePage));
                }
                else //consider this as a string and collect
                {
                    asciiString.Append(textBox_code.SelectedText);
                }

                textBox_code.SelectionStart = textBox_code.SelectionStart + textBox_code.SelectionLength;
            }

            if (asciiString.Length != 0)
            {
                var saveStr = new StringBuilder();
                saveStr.Append("#" + ParseEscPos.commandFramePosition + " RAW data [" + asciiString + "]\r\n");
                if (Accessory.PrintableHex(asciiString.ToString()))
                {
                    saveStr.Append("ASCII string: \"" + Encoding.GetEncoding(Settings.Default.CodePage)
                                   .GetString(Accessory.ConvertHexToByteArray(asciiString.ToString())) + "\"\r\n");
                }
                saveStr.Append("\r\n");
                File.AppendAllText(SourceFile + ".list", asciiString + "\r\n",
                                   Encoding.GetEncoding(Settings.Default.CodePage));
                File.AppendAllText(SourceFile + ".escpos", saveStr.ToString(),
                                   Encoding.GetEncoding(Settings.Default.CodePage));
                asciiString.Clear();
            }
        }
예제 #2
0
        private void Button_find_Click(object sender, EventArgs e)
        {
            textBox_command.Text = "";
            textBox_commandDesc.Clear();
            ResultDatabase.Clear();
            if (textBox_code.SelectionStart != textBox_code.Text.Length) //check if cursor position in not last
            {
                if (textBox_code.Text.Substring(textBox_code.SelectionStart, 1) == " ")
                {
                    textBox_code.SelectionStart++;
                }
            }
            if (textBox_code.SelectionStart != 0) //check if cursor position in not first
            {
                if (textBox_code.Text.Substring(textBox_code.SelectionStart - 1, 1) != " " &&
                    textBox_code.Text.Substring(textBox_code.SelectionStart, 1) != " ")
                {
                    textBox_code.SelectionStart--;
                }
            }
            label_currentPosition.Text = textBox_code.SelectionStart + "/" + textBox_code.TextLength;
            if (ParseEscPos.FindCommand(textBox_code.SelectionStart))
            {
                ParseEscPos.FindCommandParameter();
                if (sender != button_auto) //update interface only if it's no auto-parsing mode
                {
                    dataGridView_commands.CurrentCell = dataGridView_commands.Rows[ParseEscPos.commandDbLineNum]
                                                        .Cells[ParseEscPos.CSVColumns.CommandName];
                    if (ParseEscPos.itIsReply)
                    {
                        textBox_command.Text = "[REPLY] " + ParseEscPos.commandName;
                    }
                    else
                    {
                        textBox_command.Text = "[COMMAND] " + ParseEscPos.commandName;
                    }
                    if (ParseEscPos.crcFailed)
                    {
                        textBox_commandDesc.Text += "!!!CRC FAILED!!! ";
                    }
                    if (ParseEscPos.lengthIncorrect)
                    {
                        textBox_commandDesc.Text += "!!!FRAME LENGTH INCORRECT!!! ";
                    }
                    textBox_commandDesc.Text = ParseEscPos.commandDesc;
                    for (var i = 0; i < ParseEscPos.commandParamSize.Count; i++)
                    {
                        var row = ResultDatabase.NewRow();
                        row[ResultColumns.Value] = ParseEscPos.commandParamValue[i];
                        row[ResultColumns.Type]  = ParseEscPos.commandParamType[i];
                        row[ResultColumns.Raw]   =
                            Accessory.ConvertByteArrayToHex(ParseEscPos.commandParamRAWValue[i].ToArray());
                        row[ResultColumns.Description] = ParseEscPos.commandParamDesc[i];
                        if (ParseEscPos.commandParamType[i].ToLower() == ParseEscPos.DataTypes.Error)
                        {
                            row[ResultColumns.Description] +=
                                ": " + GetErrorDesc(int.Parse(ParseEscPos.commandParamValue[i]));
                        }
                        ResultDatabase.Rows.Add(row);

                        if (ParseEscPos.commandParamType[i].ToLower() == ParseEscPos.DataTypes.Bitfield
                            ) //add bitfield display
                        {
                            var b = byte.Parse(ParseEscPos.commandParamValue[i]);
                            for (var i1 = 0; i1 < 8; i1++)
                            {
                                row = ResultDatabase.NewRow();
                                row[ResultColumns.Value] =
                                    (Accessory.GetBit(b, (byte)i1) ? (byte)1 : (byte)0).ToString();
                                row[ResultColumns.Type]        = "bit" + i1;
                                row[ResultColumns.Description] = dataGridView_commands
                                                                 .Rows[ParseEscPos.commandParamDbLineNum[i] + i1 + 1]
                                                                 .Cells[ParseEscPos.CSVColumns.CommandDescription].Value;
                                ResultDatabase.Rows.Add(row);
                            }
                        }
                    }
                }

                textBox_code.Select(textBox_code.SelectionStart, ParseEscPos.commandBlockLength);
            }
            else //no command found. consider it's a string
            {
                var i = 3;
                while (!ParseEscPos.FindCommand(textBox_code.SelectionStart + i) &&
                       textBox_code.SelectionStart + i < textBox_code.TextLength) //looking for a non-parseable part end
                {
                    i += 3;
                }
                ParseEscPos.commandName = "";
                textBox_code.Select(textBox_code.SelectionStart, i);
                if (sender != button_auto)
                {
                    textBox_command.Text = "\"" + textBox_code.SelectedText + "\"";
                    dataGridView_commands.CurrentCell = dataGridView_commands.Rows[0].Cells[0];
                    if (Accessory.PrintableHex(textBox_code.SelectedText))
                    {
                        textBox_commandDesc.Text = "\"" + Encoding.GetEncoding(Settings.Default.CodePage)
                                                   .GetString(Accessory.ConvertHexToByteArray(textBox_code.SelectedText)) + "\"";
                    }
                }
            }

            textBox_code.ScrollToCaret();
        }