Page 423 - MDP2020-3
P. 423

················································································  명장양성프로젝트  【MDP】  과제발표회  자료집  Ⅲ    |  417


            - SerialReader.java  :  시리얼  포트를  통해  들어오는  데이터  입력
            import  java.io.IOException;

            import  java.io.InputStream;


            public  class  SerialReader  implements  Runnable  {
                    InputStream  in;



                    public  SerialReader(InputStream  in)  {
                            this.in  =  in;
                    }


                    public  void  run()  {

                            byte[]  buffer  =  new  byte[1024];
                            int  len  =  -1;
                            try  {
                                    while  ((len  =  this.in.read(buffer))  >  -1)  {
                                            System.out.print(new  String(buffer,  0,  len));

                                    }
                            }  catch  (IOException  e)  {
                                    e.printStackTrace();
                            }
                    }

            }
   418   419   420   421   422   423   424   425   426   427   428