I got this working by rewriting the 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
iolit = IOBuffer(s)
num = read(iolit, Int16)
# println(sizeof(num))
# println(num[1])
# @printf("value = %d", Int(num))
close(iolit)
# typeof(s)
# k = parse(Int,s) # Convert String to integer
return num # Return the integer
end
Thank you, @Benny, for your response.