LoadError: LoadError: UndefVarError: ASCIIString not defined

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

function pinMode(file_des::SerialPorts.SerialPort , pin_no::Int64 , mode::ASCIIString)
  m = uppercase(mode)                                             # Prevent errors due to case differences
  if m == "INPUT"  str = "Da"*string(Char(48+pin_no))*"0"  end    # Dan0 for INPUT
  if m == "OUTPUT"  str = "Da"*string(Char(48+pin_no))*"1"  end   # Dan1 for OUTPUT
  str = ascii(str)                                                # Converts UTF8String to ASCIIString
  write(file_des,str)
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: LoadError: UndefVarError: ASCIIString not defined

I came to know that ASCIIString no longer exists in Base, as given on ASCIIString not defined. On this website, I also found that one can use LegacyStrings package to use ASCIIString. I tried using this package and called LegacyStrings.ASCIIString instead of ASCIIString in the above-mentioned function. However, it didn’t work and later, I realized that LegacyStrings.jl package had not been updated for v0.7/master yet. Could you please help me with how to use ASCIIString in the above-mentioned function on Julia 1.6.0?

Thanking you in anticipation,

Regards,
Sudhakar

The reply on the post you link to is probably the best answer:

I encourage yo to try and work without ASCIISTRING. For example, as proposed in the answer, you could just use String and check if the string is ascii inside the function

function pinMode(file_des::SerialPorts.SerialPort , pin_no::Int64 , mode::String)
!isascii(mode) && throw("Mode needs to be ascii") #This will throw an error if mode is not ascii
  m = uppercase(mode)                                             # Prevent errors due to case differences
  if m == "INPUT"  str = "Da"*string(Char(48+pin_no))*"0"  end    # Dan0 for INPUT
  if m == "OUTPUT"  str = "Da"*string(Char(48+pin_no))*"1"  end   # Dan1 for OUTPUT
  str = ascii(str)                                                # Converts UTF8String to ASCIIString
  write(file_des,str)
end

If your code is composed of more functions, probably updating first to v0.5, then to v0.6 and v0.7. In particular v0.7 will tell you a lot of deprecation warnings to help you get your code ready for Julia v1.6

2 Likes