[精讚] [會員登入]
466

用java讀取microbit寫到serial的資料

用java讀取microbit寫到serial的資料

分享此文連結 //n.sfs.tw/14876

分享連結 用java讀取microbit寫到serial的資料@igogo
(文章歡迎轉載,務必尊重版權註明連結來源)
2020-12-23 15:00:45 最後編修
2020-12-23 11:53:58 By igogo
 

 

 

 

 

使用jSerialComm 函示庫

 

	<dependency>
			<groupId>com.fazecast</groupId>
			<artifactId>jSerialComm</artifactId>
			<version>2.6.2</version>
		</dependency>

 

利用 SerialPort.getCommPorts()

找到接micro:bit的com


	SerialPort com = SerialPort.getCommPorts()[0];
		com.setComPortParameters(115200,8,1,10);
		com.setComPortTimeouts(SerialPort.TIMEOUT_SCANNER,0,0);

		com.openPort();

		InputStream in = com.getInputStream();

		byte[] buffer = new byte[com.bytesAvailable()];

		String message = "";
		for (int i = 0; i < 30; i++) {
			int len = in.read(buffer);
			if (len > 0) {
				message = new String(buffer);
				System.out.println(message);
			}
			Thread.sleep(1000);
			len = 0;

		}


		in.close();
		com.closePort();
	}

 

結果

1131431441461491501491491491491501491491491501501501511511511501501511511511521511521511521521511521511511511511521511531521521521521531511521511521501511521531521511521531521531531511531521521521511521511501521521531521521521511521521511511521521531521531531531531
5215215315315215215215215215215115215215315315215215115115215315215215215215215315315415315215315115115215315315215215315315415315315415415315415415415315315415415515315315315415415415415415415415415415415415515315415415415415415415415615415515515415415415515515415
51551551541541541541541551551<DAPLink:Overflow>

1121431441461491501491491491491501491491491501501501511511511501501511511511521511521511521521511521511511511511521511531521521521521531511521511521501511521531521511521531521531531511531521521521511521511501521521531521521521511521521511511521521531521531531531531
5215215315315215215215215215215115215215315315215215115115215315215215215215215315315415315215315115115215315315215215315315415315315415415315415415415315315415415515315315315415415415415415415415415415415415515315415415415415415415415615415515515415415415515515415
51551551541541541541541551551<DAPLink:Overflow>

1131431441461491501491491491491501491491491501501501511511511501501511511511521511521511521521511521511511511511521511531521521521521531511521511521501511521531521511521531521531531511531521521521511521511501521521531521521521511521521511511521521531521531531531531
5215215315315215215215215215215115215215315315215215115115215315215215215215215315315415315215315115115215315315215215315315415315315415415315415415415315315415415515315315315415415415415415415415415415415415515315415415415415415415415615415515515415415415515515415
51551551541541541541541551551<DAPLink:Overflow>

 

前三個數字就是方位值

END

你可能感興趣的文章

用java讀取microbit寫到serial的資料 用java讀取microbit寫到serial的資料

我有話要說

>>

限制:留言最高字數1000字。 限制:未登入訪客,每則留言間隔需超過10分鐘,每日最多5則留言。

訪客留言

[無留言]

隨機好文

vue.js components 多個組件的呈現 vue.js 組件 component

[vue.js] 動態的props 做parent-child components 雙向綁定 vue.js props components camel-case

centos 7 移机出現 dracut-initqueue timeout centos 7 移机出現 dracut-initqueue timeout 處理

proxmox lxc 救援 今天突然接到一名強者我朋友的臨時求援 他說他把pve 從5.1升到5.2後, kvm的虛擬机器都沒問題 , 但是lxc的

00-F2 的 IPV6 反解設定 近日, 強者我的大神同事, line 傳來一句: igogo 上次你那個ipv6的設定檔 再幫我跑一次 如連結 程式都寫