极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10746|回复: 3

16进制接收后做判断,这个问题一直困扰我。求助

[复制链接]
发表于 2014-5-12 14:33:45 | 显示全部楼层 |阅读模式
String ck = "";

while(Serial.available() > 0)
  {
    ck += char(Serial.read());
    delay(2);
    mark =1;
  }  
if(mark == 1)
  {
if(ck==0x06A33A2EFF12){
    fid = 0;
      if(digitalRead(41)==HIGH){
      delay(200);
      fid = 1;
      }else{
      fid = 0;
      }
      switch(fid){
      case 0: digitalWrite(41, LOW);break;
      case 1: digitalWrite(41, HIGH);break;
      }
      delay(2);
      }
  }
  ck = String("");
  mark = 0;

串口接收16进制06A33A2EFF12后进入判断。调试的时候,出现一下错误。



zonghe:63: error: integer constant is too large for 'long' type
zonghe:79: error: integer constant is too large for 'long' type
zonghe:94: error: integer constant is too large for 'long' type
zonghe.ino: In function 'void loop()':
zonghe:63: error: invalid conversion from 'long long int' to 'const char*'
zonghe:63: error: initializing argument 1 of 'unsigned char String:perator==(const char*) const'
zonghe:79: error: invalid conversion from 'long long int' to 'const char*'
zonghe:79: error: initializing argument 1 of 'unsigned char String:perator==(const char*) const'
zonghe:94: error: invalid conversion from 'long long int' to 'const char*'
zonghe:94: error: initializing argument 1 of 'unsigned char String:perator==(const char*) const'

看样子是说ck这个数组长度不够。
不知道怎么定义让他够呢。
回复

使用道具 举报

发表于 2014-5-12 17:58:01 | 显示全部楼层
你还真够长的。。。。。你试试用某些GPS处理串口的方法试试?
回复 支持 反对

使用道具 举报

发表于 2014-5-12 22:40:14 | 显示全部楼层
ck是字符串变量,而0x06A33A2EFF12是数值,二者不能直接比较判断相等,你需要把ck转换为数值后再比较。而且0x06A33A2EFF12是一个48bit的数值,也超过了长整形long存储32位(4字节)大小的变量。找本C语言的书看看就明白了
回复 支持 反对

使用道具 举报

发表于 2014-5-12 22:52:52 | 显示全部楼层
if(ck==0x06A33A2EFF12){
可改成if(ck.equals("06A33A2EFF12")){  //----如果ck和"06A33A2EFF12"完全相符,就返回TRUE
或if(ck.equalsIgnoreCase("06A33A2EFF12")){//----和equal一样,但是不限制大小写
试试
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-15 07:26 , Processed in 0.054021 second(s), 19 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表