简体   繁体   English

无法在MIT App Inventor 2中汇总数据

[英]Can't sum data in MIT App Inventor 2

在此处输入图片说明

So when I try to sum the variable Consum with Test (received from bluetooth), the blue block does not allow such operation. 因此,当我尝试将变量ConsumTest相加(从蓝牙接收)时,蓝色块不允许进行此类操作。 If this is in normal coding program it would be: 如果在常规编码程序中,它将是:

Consume = Consume + Test;

Any help? 有什么帮助吗?

you only can add data, if data is available 如果有数据,您只能添加数据
therefore in the Clock.Timer event add another if statement like this 因此,在Clock.Timer event添加另一个类似的if语句

if BluetoothClient1.BytesAvailableToReceive > 0
then...

Here is what App Inventor says about the Receive Text function: 这是App Inventor关于“接收文本”功能的说明:

Receive text from the connected Bluetooth device. 从连接的蓝牙设备接收文本。 If numberOfBytes is less than 0, read until a delimiter byte value is received. 如果numberOfBytes小于0,请读取直到接收到定界符字节值。

This function receives bytes from the Bluetooth component and returns text, which cannot be added unless the text is a number. 此函数从Bluetooth组件接收字节并返回文本,除非文本为数字,否则无法添加文本。 If you look at the error message that you get, it should tell you that you are adding a string and a number. 如果查看收到的错误消息,它应该告诉您正在添加字符串和数字。 You could have also used the Do It option in the emulator or companion to see the result that the Receive Text procedure outputs. 您还可以在仿真器或辅助程序中使用“执行”选项来查看“接收文本”过程输出的结果。

Here is an example of the proper way to use this block: you should set the test variable to bytes available to receive and then remove all available bytes by using receive text with the available bytes. 这是使用此块的正确方法的示例: 应将测试变量设置为可用于接收的字节,然后通过将接收文本与可用字节一起使用来删除所有可用字节。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM