예제 #1
0
        /// <summary>
        /// 시리얼 포트 초기화
        /// </summary>
        public void resetPorts()
        {
            String[] portNames = CommRS485.GetPortNames();

            foreach (String portname in portNames)
            {
                ports.Add(new Port {
                    PortNumber = Int32.Parse(portname.Replace("COM", "")), PortName = portname
                });
            }

            cbComPort.ItemsSource       = ports;
            cbComPort.DisplayMemberPath = "PortName";

            if (cbComPort.Items.Count > 0)
            {
                cbComPort.SelectedIndex = 0;
            }

            cbComPort2.ItemsSource       = ports;
            cbComPort2.DisplayMemberPath = "PortName";

            if (cbComPort2.Items.Count > 0)
            {
                cbComPort2.SelectedIndex = 0;
            }
        }
예제 #2
0
        /// <summary>
        /// D-Out 버튼 클릭 이벤트 처리 메소드
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDoutOpen_Click(object sender, RoutedEventArgs e)
        {
            if (DOutComm != null && DOutComm.isOpen())
            {
                if (DOutComm != null)
                {
                    DOutComm.Close();
                    DOutComm = null;
                }
                btnDoutOpen.Content = "Open";
            }
            else
            {
                Port dOutport = cbComPort2.SelectedItem as Port;
                DOutComm = new CommRS485(dOutport.PortName, OnOutDataReceived, 115200);

                if (DOutComm.Open())
                {
                    btnDoutOpen.Content = "Close";
                }
                else
                {
                    if (DOutComm != null)
                    {
                        DOutComm.Close();
                        DOutComm            = null;
                        btnDoutOpen.Content = "Open";
                    }
                    MessageBox.Show("ERROR 2 : D-Out 통신연결 실패. 포트를 확인하세요.");
                }
            }
        }
예제 #3
0
        /// <summary>
        /// 종료 버튼 클릭 이벤트 처리 메소드
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void btnStop_Click(object sender, RoutedEventArgs e)
        {
            if (comm != null)
            {
                comm.Close();
                comm = null;
            }
        }
예제 #4
0
        private void btnDinOpen_Click(object sender, RoutedEventArgs e)
        {
            if (comm != null && comm.isOpen())
            {
                if (comm != null)
                {
                    comm.Close();
                    comm = null;
                }

                btnDinOpen.Content = "Open";
            }
            else
            {
                Port dInport = cbComPort.SelectedItem as Port;
                comm = new CommRS485(dInport.PortName, OnDataReceived);

                if (comm.Open())
                {
                    //통신이 연결되면 명령어 전송 스레드를 시작한다.
                    Thread sendCmdThread = new Thread(new ThreadStart(SendCommandLoop));
                    sendCmdThread.Start();

                    btnDinOpen.Content = "Close";
                }
                else
                {
                    if (comm != null)
                    {
                        comm.Close();
                        comm = null;
                    }
                    btnDinOpen.Content = "Open";

                    MessageBox.Show("ERROR 1 : D-In 통신연결 실패. 포트를 확인하세요.");
                }
            }
        }
예제 #5
0
        /// <summary>
        /// 시작 버튼 클릭 이벤트 처리 메소드
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnStart_Click(object sender, RoutedEventArgs e)
        {
            Port port = cbComPort.SelectedItem as Port;

            comm = new CommRS485(port.PortName, OnDataReceived);

            if (comm.Open())
            {
                //통신이 연결되면 명령어 전송 스레드를 시작한다.
                Thread sendCmdThread = new Thread(new ThreadStart(SendCommandLoop));
                sendCmdThread.Start();
            }
            else
            {
                if (comm != null)
                {
                    comm.Close();
                    comm = null;
                }

                MessageBox.Show("ERROR 1 - 통신연결 실패");
            }
        }