2014-06-22 68 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))) { 
.......... 
}