123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- //Add code
- using System.Runtime.InteropServices; //ini파일 로드 필요라이브러리
- namespace RF_TRIO_PLL_ZIG
- {
- public partial class Debug : Form
- {
- int LineLimit = 500;
- [DllImport("user32.dll")]
- public static extern int SendMessage(IntPtr hWnd, Int32 wMsg, bool wParam, Int32 lParam);
- private const int WM_SETREDRAW = 11;
- Serial serial;
- public RadioButton RadioButton_ascii { get => radioButton_ascii; set => radioButton_ascii = value; }
- public RadioButton RadioButton_hex { get => radioButton_hex; set => radioButton_hex = value; }
- public Debug()
- {
-
- InitializeComponent();
-
- }
- #if true
- public void Data_Recv_Str(string text)
- {
- int nLimitLines = Convert.ToInt32(LineLimit); //제한 라인 수
- try
- {
- try
- {
- SendMessage(this.Handle, WM_SETREDRAW, false, 0);
- }
- catch (Exception e) { MessageBox.Show(e.StackTrace); }
- if (tbReceived.Lines.Length > nLimitLines)
- {
- LinkedList<string> tempLines = new LinkedList<string>(tbReceived.Lines);
- while ((tempLines.Count - nLimitLines) > 0)
- {
- tempLines.RemoveFirst();
- }
- tbReceived.Lines = tempLines.ToArray();
- }
- try
- {
- SendMessage(this.Handle, WM_SETREDRAW, true, 0);
- }
- catch { return; }
- tbReceived.AppendText(text);
- tbReceived.SelectionStart = tbReceived.Text.Length;//맨 마지막 선택...
- tbReceived.ScrollToCaret();
- }
- catch { try { SendMessage(this.Handle, WM_SETREDRAW, true, 0); } catch { return; } }
- }
- #endif
- #if false
- public void Data_Recv_Hex(byte[] text)
- {
- int nLimitLines = Convert.ToInt32(LineLimit); //제한 라인 수
- try
- {
- try
- {
- SendMessage(this.Handle, WM_SETREDRAW, false, 0);
- }
- catch (Exception e) { MessageBox.Show(e.StackTrace); }
- if (tbReceived.Lines.Length > nLimitLines)
- {
- LinkedList<string> tempLines = new LinkedList<string>(tbReceived.Lines);
- while ((tempLines.Count - nLimitLines) > 0)
- {
- tempLines.RemoveFirst();
- }
- tbReceived.Lines = tempLines.ToArray();
- }
- try
- {
- SendMessage(this.Handle, WM_SETREDRAW, true, 0);
- }
- catch { return; }
- tbReceived.AppendText(text.ToString());
- tbReceived.SelectionStart = tbReceived.Text.Length;//맨 마지막 선택...
- tbReceived.ScrollToCaret();
- }
- catch { try { SendMessage(this.Handle, WM_SETREDRAW, true, 0); } catch { return; } }
- }
- #endif
- public void Data_Send(byte[] text)
- {
- string AppendMessage = "\n[TX]";
- int nLimitLines = Convert.ToInt32(LineLimit); //제한 라인 수
- try
- {
- for (int i = 0; i < text.Length; i++)
- {
- AppendMessage += Convert.ToString(text[i], 16);
- }
- tbReceived.AppendText(AppendMessage);
- try
- {
- SendMessage(this.Handle, WM_SETREDRAW, false, 0);
- }
- catch { return; }
- if (tbReceived.Lines.Length > nLimitLines)
- {
- LinkedList<string> tempLines = new LinkedList<string>(tbReceived.Lines);
- while ((tempLines.Count - nLimitLines) > 0)
- {
- tempLines.RemoveFirst();
- }
- tbReceived.Lines = tempLines.ToArray();
- }
- try
- {
- SendMessage(this.Handle, WM_SETREDRAW, true, 0);
- }
- catch { return; }
- tbReceived.Select(tbReceived.Text.Length, 0);
- tbReceived.ScrollToCaret();
- }
- finally { }
- }
-
- public void Serial_ClassSet(object serial)
- {
- this.serial = (Serial)serial;
- }
- private void Button_Send_Click(object sender, EventArgs e)
- {
- try
- {
- this.serial.Serial_DataSend(Encoding.ASCII.GetBytes(textBox_senddata.Text));
- }
- catch (System.Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- private void Button_Clear_Click(object sender, EventArgs e)
- {
- try
- {
- this.tbReceived.Text = "";
- }
- finally { }
- }
- public void hex_to_ascii_radiobuttonConvert()
- {
- radioButton_hex.Checked = true;
- radioButton_ascii.Checked = false;
- }
- public void ascii_to_hex_radiobuttonConvert()
- {
- radioButton_ascii.Checked = true;
- radioButton_hex.Checked = false;
- }
- }
- }
|