Ejemplo n.º 1
0
        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            ComPort com = ComPort.Instance;

            if (com.IsOpen)
            {
                com.Close();
            }
        }
Ejemplo n.º 2
0
        private void btnClose_Click(object sender, EventArgs e)
        {
            ComPort com = ComPort.Instance;

            if (com.IsOpen)
            {
                com.Close();
                //com.Dispose();
                //com = null;
            }
        }
Ejemplo n.º 3
0
        private void btnOpen_Click(object sender, EventArgs e)
        {
            //read port status
            ComSetting.Port.PortName = ComboPortList.Text;
            ComSetting.Port.BaudRate = Int32.Parse(ComboBr.Text);
            ComSetting.Port.DataBits = ComboDb.SelectedIndex + 5;
            ComSetting.Port.Parity = (Parity)ComboParity.SelectedIndex;
            ComSetting.Port.StopBits = (StopBits)ComboSb.SelectedIndex;
            ComSetting.Port.Handshake = (Handshake)ComboFlow.SelectedIndex;

            //read port option
            if (radioButton2.Checked)
                ComSetting.Option.AppendToSend = ComSetting.Option.AppendType.AppendCR;
            else if (radioButton3.Checked)
                ComSetting.Option.AppendToSend = ComSetting.Option.AppendType.AppendLF;
            else if (radioButton4.Checked)
                ComSetting.Option.AppendToSend = ComSetting.Option.AppendType.AppendCRLF;
            else
                ComSetting.Option.AppendToSend = ComSetting.Option.AppendType.AppendNothing;

            ComSetting.Option.HexOutput = checkBox1.Checked;
            ComSetting.Option.MonoFont = checkBox2.Checked;
            ComSetting.Option.LocalEcho = checkBox3.Checked;
            ComSetting.Option.StayOnTop = checkBox4.Checked;
            ComSetting.Option.FilterUseCase = checkBox5.Checked;

            ComPort com = ComPort.Instance;

            if (com.IsOpen)
            {
                com.Close();
                btnOpen.Text = "disconnect";
            }
            else
            {
                com.Open();
                richTextBox1.Focus();
                btnOpen.Text = "connect";
            }
        }
Ejemplo n.º 4
0
        private void btnCalf_Click(object sender, EventArgs e)
        {
            SerialPort sPort = new SerialPort();
            ComPort com = ComPort.Instance;
            byte[] byteSendData = new byte[100];
            string bSendData;

            try
            {
                gLegCtl.GCalfStart = !gLegCtl.GCalfStart;

                if (gLegCtl.GCalfStart)
                {
                    bSendData = "calf lengh 1 100".ToString();
                    txtSend.Text = bSendData.ToString();

                    byteSendData = Encoding.ASCII.GetBytes(bSendData);
                    sPort.Write(byteSendData, 0, byteSendData.Length);

                    tBoxCalfCtl.Text = "move".ToString();
                }
                else
                {
                    bSendData = "calf lengh 0 100".ToString();
                    txtSend.Text = bSendData.ToString();

                    byteSendData = Encoding.ASCII.GetBytes(bSendData);
                    sPort.Write(byteSendData, 0, byteSendData.Length);

                    tBoxCalfCtl.Text = "stop".ToString();
                }
            }
            catch (Exception ex)
            {
                gLegCtl.GCalfStart = false;
                txtSend.Clear();
                MessageBox.Show("serial port를 연결해주세요");
            }
        }
Ejemplo n.º 5
0
        public Form1()          //Constructor
        {
            InitializeComponent();

            this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true); this.SetStyle(ControlStyles.SupportsTransparentBackColor, true); this.UpdateStyles();

            //splitContainer1.FixedPanel = FixedPanel.Panel1;
            //splitContainer2.FixedPanel = FixedPanel.Panel2;

            //outputList_Initialize();

            ComSetting.Read();
            TopMost = ComSetting.Option.StayOnTop;

            // let form use multiple fonts
            origFont = Font;
            FontFamily SerialFont = new FontFamily("Courier New");
            monoFont = new Font(SerialFont, 10, FontStyle.Regular);
            Font = ComSetting.Option.MonoFont ? monoFont : origFont;

            ComPort com = ComPort.Instance;
            com.StatusChanged += OnStatusChanged;
            com.DataReceived += OnDataReceived;
        }
Ejemplo n.º 6
0
            private void button33_Click(object sender, EventArgs e)
            {
                // HEXA 로 보낼때 필요한 변수
                byte[] byteSendData = new byte[200];
                int iSendCount = 0;  // 헥사로 보낼때의 데이터 수

                ComPort com = ComPort.Instance;

                byteSendData[0] = 0xa2;

                try
                {
                    if (true == checkBox1.Checked) // 헥사로 보낸다면
                    {
                        /*
                        foreach (string s in txtSend.Text.Split(' '))
                        {
                            if (null != s && "" != s)
                                byteSendData[iSendCount++] = Convert.ToByte(s, 16);
                        }
                        */
                        com.Send(byteSendData, 0, iSendCount);
                       // m_sp1.Write(byteSendData, 0, iSendCount);
                    }
                    else
                    {
                        // string을 그대로 보내기
                        com.Send(txtSend.Text);
                        //m_sp1.Write(txtSend.Text);
                    }
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show(ex.Message, "SEND 데이터 오류");
                }
            }
Ejemplo n.º 7
0
        private void Form1_Load(object sender, EventArgs e)
        {
            this.TopMost = false;
            this.AutoSize = false;
            this.AutoSizeMode = AutoSizeMode.GrowOnly;
            this.AutoScaleMode = AutoScaleMode.Inherit;

            this.richTextBox1.Anchor = AnchorStyles.Bottom|AnchorStyles.Left|AnchorStyles.Top|AnchorStyles.Right;
            this.richTextBox1.ReadOnly = true;
            this.richTextBox1.BorderStyle = BorderStyle.FixedSingle;

            this.txtSend.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
            this.txtSend.Multiline = false;
            this.txtSend.ReadOnly = false;

            this.pictureBox1.Anchor = AnchorStyles.Bottom | AnchorStyles.Right | AnchorStyles.Top;

            this.button1.Click += new System.EventHandler(this.Button_Click);
            this.button2.Click += new System.EventHandler(this.Button_Click);
            this.button3.Click += new System.EventHandler(this.Button_Click);
            this.button4.Click += new System.EventHandler(this.Button_Click);
            this.button5.Click += new System.EventHandler(this.Button_Click);

            this.button6.Click += new System.EventHandler(this.Button_Click);
            this.button7.Click += new System.EventHandler(this.Button_Click);
            this.button8.Click += new System.EventHandler(this.Button_Click);
            this.button9.Click += new System.EventHandler(this.Button_Click);
            this.button10.Click += new System.EventHandler(this.Button_Click);

            this.button11.Click += new System.EventHandler(this.Button_Click);
            this.button12.Click += new System.EventHandler(this.Button_Click);
            this.button13.Click += new System.EventHandler(this.Button_Click);
            this.button14.Click += new System.EventHandler(this.Button_Click);
            this.button15.Click += new System.EventHandler(this.Button_Click);

            this.button16.Click += new System.EventHandler(this.Button_Click);
            this.button17.Click += new System.EventHandler(this.Button_Click);
            this.button18.Click += new System.EventHandler(this.Button_Click);
            this.button19.Click += new System.EventHandler(this.Button_Click);
            this.button20.Click += new System.EventHandler(this.Button_Click);

            this.button21.Click += new System.EventHandler(this.Button_Click);
            this.button22.Click += new System.EventHandler(this.Button_Click);
            this.button23.Click += new System.EventHandler(this.Button_Click);
            this.button24.Click += new System.EventHandler(this.Button_Click);
            this.button25.Click += new System.EventHandler(this.Button_Click);

            this.button26.Click += new System.EventHandler(this.Button_Click);
            this.button27.Click += new System.EventHandler(this.Button_Click);
            this.button28.Click += new System.EventHandler(this.Button_Click);
            this.button29.Click += new System.EventHandler(this.Button_Click);
            this.button30.Click += new System.EventHandler(this.Button_Click);

            this.button31.Click += new System.EventHandler(this.Button_Click);
            this.button32.Click += new System.EventHandler(this.Button_Click);

            this.button1.Size = new Size(btSizeWidth, btSizeHeight);
            this.button2.Size = new Size(btSizeWidth, btSizeHeight);
            this.button3.Size = new Size(btSizeWidth, btSizeHeight);
            this.button4.Size = new Size(btSizeWidth, btSizeHeight);
            this.button5.Size = new Size(btSizeWidth, btSizeHeight);

            this.button6.Size = new Size(btSizeWidth, btSizeHeight);
            this.button7.Size = new Size(btSizeWidth, btSizeHeight);
            this.button8.Size = new Size(btSizeWidth, btSizeHeight);
            this.button9.Size = new Size(btSizeWidth, btSizeHeight);
            this.button10.Size = new Size(btSizeWidth, btSizeHeight);

            this.button11.Size = new Size(btSizeWidth, btSizeHeight);
            this.button12.Size = new Size(btSizeWidth, btSizeHeight);
            this.button13.Size = new Size(btSizeWidth, btSizeHeight);
            this.button14.Size = new Size(btSizeWidth, btSizeHeight);
            this.button15.Size = new Size(btSizeWidth, btSizeHeight);

            this.button16.Size = new Size(btSizeWidth, btSizeHeight);
            this.button17.Size = new Size(btSizeWidth, btSizeHeight);
            this.button18.Size = new Size(btSizeWidth, btSizeHeight);
            this.button19.Size = new Size(btSizeWidth, btSizeHeight);
            this.button20.Size = new Size(btSizeWidth, btSizeHeight);

            this.button21.Size = new Size(btSizeWidth, btSizeHeight);
            this.button22.Size = new Size(btSizeWidth, btSizeHeight);
            this.button23.Size = new Size(btSizeWidth, btSizeHeight);
            this.button24.Size = new Size(btSizeWidth, btSizeHeight);
            this.button25.Size = new Size(btSizeWidth, btSizeHeight);

            this.button26.Size = new Size(btSizeWidth, btSizeHeight);
            this.button27.Size = new Size(btSizeWidth, btSizeHeight);
            this.button28.Size = new Size(btSizeWidth, btSizeHeight);
            this.button29.Size = new Size(btSizeWidth, btSizeHeight);
            this.button30.Size = new Size(btSizeWidth, btSizeHeight);

            this.button31.Size = new Size(btSizeWidth, btSizeHeight);
            this.button32.Size = new Size(btSizeWidth, btSizeHeight);

            this.button1.Location = new Point(btFirstX, btLocHeight);
            this.button2.Location = new Point(btFirstX + btInverval, btLocHeight);
            this.button3.Location = new Point(btFirstX + btInverval * 2, btLocHeight);
            this.button4.Location = new Point(btFirstX + btInverval * 3, btLocHeight);
            this.button5.Location = new Point(btFirstX + btInverval * 4, btLocHeight);
            this.button6.Location = new Point(btFirstX + btInverval * 5, btLocHeight);
            this.button7.Location = new Point(btFirstX + btInverval * 6, btLocHeight);
            this.button8.Location = new Point(btFirstX + btInverval * 7, btLocHeight);
            this.button9.Location = new Point(btFirstX + btInverval * 8, btLocHeight);
            this.button10.Location = new Point(btFirstX + btInverval * 9, btLocHeight);

            this.button11.Location = new Point(btFirstX + btInverval * 10, btLocHeight);
            this.button12.Location = new Point(btFirstX + btInverval * 11, btLocHeight);
            this.button13.Location = new Point(btFirstX + btInverval * 12, btLocHeight);
            this.button14.Location = new Point(btFirstX + btInverval * 13, btLocHeight);
            this.button15.Location = new Point(btFirstX + btInverval * 14, btLocHeight);
            this.button16.Location = new Point(btFirstX + btInverval * 15, btLocHeight);
            this.button17.Location = new Point(btFirstX + btInverval * 16, btLocHeight);
            this.button18.Location = new Point(btFirstX + btInverval * 17, btLocHeight);
            this.button19.Location = new Point(btFirstX + btInverval * 18, btLocHeight);
            this.button20.Location = new Point(btFirstX + btInverval * 19, btLocHeight);

            this.button21.Location = new Point(btFirstX + btInverval * 20, btLocHeight);
            this.button22.Location = new Point(btFirstX + btInverval * 21, btLocHeight);
            this.button23.Location = new Point(btFirstX + btInverval * 22, btLocHeight);
            this.button24.Location = new Point(btFirstX + btInverval * 23, btLocHeight);
            this.button25.Location = new Point(btFirstX + btInverval * 24, btLocHeight);
            this.button26.Location = new Point(btFirstX + btInverval * 25, btLocHeight);
            this.button27.Location = new Point(btFirstX + btInverval * 26, btLocHeight);
            this.button28.Location = new Point(btFirstX + btInverval * 27, btLocHeight);
            this.button29.Location = new Point(btFirstX + btInverval * 28, btLocHeight);
            this.button30.Location = new Point(btFirstX + btInverval * 29, btLocHeight);

            this.button31.Location = new Point(btFirstX + btInverval * 30, btLocHeight);
            this.button32.Location = new Point(btFirstX - btInverval , btLocHeight);

            this.button1.Text = "1";
            this.button2.Text = "2";
            this.button3.Text = "3";
            this.button4.Text = "4";
            this.button5.Text = "5";
            this.button6.Text = "6";
            this.button7.Text = "7";
            this.button8.Text = "8";
            this.button9.Text = "9";
            this.button10.Text = "0";

            this.button11.Text = "1";
            this.button12.Text = "2";
            this.button13.Text = "3";
            this.button14.Text = "4";
            this.button15.Text = "5";
            this.button16.Text = "6";
            this.button17.Text = "7";
            this.button18.Text = "8";
            this.button19.Text = "9";
            this.button20.Text = "0";

            this.button21.Text = "1";
            this.button22.Text = "2";
            this.button23.Text = "3";
            this.button24.Text = "4";
            this.button25.Text = "5";
            this.button26.Text = "6";
            this.button27.Text = "7";
            this.button28.Text = "8";
            this.button29.Text = "9";
            this.button30.Text = "0";

            this.button31.Text = "1";

            this.button32.Text = "L";

            this.button1.Font = new Font("굴림", 7F);
            this.button2.Font = new Font("굴림", 7F);
            this.button3.Font = new Font("굴림", 7F);
            this.button4.Font = new Font("굴림", 7F);
            this.button5.Font = new Font("굴림", 7F);

            this.button6.Font = new Font("굴림", 7F);
            this.button7.Font = new Font("굴림", 7F);
            this.button8.Font = new Font("굴림", 7F);
            this.button9.Font = new Font("굴림", 7F);
            this.button10.Font = new Font("굴림", 7F);

            this.button11.Font = new Font("굴림", 7F);
            this.button12.Font = new Font("굴림", 7F);
            this.button13.Font = new Font("굴림", 7F);
            this.button14.Font = new Font("굴림", 7F);
            this.button15.Font = new Font("굴림", 7F);

            this.button16.Font = new Font("굴림", 7F);
            this.button17.Font = new Font("굴림", 7F);
            this.button18.Font = new Font("굴림", 7F);
            this.button19.Font = new Font("굴림", 7F);
            this.button20.Font = new Font("굴림", 7F);

            this.button21.Font = new Font("굴림", 7F);
            this.button22.Font = new Font("굴림", 7F);
            this.button23.Font = new Font("굴림", 7F);
            this.button24.Font = new Font("굴림", 7F);
            this.button25.Font = new Font("굴림", 7F);

            this.button26.Font = new Font("굴림", 7F);
            this.button27.Font = new Font("굴림", 7F);
            this.button28.Font = new Font("굴림", 7F);
            this.button29.Font = new Font("굴림", 7F);
            this.button30.Font = new Font("굴림", 7F);

            this.button31.Font = new Font("굴림", 7F);
            this.button32.Font = new Font("굴림", 7F);
#if false
            this.checkBox1.Checked = true;
            this.checkBox2.Checked = true;
            this.checkBox3.Checked = true;

            this.checkBox1.CheckState = CheckState.Checked;
            this.checkBox2.CheckState = CheckState.Checked;
            this.checkBox3.CheckState = CheckState.Checked;
#endif
            btnOpen.Text = "connect".ToString();

            ComPort com = ComPort.Instance;

            Int32[] BaudRate = { 110, 300, 600, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600, 0};

            //add port to ComboPortList
            int found = 0;

            string[] portList = com.GetAvailablePorts();

            for (int i = 0; i < portList.Length; i++)
            {
                string name = portList[i];
       
                ComboPortList.Items.Add(name);
                if (name == ComSetting.Port.PortName)
                    found = i;
            }

            if (portList.Length > 0)
            {
                ComboPortList.SelectedIndex = found;
            }

            //add baudrate to CobboBr
            found = 0;

            for (int i = 0; BaudRate[i] != 0; i++)
            {
                ComboBr.Items.Add(BaudRate[i].ToString());

                if (BaudRate[i] == ComSetting.Port.BaudRate)
                {
                    found = i;
                }
            }
            ComboBr.SelectedIndex = found;

            //Add DataBIt to Combobox
            ComboDb.Items.Add("5");
            ComboDb.Items.Add("6");
            ComboDb.Items.Add("7");
            ComboDb.Items.Add("8");
            ComboDb.SelectedIndex = ComSetting.Port.DataBits - 5;

            //add Parity to Combobox
            foreach (string s in Enum.GetNames(typeof(Parity)))
            {
                ComboParity.Items.Add(s);
            }
            ComboParity.SelectedIndex = (int)ComSetting.Port.Parity;

            //add StopBIts to combobox
            foreach (string s in Enum.GetNames(typeof(StopBits)))
            {
                ComboSb.Items.Add(s);
            }
            ComboSb.SelectedIndex = (int)ComSetting.Port.StopBits;

            foreach (string s in Enum.GetNames(typeof(Handshake)))
            {
                ComboFlow.Items.Add(s);
            }
            ComboFlow.SelectedIndex = (int)ComSetting.Port.Handshake;

            switch (ComSetting.Option.AppendToSend)
            {
                case ComSetting.Option.AppendType.AppendNothing:
                    radioButton1.Checked = true;
                    break;
                case ComSetting.Option.AppendType.AppendCR:
                    radioButton2.Checked = true;
                    break;
                case ComSetting.Option.AppendType.AppendLF:
                    radioButton3.Checked = true;
                    break;
                case ComSetting.Option.AppendType.AppendCRLF:
                    radioButton4.Checked = true;
                    break;
            }
            checkBox1.Checked = ComSetting.Option.HexOutput;
            checkBox2.Checked = ComSetting.Option.MonoFont;
            checkBox3.Checked = ComSetting.Option.LocalEcho;
            checkBox4.Checked = ComSetting.Option.StayOnTop;
            checkBox5.Checked = ComSetting.Option.FilterUseCase;
        }