开发者

Return Uint8Array from function

开发者 https://www.devze.com 2022-12-07 18:06 出处:网络
I\'m trying to combine two Uint8Array and return the result in this function commandframe = new Uint8Array([0x01,0x00]); GetCRC16Full(commandframe, true);

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

精彩评论

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