%s1 = serialport('COM4',115200);

%str = [0x90 0x02 0x60 0x02 0x00 0x00 0x20 0x00 0xfe 0xb6];

Req_frame = [0x60 0x02 0x01 0x30 0xB0 0x00];

DataArray = [0x0260 0xB001 0x0030 0x0000];
CRC = uint16(0);
mask_val = uint16(32768);
for i = 1:size(DataArray,2)
    shifter = 32768;
    c = uint16(DataArray(i));
    while(shifter>0)
        carry = bitand(CRC,mask_val);
        CRC = bitshift(CRC,1);
        if (c && shifter)
            CRC=CRC+1;
        end
        if(carry)
            CRC=bitxor(CRC,4129);
        end
        shifter = shifter/2;

    end

end

%write(s1,str,"uint8");
