2014-06-22 36 views
0

我需要一个代码,一个AnalogIn输入转换的mbed LPC1768数字由我使用的CAN controller.The例如语法被用来帮助模拟输入转换为数字的CAN是在mbed LPC1768

if(can1.write(CANMessage(1337, &counter, 2))) { 
.......... 
} 

其中“counter”是要由我作为一个符号的int(该示例然而它定义为一个char)发送和定义的数据。但我不断收到错误消息

Error: No instance of constructor "mbed::CANMessage::CANMessage" matches the argument list in "project_test.cpp" 

控制器CANMessage语法

CANMessage(int _id, const char *_data, char _len = 8, CANType _type = CANData, CANFormat _format = CANStandard) { 

    len = _len & 0xF; 
    type = _type; 
    format = _format; 
    id  = _id; 
    memcpy(data, _data, _len); 
} 

我真的不明白控制器语法和如何应用它。任何帮助解释将不胜感激。由于

回答

0

由于CANMessage只接受一个char *的数据参数,则您可以将您的符号int值(也就是4个字节)转换为unsigned char类型是这样的:

unsigned char buf[0x8]; 
buf[0]=value & 0x000000ff; 
buf[1]=(value >> 8) & 0x000000ff; 
buf[2]=(value >> 16) & 0x000000ff; 
buf[3]=(value >> 24) & 0x000000ff; 

然后

if (can1.write(CANMessage(1337, &buf, 8))) { 
.......... 
}