포트개방하는 부분에 대해서 질문드립니다.
독특한
import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.comm.*;
import javax.swing.*;
public class SimpleRead extends Frame implements Runnable, SerialPortEventListener, ActionListener{
int cnt = 0;
static CommPortIdentifier portId;
static Enumeration portList;
InputStream inputStream;
SerialPort serialPort;
static Thread readThread;
boolean threadFlg = true;// 스레드 루프내 제어 프레그
boolean suspendFlg = false;// 스레드 일시정지 및 재개를 Control
public static JFrame frame = new JFrame(Port);
static TextArea ta = new TextArea(28,105);
static JButton start = new JButton(START);
static JButton stop = new JButton(STOP);
public static void main(String[] args)
{
//frame.setPreferredSize(new Dimension(1200,900));
frame.setSize(755, 520);
Container contentPane = frame.getContentPane();
contentPane.setLayout(new FlowLayout());
contentPane.setBackground(Color.DARK_GRAY);
contentPane.add(ta);
contentPane.add(start,BorderLayout.SOUTH);
contentPane.add(stop,BorderLayout.SOUTH);
frame.setResizable(false); //확대,축소 금지
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//frame.pack();
frame.setVisible(true);
portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements())
{
portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL)
{
if (portId.getName().equals(COM2))
{
SimpleRead reader = new SimpleRead();
}
}
}
} //메인 종료
public void init()
{
start.addActionListener(this);
stop.addActionListener(this);
this.add(start);
this.add(stop);
}
public void start()
{
readThread = new Thread(this);
readThread.start();
}
public void stop()
{
threadFlg = false;
}
public synchronized void actionPerformed(ActionEvent e)
{
if(e.getSource() == start)// 재개(일시정지 해제)
{
suspendFlg = false;
notify();
}
else if(e.getSource() == stop)
threadFlg = false;// 완전 정지
}
// SimpleRead 생성자
public SimpleRead()
{
try
{
serialPort = (SerialPort) portId.open(SimpleReadApp, 2000);
} catch (PortInUseException e) {}
try {
inputStream = serialPort.getInputStream();
} catch (IOException e) {}
try
{
serialPort.addEventListener(this);
} catch (TooManyListenersException e) {}
serialPort.notifyOnDataAvailable(true);
try
{
serialPort.setSerialPortParams(57600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
&nbs
} catch (UnsupportedCommOperationException e) {}
}
public void run()
{
try
{
Thread.sleep(20000);
}
catch (InterruptedException e) {}
}
public void serialEvent(SerialPortEvent event)
{
switch(event.getEventType())
{
case SerialPortEvent.BI:
case SerialPortEvent.OE:
case SerialPortEvent.FE:
case SerialPortEvent.PE:
case SerialPortEvent.CD:
case SerialPortEvent.CTS:
case SerialPortEvent.DSR:
case SerialPortEvent.RI:
case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
break;
case SerialPortEvent.DATA_AVAILABLE:
byte[] readBuffer = new byte[1];
try{
while (inputStream.available() 0 ) {
int numBytes = inputStream.read(readBuffer);
printByte(System.out, readBuffer[0]);
cnt++;
if(cnt == 42)
{
ta.append(\n);
cnt = 0;
}
}
} catch (IOException e) {}
break;
}
}
public static void printByte(PrintStream p, int b)
{
String bs = Integer.toHexString(b & 0xff).toUpperCase();
if (b =0 && b 16)
ta.append(0);
ta.append(bs + );
}
}
자바로 시리얼 통신을 하기위한 소스입니다.
start버튼이랑 stop버튼에 기능을 추가할려고하는데 ㅜㅜ
포트에서 값을 받는 부분이랑 포트를 개방해주는 부분이 도저히 어딘지 모르겠습니다 ㅜㅜ
어느부분인지 좀 가르쳐주세요 .....
-
뿌닝
portList = CommPortIdentifier.getPortIdentifiers();
while(portList.hasMoreElements()){
portID = (CommPortIdentifier)portList.nextElement();
System.out.print(\Port Name : \ + portID.getName() + \ -
인1형녀
1.public void serialEvent(SerialPortEvent event) 2.serialPort = (SerialPort) portId.open(\SimpleReadApp\
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2654653 | 개발툴 콘솔창에 아무것도 나오지 않는데 해결좀....해주세요... (3) | 쌍둥이자리 | 2024-05-12 |
2654625 | textare 중간부터 글이 나옵니다. | 영글 | 2024-05-12 |
2654595 | C언어랑 C++ 두개만배워놓으면 (3) | 아빠몬 | 2024-05-12 |
2654543 | 드라이브 체크 어떻게 해야할까요 | 아연 | 2024-05-11 |
2654483 | 익스플로어 6과 7의 버젼에 따라서 클릭이 되지 않을 수 있나요? (1) | 히메 | 2024-05-11 |
2654431 | Invalid procedure call or argument 는 무슨뜻이죠 ;? | 날샘 | 2024-05-10 |
2654372 | 이중연결리스트 정렬 문의 드립니다. (1) | 야미 | 2024-05-10 |
2654343 | 레이어 팝업.. 흑흑 (4) | 다인 | 2024-05-10 |
2654284 | 반응형 웹에서 | HotPink | 2024-05-09 |
2654234 | 타이틀옆에 카테고리 정렬질문이요 (2) | 밤 | 2024-05-09 |
2654207 | 퍼블리셔포트폴리오질문이요! ! (2) | 훌림목 | 2024-05-08 |
2654175 | 방문자 수,포스트마다 사람들이 클릭 한 수 알 수 있는 방법 없나요? | 찬늘 | 2024-05-08 |
2654145 | 숙제란! | 피리 | 2024-05-08 |
2654120 | 레이어팝업 이용시 body 스크롤 고정(?) 질문입니다. (2) | 꿈빛 | 2024-05-08 |
2654094 | 메인메뉴와 윈쪽사이드메뉴 테마? | 솔찬 | 2024-05-07 |
2654064 | mp3 plyer에서 이퀄라이져를 구현하고 싶습니다. (7) | 촉촉한 초코칩 | 2024-05-07 |
2654034 | 초보자라 조언좀얻고자합니다 씨언어 문제입니다 (4) | 모이 | 2024-05-07 |
2654006 | 아주 극초보 배열문젠데요...오류를 어케 처리하죠..;;; (2) | 눈꽃 | 2024-05-07 |
2653980 | 이미지 슬라이드 안에 삽입한 텍스트 애니메이션 제어방법? | 다흰 | 2024-05-06 |
2653950 | 키보드 누르기.. | 의사양반 | 2024-05-06 |