function [err] = BK_SetMaxCurrent(sp,Imax)

PACKET_LENGTH = 26;
Imax = uint32(Imax*10000);  %Convert to milliamps units

LoadCmdPacket = zeros(1,PACKET_LENGTH);
LoadCmdPacket(1:3)  = [ hex2dec('aa') 00 hex2dec('24')];
LoadCmdPacket(4) = uint8(bitand(Imax,255,'uint32'));
LoadCmdPacket(5) = uint8(bitand(bitshift(Imax,-8),255,'uint32'));
LoadCmdPacket(6) = uint8(bitand(bitshift(Imax,-16),255,'uint32'));
LoadCmdPacket(7) = uint8(bitand(bitshift(Imax,-24),255,'uint32'));

LoadCmdPacket(end) = rem(sum(LoadCmdPacket(1:end-1)),256);  %Compute checksum

%dec2hex(LoadCmdPacket')

fwrite(sp,LoadCmdPacket);
 A = fread(sp,PACKET_LENGTH);
% dec2hex(A')
 if(A(4) == hex2dec('80'))
     err = 0;
 else
     err = 1;
 end
end
