|  | 
 
 发表于 2014-6-6 10:46:14
|
显示全部楼层 
| 本帖最后由 blackblue 于 2014-6-12 09:39 编辑 
 楼主还来么?
 
 1,能否帮我看看,ROBOTCFOR NXT有没有可以用的中断(硬件中断,比如串口中断什么的)?
 2,另,nxtReadRawHS能不能用它写出类似ARDUINO一样的Serial.read()一样的,一个字节一个字节读的功能来,我试了几次均不灵光.......
 3,发一个刚写的,ARDUINO与NXT 485有线的通讯程序,里面有注释的(验证定长字节浮点数串口传送与还原)
 /*
 Data Source Format: 8 bytes, the first four are "ROLL" floating point format; After four is the angular velocity, but also floating point format;
 Each frame of data is 8 bytes, the rate is less than 7.5 to 8ms refresh;
 485 port transfer, BAND = 115200;*115200 = 1ms can transmit 14 bytes
 Operation: first NXT host sends "#" signal. After the device is connected to port 4 received loopback 8 bytes of data.
 
 "while (true)" Time cycle time needed to "dt", to be written .....
 "dt" time to control at 10ms or less (target);
 ROBOTC FOR NXT hardware interrupt is still not available, it is not good .....
 
 Write time :2014-5-4 Author: Jack Lu
 Note:Code must be run in the robotc 3.6.2 or higher
 */
 
 //
 void rs485_init()
 {
 nxtEnableHSPort();
 nxtSetHSBaudRate(115200);
 nxtHS_Mode = hsRawMode;
 wait10Msec(50);
 }
 /*//Mandatory for ROBOTC invalid pointer type, abandoned
 float ByteToFloat(unsigned char* byteArry)
 {
 return *((float*)byteArry);
 }
 */
 
 task main()
 {
 ubyte ASK[1]=0x23;
 bool sign=true;
 unsigned char Re_buf[8],roll[4],omiga[4];
 int len=0,i=0;
 float angle,x_speed;
 memset(&Re_buf, 0, 8); //Formatting the memory array
 memset(&roll, 0, 4);
 memset(&omiga, 0, 4);
 
 rs485_init();
 
 while(true)
 {
 while(sign)   //Serial data transmission start
 {
 nxtWriteRawHS(&ASK[0],1);
 wait1Msec(1);
 sign=false; }
 
 if (sign==false)
 {
 
 while( nxtGetAvailHSBytes()<8){
 wait1Msec(1); }
 
 len =  nxtGetAvailHSBytes(); //"len" variable is when debug can easily see nxtGetAvailHSBytes () return value.
 if (len==8)  nxtReadRawHS(&Re_buf[0], len);
 
 for ( i=0;i<8;i++)  //8 bytes of data split,In fact, you can add the parity bit, here is the test, so there is no use parity
 {
 if (i<4) roll = Re_buf;
 if (i>=4) omiga[i-4] = Re_buf;
 }
 sign=true;
 }
 
 memcpy(&angle,&roll[0],sizeof(angle));  //4 bytes from memory copy UNSIGNED CHAR array and pointer types into FLOAT
 memcpy(&x_speed,&omiga[0],sizeof(x_speed));
 
 nxtDisplayTextLine(0, "Stat Test");
 nxtDisplayTextLine(1, "-------------------");
 nxtDisplayTextLine(3, "%f",angle);
 nxtDisplayTextLine(5, "%f",x_speed);
 
 // do somtings
 }
 }
 | 
 |