Robofun 機器人論壇
標題:
NXT大量資料藍芽傳輸
[打印本頁]
作者:
神鵰
時間:
2009-8-14 17:15
標題:
NXT大量資料藍芽傳輸
我現在已經會用NXC語言來一次傳輸一個數值,但是我怎麼試都無法一次傳輸兩個以上的數值,這樣的語法該怎麼寫呢?
聽說NXT只有10個收發信箱,有沒有什麼語法或方法來擴大資料的傳輸呢?
還有一個小問題,為什麼接收到資料之後,回傳的數值要是0xFF? 而不是一般的時進位法
我寫的失敗程式(傳輸i和z兩亂數,接收後轉變為in和c,再顯示出來):
//MASTER
#define BT_CONN 1
#define OUTBOX 5
#define INBOX 1
#define OUTBOX 4
#define INBOX 2
sub BTCheck(int conn){
if (!BluetoothStatus(conn)==NO_ERR){
TextOut(5,LCD_LINE2,"Error");
Wait(1000);
Stop(true);
}
}
task main(){
int ack, i, z;
BTCheck(BT_CONN);
TextOut(10,LCD_LINE1,"Master sending");
while(true){
i = Random(100);
z = Random(50);
TextOut(0,LCD_LINE3," ");
NumOut(5,LCD_LINE3,i);
TextOut(0,LCD_LINE2," ");
NumOut(5,LCD_LINE2,z);
ack = 0;
SendRemoteNumber(BT_CONN,OUTBOX,i);
SendRemoteNumber(BT_CONN,OUTBOX,z);
until(ack==0xFF) {
until(ReceiveRemoteNumber(INBOX,true,ack) == NO_ERR);
}
Wait(2000);
}
}
//SLAVE
#define BT_CONN 1
#define OUT_MBOX 1
#define IN_MBOX 5
#define OUT_MBOX 2
#define IN_MBOX 4
sub BTCheck(int conn){
if (!BluetoothStatus(conn)==NO_ERR){
TextOut(1,LCD_LINE4,"Error");
Wait(1000);
Stop(true);
}
}
task main(){
int in, c;
BTCheck(0);
TextOut(5,LCD_LINE1,"Slave receiving");
SendResponseNumber(OUT_MBOX,0xFF);
while(true){
if (ReceiveRemoteNumber(IN_MBOX,true,in) && ReceiveRemoteNumber(IN_MBOX,true,c) != STAT_MSG_EMPTY_MAILBOX) {
TextOut(0,LCD_LINE3," ");
NumOut(5,LCD_LINE3,in);
TextOut(0,LCD_LINE2," ");
NumOut(5,LCD_LINE2,c);
SendResponseNumber(OUT_MBOX,0xFF);
}
Wait(2000);
}
}
歡迎光臨 Robofun 機器人論壇 (https://robofun.net/forum/)
Powered by Discuz! X3.2