RX,TX - 시리얼(Serial)
자바 프로그램 작성을 통해서, 시리얼 통신을 다뤄보고자 합니다.
1. 개발 언어
개발언어 | |
자바(JAVA) |
* 라이브러리(RXTX 프로젝트)
2. 시리얼 프로그램 - 자바로 작성하기(입문)
1. Eclipse에서 프로젝트 속성 설정하기 |
2. RXTXcomm.jar을 "Add Jars"를 클릭하여 추가합니다. |
package Program; import Libraries.Serial; public class Init { public static void main(String[] args) { |
Init.java |
package Libraries; import gnu.io.CommPort; import java.io.IOException; public class Serial } /** */ |
Serial.java |
동작 - 영상 |
|
(고급) 3. RX-TX GUI 프로그램 작성하기
|
/* package Main; import java.awt.BorderLayout; import javax.swing.JFrame; import Libraries.CommBaudRate; import javax.swing.JLabel; import javax.swing.JMenuBar; public class GUI extends JFrame implements ChangeListener, ActionListener { //Communicator object //Variables } private void initComponents() { setTitle("RX-TX"); JScrollPane scrollPane = new JScrollPane(txtLog); } } } } @Override
|
GUI.java |
package Libraries; import javax.swing.JComboBox; public class CommBaudRate{
|
CommBaudRate.java |
/* package Libraries; import gnu.io.*; import java.awt.Color; import Main.GUI; public class Communicator implements SerialPortEventListener //for containing the ports that will be found //map the port names to CommPortIdentifiers //this is the object that contains the opened port //input and output streams for sending and receiving data //just a boolean flag that i use for enabling //private int sensCounter = 0; private boolean bConnected = false; //the timeout value for connecting with the port //some ascii values for for certain things
public Communicator(GUI window) //search for all the serial ports while (ports.hasMoreElements()) //get only serial ports //connect to the selected port in the combo box CommPort commPort = null; try //for controlling GUI elements //logging window.txtLog.append( baudRate + "Rate" + "\n" ); //enables the controls on the GUI if a successful connection is made window.keybindingController.toggleControls(); window.txtLog.setForeground(Color.RED); //open the input and output streams try { input = serialPort.getInputStream(); successful = true; //starts the event listener that knows whenever data is available to be read //disconnect the serial port serialPort.removeEventListener(); logText = "Disconnected."; final public boolean getConnected() public void setConnected(boolean bConnected) //what happens when data is received try //method that can be called to send data public void updateRGB(byte rValue, byte gValue, byte bValue) { public void updateFrame(byte[] rgbMap) { } |
Communicator.java |
/* package Libraries; import Main.GUI;
public class KeybindingController { public KeybindingController(GUI window) {
/* } |
| KeybindingController.java |
소스 파일
4. 참고 자료
1. Serial Communication in Java with Example Program,
https://blog.henrypoon.com/blog/2011/01/01/serial-communication-in-java-with-example-program/
2. TIAL/GUI.java at master · nilsberglund/TIAL,
https://github.com/nilsberglund/TIAL/tree/master/Java-App/src/tialControlPanel
3. Serial port - Wikipedia
https://en.wikipedia.org/wiki/Serial_port
시리얼 포트에 대한 소개 및 Baud Rate(보오 레이트) 값 등을 자세히 소개하고 있습니다.
'공부 > 자바(JAVA)' 카테고리의 다른 글
| 자바(Swing) - 달력 구현하기 (0) | 2017.10.28 |
|---|---|
| 자바 Swing(스윙) 차트 - JfreeChart (0) | 2017.10.24 |
| Jasper Reports - 보고서 구현하기 (0) | 2017.10.24 |
| 바둑, 오목 보드(Baduk, Omok Board) - GUI (0) | 2017.10.22 |
| DB연동 프로젝트(Java Swing) (0) | 2017.10.15 |