串行速度在serproxy和Arduino草图中是否匹配?
parseInt() 它不适用于二进制数据,它希望数字为ascii字符:“1”,而不是1。
parseInt()
尝试通过Socket类的字符串方法之一发送数据,例如:
socket.writeMultiByte("125" , "us-ascii") ; socket.flush();
并尝试手动将数据输入到以下草图的串行监视器中以查看方法 parseInt() 作品:
int n = 401;//display value, this value will be displayed, can be changed boolean new_val = true ; void setup() { Serial.begin(9600); // set up Serial library at 9600 bps // This check is only needed on the Leonardo: while (!Serial) { ; // Wait for serial port to connect. Needed for Leonardo only } delay(100) ; Serial.println( "Started") ; } void loop() { serialEvent(); if (new_val) { Serial.print( "n: " ); Serial.println( n , DEC ) ; new_val = false ; } delay(200) ; } void serialEvent() { while(Serial.available() > 0) { int c = Serial.parseInt(); if (c != 0) { n = c; new_val = true ; } } }