开发者

Return Uint8Array from function

I'm trying to combine two Uint8Array and return the result in this function

commandframe = new Uint8Array([0x01,0x00]); GetCRC16Full(commandframe, true);

function GetCRC16Full(cmd, IsHighBefore) {
    let check= [0xff];

    var mergedArray = new Uint8Array(cmd.length + check.length);
    mergedArray.set(cmd);
    mergedArray.set(check, cmd.length);
    
    return mergedArray;

}

in Vscode debug mode I can see in function mergedArray is [0x01,0x00,0xff], but after return commandframe doesn't change, why is tha开发者_运维知识库t?


You are never modifying commandFrame. The mergedArray is returned from the function but is not assigned to commandFrame

you can try this:

commandframe = new Uint8Array([0x01,0x00]); 
commandframe = GetCRC16Full(commandframe, true);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜