LoadError: UndefVarError: nb_available not defined

Hello everyone! I have a function (as given below) that was working for Julia 0.4.5.

function analogRead(file_des::SerialPorts.SerialPort , pin_no::Int64)
  str = "A"*string(Char(48+pin_no))   #"An" for analog value on pin n
  write(file_des,str)
  sleep(0.1)                          # Delay next step by 100 milliseconds
  n = nb_available(file_des)          # Get number of bytes in input buffer
  s = read(file_des,n)                # Read n bytes from SerialPort
  k = parse(Int,s)                    # Convert String to integer
  return k                            # Return the integer
end

Now, I have Julia 1.6.0 on my machine. As expected, the above-mentioned function is not working on this new Julia. While running this function on Julia 1.6.0, we get an error, as shown below.

LoadError: UndefVarError: nb_available not defined

I came to know that nb_available no longer exists in Base, as given on Base.nb_available is deprecated in Julia 0.7 and gone in 1.0 · Issue #53 · BioJulia/BufferedStreams.jl · GitHub. On LibSerialPort.jl – access serial ports · LibSerialPort.jl, I found that one can use
Base.bytesavailable, which returns the number of bytes waiting in the input buffer. Thus, I modified my function as given below:

function analogRead(file_des::SerialPorts.SerialPort , pin_no::Int64)
  str = "A"*string(Char(48+pin_no))   #"An" for analog value on pin n
  write(file_des,str)
  sleep(0.1)                          # Delay next step by 100 milliseconds
  n = bytesavailable(file_des)          # Get number of bytes in input buffer
  s = read(file_des,n)                # Read n bytes from SerialPort
  k = parse(Int,s)                    # Convert String to integer
  return k                            # Return the integer
end

However, it didn’t work, and upon executing this function in my Julia code, it throws an error as shown below:

LoadError: ArgumentError: invalid base 10 digit '' in "\x02"

Could you please help me with how to use bytesavailable in the above-mentioned function on Julia 1.6.0?

Thanking you in anticipation,

Regards,
Sudhakar

I got this working, as given in Converting string of bytes to integer - #4 by SudhakarKuma.

Thanks, @Benny.