最近のコースでは、上部コンピューター向けのシリアルコミュニケーションツールを作成する必要があります。 Javaに基づいたグラフィカルインターフェイスを使用して、シンプルなシリアルコミュニケーションツールを書きました。プロセスについては、参照のために以下で詳しく説明します^_^
1つ:
まず、Javaシリアルポート通信操作をサポートする追加のJARパッケージをダウンロードする必要があります。 Java.Commは比較的古く、64ビットシステムをサポートしていないため、RXTX JARパッケージ(両方とも32ビット/64ビットサポート)をお勧めします。
公式ダウンロードアドレス:http://fizzed.com/oss/rxtx-for-java(注:FQはダウンロードする必要がある場合があります)
FQにならない子供用の靴はここからダウンロードできます:
http://xiazai.vevb.com/201612/yuanma/javamfzrxtx(vevb.com).rar(32-bit)
http://xiazai.vevb.com/201612/yuanma/javamfzrxtx(vevb.com).rar(64-bit)
二:
解凍されたJARパッケージをダウンロードして、Javaビルドパスの下に紹介します。
捕獲
注: java.lang.unsatisfiedlinkerrorエラーが操作中にスローされている場合は、rxtx parallel.dllとrxtxserial.dllの2つのファイルをrxtx減圧パッケージにコピーして、エラーを解決してc:/windows/system32ディレクトリにコピーしてください。
三つ:
このJARパッケージの使用に関して、SerialTool.javaクラスを書きました。これは、シリアルポート通信のためのさまざまなシンプルなサービスを提供します。コードは次のとおりです(このクラスはシリアルポートパッケージにあることに注意してください):
パッケージserialport; import java.io.ioexception; import java.io.inputStream; Import java.OutputStream; Import Java.util.ArrayList; Import Java.util.Enumeration; Import java.util.tumanylistensexectice; gnu.io.nosuchportexception; import gnu.io.portinuseexception; Import gnu.io.serialport; Import gnu.io.serialportedCommoperationException; Import gnu.io.unsuptedCommoperationException;シングルトン設計モード) * @author zhong * */public class serialtool {private static serialtool serialtool = null; static {//このクラスがclassloaderによってロードされたときにserialtoolオブジェクトを初期化if(serialtool == null){serialTool = new SerialTool(); }} //プライベートSerialToolクラスのコンストラクターは、SerialToolオブジェクトを生成することが許可されていませんプライベートSerialTool(){} /*** Service* @return SerialTool* /public Static SerialTool GetSerialTool(){if(serialtool == null){serialtool = serialTool(); } serialToolを返します。 } /***利用可能なすべてのポートを見つける* @return利用可能なポート名のリスト* /public static final arraylist <string> findport(){//現在利用可能なすべてのシリアルポート列挙<comportidentidifier> portlist = commportidentifier.getportidentifiers(); ArrayList <String> portnameList = new ArrayList <>(); //使用可能なシリアルポート名をリストしてリストをリストし、[portlist.hasMoreElements()){string portname = portlist.nextelement()。getName(); portnameList.add(portname); } portnameListを返します。 } /***オープンシリアルポート* @paramポート名ポート名* @param baudrate baudrate* @return serialport object* @throws serialpormetarfailureは、シリアルポートパラメーターの設定に失敗しました* @throws notaserialport notaserialport notaserialport notaserialportは、デバイスのポートタイプではありません。占有*/public static final serialport openport(string portname、int baudrate)Slows serialportparameterfailure、notaserialport、nosuchport、portinuse {//ポート名commportidifier portidentifier = commportidentidifier.getportifier(portname); //ポートを開き、ポート名とタイムアウト(オープニングオペレーションのタイムアウト時間)Commport commport = portidentidifier.open(Portname、2000); //それがシリアルポートであるかどうかを防御する(commport instance of serialport){serialport serialport =(serialport)commport; try {//シリアルポートSerialport.setSerialPortparams(baudrate、serialport.databits_8、serialport.stopbits_1、serialport.parity_none)のボーレートおよびその他のパラメーターを設定します。 } catch(unsupportedcommoperationexception e){新しいserialpormparameterfailure(); } //system.out.println("open " + portname +" susessully! "); Serialportを返します。 } else {//シリアルポートではない新しいnotaserialport(); }} catch(nosuchportexception e1){throw new nosuchport(); } catch(portinuseexception e2){new portinuse(); }} / ***シリアルポートを閉じる* @paramシリアルポートシリアルポートオブジェクトを閉じますserialport = null; }} / ***シリアルポートにデータを送信* @paramシリアルポートシリアルポートオブジェクト* @param注文データが送信されます* @throws senddatoserialportfailureはシリアルポートにデータを送信できませんでした* @throws serialputstreamclosefailure senddatoserialportfailure、serialportputstreamclosefailure {outputstream out = null; try {out = serialport.getOutputStream(); out.write(注文); out.flush(); } catch(ioException e){新しいsenddatoserialportfailure(); }最後に{try {if(out!= null){out.close(); out = null; }} catch(ioException e){new serialportOutputStremCloseFailure(); }}} / ***シリアルポートからのデータの読み取り* @param serialport接続のシリアルポートオブジェクトが確立されました* @returnデータread* @throws readdatafromserialportfailureシリアルポートの読み取り中にエラーが発生しました。 ReadDataFromserialPortfailure、serialPortinputStreamCloseFailure {inputstream in = null; byte [] bytes = null; try {in = serialport.getInputStream(); int bufflenth = in.abailable(); //バッファでデータ長を取得しますwhile(bufflenth!= 0){bytes = new byte [bufflenth]; // buffer in.read(bytes)のデータの長さにバイト配列を初期化します。 Bufflenth = in.abailable(); }} catch(ioException e){新しいReadDataFromserialPortFailure(); }最後に{try {if(in!= null){in.close(); in = null; }} catch(ioException e){new serialPortinputStremCloseFailure(); }}バイトを返します。 } /***リスナーの追加* @paramポートシリアルポートオブジェクト* @paramリスナーシリアルポートリスナー* @throws toomanylistenersリスニングクラスオブジェクトが多すぎます* /public static void addlistener(シリアルポート、シリアルポートリステナーリスナー)Toomanylistenersをスロー//データが到着したときにリスニング受信スレッドを覚ますように設定します。 //通信が中断されたときに割り込みスレッドを覚ますように設定しますport.notifyOnbreakinterrupt(true); } catch(toomanylistenersexception e){new toomanylisteners(); }}}注:この方法のスロー例外はすべて私のカスタム例外です。この理由は、メインプログラムで対応する処理を促進するためです。例外の1つの説明は次のとおりです。
(すべてのカスタム例外はSerialExceptionパッケージに配置されていることに注意してください)
パッケージSerialException; public class serialportparameterfailureは例外を拡張します{ / ** * * / private static final long serialversionuid = 1l; public serialpormparameterfailure(){} @override public string toString(){return "シリアルポートパラメーターの設定失敗!シリアルポート操作の開くことは完了していません!"; }}各カスタム例外クラスのtoString()メソッドを書き直しました。これにより、メインプログラムは、例外をキャッチした後に対応するエラーメッセージを印刷できます。
また、SerialExceptionパッケージには、受信した例外オブジェクトにエラー情報を抽出し、文字列に変換して返すクラスもあります。コードは次のとおりです。
パッケージserialexception; Import java.io.ioexception; import java.io.printwriter; Import java.io.stringwriter;/***渡された例外のエラーメッセージの抽出と変換を担当します。 * @author zhong * */public class exceptionwriter {/** *エラーメッセージを文字列に戻し、文字列に戻す * @param eがエラー例外を含む * @returnエラーメッセージ文字列 */public static string geterrorinfofromexception(例外e){stringwriter sw = null; printwriter pw = null; try {sw = new StringWriter(); pw = new Printwriter(SW); E.PrintStackTrace(PW); return "/r/n" + sw.toString() + "/r/n"; } catch(Exception E2){return "エラーメッセージは取得されませんでした。チェックして再試行してください!」; }最後に{try {if(pw!= null){pw.close(); } if(sw!= null){sw.close(); }} catch(ioexception e1){e1.printstacktrace(); }}}}4:
メインプログラムクラスの使用、Client.javaには、プログラムのエントリアドレス(メインメソッド)が含まれています。その機能は、ウェルカムインターフェイスを表示し、実際のシリアルポートデータ表示のdataview.javaクラスを呼び出すことです。
client.javaコードは次のとおりです。
パッケージSerialPort; Import Java.awt.Color; Import java.awt.Flowlayout; Import java.awt.font; Import java.awt.graphics; Import java.awt.gridlayout; import java.awt.image; Import java.awt.awt.wat.awt.wat.awt.wat. java.awt.toolkit; Import java.awt.event.keyadapter; Import java.awt.event.keyevent; Import java.awt.event.event.windowadapter; Import java.awt.event.windowevent; import javax.swing.joptionceptionpane; Import serialexceptionpane; * */パブリッククラスクライアントはframe {/** * */private static final long serialversionuid = 1lを拡張します。 / ***プログラムインターフェイス幅*/ public static final int width = 800; / ***プログラムインターフェイスの高さ*/ public static final int height = 620; / ** *プログラムインターフェイスの位置(水平座標) */ public static final int loc_x = 200; / ** *プログラムインターフェイスの位置(水平座標) */ public static final int loc_y = 70;色の色=色。ホワイト;画像offscreen = null; //ダブルバッファリングに使用//ウィンドウのアイコンを設定します(ここでは、ウィンドウウィンドウのアイコンアイコンをカスタマイズしました。画像アイコン= toolkit.getImage(client.class.getResource( "Computer.png")); //他のクラスを保持しますdataview dataview = new dataview(this); //メインインターフェイスクラス(監視データメインパネルの表示)/***メインメソッド* @param args //*/public static void main(string [] args){new Client()。launchframe(); } / ***メインインターフェイスを表示* / public void launchframe(){this.setBounds(loc_x、loc_y、width、height); //プログラムがデスクトップに表示される場所を設定します。 //プログラムタイトルthis.seticOnimage(アイコン)を設定します。 this.setbackground(color.white); //背景色を設定しますthis.addwindowlistener(new windowadapter(){// windows window status public void closing(windowevent arg0){//system.exit(0); //プログラムを終了}}); this.addkeylistener(new keymonitor()); //キーボードリスナーを追加します。 //ウィンドウサイズを変更できません。SetVisible(true); //表示ウィンドウnewスレッド(new Repaintthread())。start(); // Repaint Thread}/***プログラムインターフェイスのさまざまなコンポーネント要素を描画*/public void paint(グラフィックスG){color c = g.getColor(); G.SetFont(new Font( "Microsoft Yahei"、font.bold、40)); g.setcolor(color.black); G.DrawString(「アッパーコンピューターのリアルタイム監視システムを使用することを歓迎」、45、190); G.SetFont(new Font( "Microsoft Yahei"、font.italic、26)); g.setcolor(color.black); G.DrawString( "バージョン:1.0搭載:Zhonglei"、280、260); G.SetFont(new Font( "Microsoft Yahei"、font.bold、30)); G.SetColor(色); g.drawString("―--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- = Color. / ***インターフェイスの各要素コンポーネント(グラフィックスG){(offscreen == null)this.createimage(width、height); goffscolor(color.white)fillRect;元のキャンバス} /**内側のクラスは、キーボードイベントの監視を実装しています* /プライベートクラスのkeymonitorはkeyadapter {public void keyReleased(keyevent e){int keycode = e.getkeycode(); if(keycode == keyevent.vk_enter){//モニターがキーボードの入力キーにヒットすることをモニターが聞いたら、次の操作setVisible(false)を実行します。 //歓迎インターフェイスdataview.setVisible(true); //監視インターフェイスdataview.dataframe()を表示します。 //監視インターフェイスの初期化}}}/ * *スレッドを塗り直します(250ミリ秒ごとに塗り直します) {thread.sleep(250); } catch(arternedexception e){// repaintスレッドが例外をスローし、例外の詳細を表示したときにダイアログを作成しますerr = excepterwriter.geterrorinfofromexception(e); joptionpane.showmessageialog(null、err、 "error"、joptionpane.information_message); System.Exit(0); }}}}}ランニングスクリーンショット:
注:実際の操作プロセスの下部「[キーの入力]をクリックしてメインインターフェイスを入力する」はフラッシュ効果があります(たまにインターフェイスを再描画し、この文が白と黒の色で繰り返し表示できるようにすることで達成されます)。ダブルバッファリング方法は、再描画時にインターフェイスを点滅させる問題を解決するのに役立ちます(二重バッファリング方法を使用しない場合、古いインターフェイスに新しいものを少し描画するたびにビットでビットで描画するのと同等であり、基本的に最初に新しいインターフェースをメモリに描画し、次に古いインターフェースを直接カバーすることができます。
dataview.javaコードは次のとおりです。(このクラスは、シリアルポートデータをリアルタイムで表示するために使用されます)
簡単な説明:
ハードウェアデバイスは、時々シリアルポートを介してデータをコンピューターに送信します。シリアルポートツールがハードウェアデバイスに正常に接続され、監視が追加された後、データを受信するたびにデータを解析してインターフェイスを更新します。
あなたの要件は、それを使用するときに私のものとは異なる可能性があります。このクラスは参照用です。実際には、データ表示インターフェイスとデータ分析方法を再作成する必要がある場合があります。
パッケージSerialPort; Import Java.awt.Button; Import Java.awt.Choice; Import Java.awt.Color; Import Java.awt.Frame; Import Java.awt.Graphics;インポートJava.awt.image; Import java.awt.laba.awt. java.awt.event.actionevent; Import java.awt.event.actionlistener; Import java.awt.event.windowadapter; import java.awt.event.windowent; Import java.util.list; Import Java.util.utelistenSexception; Import javax.swynexcept.swynexcection; gnu.io.serialport; Import gnu.io.serialportevent; Import gnu.io.serialporteventlistener; Import serialexception。クライアントクライアント= null;プライベートリスト<String> commlist = null; //利用可能なポート番号を保存Private SerialPort SerialPort = null; //シリアルポートオブジェクトの保存プライベートフォントフォント=新しいフォント( "Microsoft yahei"、font.bold、25);プライベートラベルTem = new Label( "No data illal"、label.center); //温度プライベートラベルhum = new Label( "No data illal"、label.center); //湿度のプライベートラベルPA = new Label( "No Data No Alut"、label.center); //圧力プライベートラベルRain = new Label( "No data illal"、label.center); // Rainfall Private Label win_sp = new Label( "No Data illal"、label.center); //風速プライベートラベルwin_dir = new label( "No Data No Illat"、label.center); // Wind Direction Private Choice Commchoice = new Choice(); //シリアルポート選択(ドロップダウンボックス)プライベート選択bpschoice = new Choice(); //不良レート選択プライベートボタンopenserialbutton = newボタン( "SERIAL PORTを開く");画像offscreen = null; // canvas repainting //ウィンドウのアイコンを設定するtoolkit toolkit = getToolKit();画像アイコン= toolkit.getImage(dataview.class.getResource( "Computer.png")); / *** class constructor* @param client*/ public dataview(client client){this.client = client; commlist = serialTool.findport(); //プログラムが初期化されたときに一度有効なシリアルポートをスキャン} /***メインメニューウィンドウが表示されます。 *ラベル、ボタン、ドロップダウンバー、関連するイベントリスニングを追加します。 */ public void dataframe(){this.setBounds(client.loc_x、client.loc_y、client.width、client.height); this.settitle( "cdio project"); this.seticOnimage(アイコン); this.setbackground(color.white); this.setlayout(null); this.addwindowlistener(new windowadapter(){public void windowclosing(windowevent arg0){if(serialport!= null){//プログラムがリソースSerialTool.ClosePort(serialport);} System.exit(0);}}); Tem.setbounds(140、103、225、50); tem.setbackground(color.black); tem.setfont(font); tem.setforeground(color.white); add(tem); hum.setbounds(520、103、225、50); hum.setbackground(color.black); hum.setfont(font); hum.setforeground(color.white); add(hum); Pa.setbounds(140、193、225、50); pa.setbackground(color.black); pa.setfont(font); pa.setforeground(color.white); add(pa); Rain.setbounds(520、193、225、50); rain.setbackground(color.black); rain.setfont(font); Rain.setforeground(color.white);追加(雨); win_sp.setbounds(140、283、225、50); win_sp.setbackground(color.black); win_sp.setfont(font); win_sp.setforeground(color.white); add(win_sp); win_dir.setbounds(520、283、225、50); win_dir.setbackground(color.black); win_dir.setfont(font); win_dir.setforeground(color.white); add(win_dir); //シリアルポート選択オプションを追加するcommchoice.setbounds(160、397、200、200); //利用可能なシリアルポートがあるかどうかを確認します。 if(commlist == null || commlist.size()<1){joptionpane.showmessageialog(null、 "有効なシリアルポートは見つかりませんでした!"、 "error"、joptionpane.information_message); } else {for(string s:commlist){commchoice.add(s); }} add(commchoice); //ボーレートオプションを追加するbpschoice.setbounds(526、396、200、200); bpschoice.add( "1200"); bpschoice.add( "2400"); bpschoice.add( "4800"); bpschoice.add( "9600"); bpschoice.add( "14400"); bpschoice.add( "19200"); bpschoice.add( "115200"); add(bpschoice); //開いたシリアルポートボタンを追加しますopenserialbutton.setbounds(250、490、300、50); openserialbutton.setbackground(color.lightgray); openSerialButton.setFont(new Font( "Microsoft yahei"、font.bold、20)); openserialbutton.setforeground(color.darkgray); add(openserialbutton); //オープンシリアルポートボタンをリスニングするイベントを追加OpenSerialButton.AddActionListener(new ActionListener(){public void ActionPerformed(ActionEvent e){//シリアルポート名String commname = commchoice.getSelectedItem(); (commname == null || commname.equals( "")){joptionpane.showmessageialog(null、 "有効なシリアルポートは見つかりませんでした!"、 "error"、joptionpane.information_message) joptionpane.showmessageialog(null、 "悪いレートがエラー!"、 "error"、joptionpane.information_message) serialtool.openport(commname、bps); //モニターの監視が成功するように求められますjoptionpane.showmessageialog(null、「モニターは成功します、監視データが後で表示されます!」、「prompt」、joptionpane.information_message); } catch(serialpormparameterfailure | notaserialport | nosuchport | Nosuchport | portinuse | toomanylisteners e1){//エラーが発生した場合、ダイアログを使用して特定のエラーメッセージJoptionpane.showMessageialog(null、e1、 "error"、joptionpane.information_message); }}}}}}); this.SetSizable(false);新しいスレッド(new Repaintthread())。start(); // repaintスレッドを起動}/***メインインターフェイスコンポーネント要素を描画*/public void paint(グラフィックスG){color c = g.getColor(); g.setcolor(color.black); g.setFont(new Font( "Microsoft Yahei"、font.bold、25)); G.DrawString( "温度:"、45、130); g.setcolor(color.black); g.setFont(new Font( "Microsoft Yahei"、font.bold、25)); G.DrawString( "湿度:"、425、130); g.setcolor(color.black); g.setFont(new Font( "Microsoft Yahei"、font.bold、25)); G.DrawString( "圧力:"、45、220); g.setcolor(color.black); g.setFont(new Font( "Microsoft Yahei"、font.bold、25)); G.DrawString( "Rain:"、425、220); g.setcolor(color.black); g.setFont(new Font( "Microsoft Yahei"、font.bold、25)); G.DrawString( "風速:"、45、310); g.setcolor(color.black); g.setFont(new Font( "Microsoft Yahei"、font.bold、25)); G.ドローストリング( "風向:"、425、310); g.setcolor(color.gray); g.setFont(new Font( "Microsoft Yahei"、font.bold、20)); G.DrawString( "シリアルポート選択:"、45、410); g.setcolor(color.gray); g.setFont(new Font( "Microsoft Yahei"、font.bold、20)); G.DrawString( "Bad Rate:"、425、410); } / ***ダブルバッファリングメソッドは、インターフェイスの各要素コンポーネントを塗り直します* / public void update(グラフィックスG){if(offscreen == null)offcreen = this.createimage(client.width、client.height);グラフィックgoffscreen = offscreen.getGraphics(); color c = goffscreen.getColor(); goffscreen.setcolor(color.white); goffscreen.fillrect(0、0、client.width、client.height); //背景キャンバスthis.paint(goffscreen)を塗り直します。 //インターフェイス要素goffscreen.setColor(c)を塗り直します。 G.drawimage(オフスクリーン、0、0、null); //「スプレー」された元のキャンバスに新しく描かれたキャンバス}/ * * repaintスレッド(30ミリ秒ごとに再塗装) //利用可能なシリアルポートCommlist = serialTool.findport()をスキャンします。 if(commlist!= null && commlist.size()> 0){//(string s:commlist)for(string s:commlist)の新しくスキャンされた使用可能なシリアルポートを追加します。最初のデフォルトは存在しません(コムリストに存在するが、通信に存在しない場合、新しく追加されます)boolean commexist = false; for(int i = 0; i <commchoice.getItemcount(); i ++){if(s.equals(commchoice.getitem(i))){//現在スキャンされているシリアルポート名は、最初のスキャンcommexist = trueに既に存在しています。壊す; }} if(commexist){//最初のスキャンには現在スキャンされているシリアルポート名が既に存在し、次のループの継続を直接入力します。 } else {//存在しない場合は、新しいシリアルポート名を使用可能なシリアルポートドロップダウンリストcommchoice.add(s)に追加します。 }} //(int i = 0; i <commchoice.getItemcount(); i ++){//シリアルポートの有効期限が切れているかどうかは無効であるかどうか(通信党に存在しないが、期限切れになっていない)boolean commnotexist = true; for(string s:commlist){if(s.equals(commchoice.getitem(i))){commnotexist = false;壊す; }} if(commnotexist){//system.out.println("remove " + commchoice.getitem(i)); commchoice.remove(i); } else {続行; }}} else {//スキャンされたコムリストが空の場合、既存のすべてのシリアルポートcommchoice.removeall()を削除します。 } try {thread.sleep(30); } catch(arturnedexception e){string err = exceptionwriter.geterrorinfofromexception(e); joptionpane.showmessageialog(null、err、 "error"、joptionpane.information_message); System.Exit(0); }}}}}} / ***内部クラスの形でシリアルリスニングクラスを作成します* @author zhong*** / private class seriallistenerは、シリアルポートventlistener { / ***監視対象のシリアルポートイベント*を処理します* / public void serialevent(serialportteventevent(){Switch()switch()sited()sited()sited()sited() serialPortevent.bi:// 10通信中割り込みjoptionpane.showmessageialog(null、 "communication interrurt with serial device"、 "error"、joptionpane.information_message);壊す; case serialportevent.oe:// 7オーバーフロー(オーバーフロー)ケースserialportevent.fe:// 9フレームエラーケースserialportevent.pe:// 8パリティエラーケースserialportevent.cd:// 6キャリア検出ケースシリアルポートエベント。 5リンギングは、serialportevent.output_buffer_empty:// 2 case serialportevent.output_buffer_emptyを示します。 serialportevent.data_available:// 1つの使用可能なデータがシリアルポート// system.out.println( "fund data")に存在します。 byte [] data = null; try {if(serialport == null){joptionpane.showmessageialog(null、 "シリアルポートオブジェクトは空です!監視が失敗!"、 "error"、joptionpane.information_message); } else {data = serialtool.readfromport(serialport); //データを読み取り、それをバイト配列に保存します// System.out.println(new String(data)); //解析プロセスをカスタマイズすると、実際の使用プロセス中に自分のニーズに応じてデータを受信した後にデータを解析できます。 joptionpane.information_message); System.Exit(0); } else {string dataoriginal = new String(data); //バイト配列データを元のデータ文字列を保存する文字列に変換しますdatavalid = ""; //有効なデータ(元のデータ文字列を保存し、最初の *番号の後に文字列を削除するために使用される)文字列[] elements = null; //元の文字列をスペースで分割した後に取得した文字列アレイを保存するために使用されます要素= datavalid.split( ""); if(elements == null || emention.length <1){//データが正しく解析されているかどうかを確認しますjoptionpane.showmessageialog(null、 "データ解析プロセスにはデバイスまたはプログラムがあります!"、 "error"、joptionpane.information_message); System.Exit(0); } else {try {//インターフェイスラベル値/*for(int i = 0; i <lemention.length; i ++){system.out.println(elements [i]); }*///system.out.println("win_dir: " +要素[5]); tem.settext(要素[0] + "℃"); hum.settext(要素[1] + "%"); pa.settext(要素[2] + "hpa"); rain.settext(要素[3] + "mm"); win_sp.settext(要素[4] + "m/s"); win_dir.settext(要素[5] + "°"); } catch(arrayindexOutofboundsexception e){joptionpane.showmessageialog(null、 "データ分析プロセスにはエラーがあり、更新インターフェイスデータが失敗しました!デバイスまたはプログラムを確認してください!」、「エラー」、joptionpane.information_message); System.Exit(0); }}}}}}}} catch(readDatafromserialportfailure | serialportinputStreamCloseFailure e){joptionpane.showmessageialog(null、e、 "error"、joptionpane.information_message); System.Exit(0); //読み取りエラーが発生したときにエラーメッセージが表示された後にシステムを終了します} break; }}}}ランニングスクリーンショット:
プロジェクトソースコード全体をダウンロードしてください:http://xiazai.vevb.com/201612/yuanma/javaserialmonitor(vevb.com).rar
上記はこの記事のすべての内容です。みんなの学習に役立つことを願っています。誰もがwulin.comをもっとサポートすることを願っています。