[精讚] [會員登入]
318

用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] 設定 content type 今天在wickt 端怎麼就是收不到vue.js 以post 傳過來的資料 找了好久才發現 application/jso

download a file from spring boot controllers ownload a file from spring boot controllers

axios vuejs application/x-www-form-urlencoded 送資料 VUE.JS 以 application/x-www-form-urlencoded 送資料

windows ad 如何得知 dn 值 如何得知 windows ad 上的使用者dn 值 https://support.symantec.com/en_US

ArrayList 與 HashMap 範例 public static void main(String[] args) { String titleIds = &