Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Compiler always encodes in UTF-8? (Read 148 times)
Johnny_J
Newbies
*
Offline


Posts: 4
Joined: Apr 22nd, 2024
Compiler always encodes in UTF-8?
Dec 17th, 2024 at 5:40am
Print Post  
I have a font with europeean characters in the range 0x80 to 0xff (ANSI, Windows-1252-encoding). The editor/compiler however, always encode C-strings in UTF-8 so the europeean characters diplays as garbage on the display. How can I tell the compiler to stick to ANSI (Windows-1252) as plain Visual Studio does? The file is saved as ANSI, no UTF-encoding.
Also, if I build the code in Visual Studio Code it works as it should and displays all characters correctly.
« Last Edit: Dec 17th, 2024 at 7:41am by Johnny_J »  
Back to top
 
IP Logged
 
Simon@Visual Micro
Administrator
*****
Offline


Posts: 2496
Joined: Feb 13th, 2019
Re: Compiler always encodes in UTF-8?
Reply #1 - Dec 17th, 2024 at 10:41am
Print Post  
Thanks for the report.

If you save the source file with UTF-8 Encoding specifically the characters should print as expected.

In Visual Studio with the INO file open, click File > Save As > Click the drop down next to the [Save] button and select Save With Encoding > Click Yes to Overwrire the existing File > Select Unicode UTF-8 with Signature - Code Page 65001 > OK.

Then build and upload the sketch again and the characters should be displayed as required.
https://visualmicro.com/page/User-Guide.aspx?doc=Non-ASCII.html
  
Back to top
IP Logged
 
Johnny_J
Newbies
*
Offline


Posts: 4
Joined: Apr 22nd, 2024
Compiler must use UTF-8?
Reply #2 - Dec 17th, 2024 at 11:38am
Print Post  
Thanks for the reply but saving the file as UTF-8 is already tried.
It can never work as the font file is in Windows-1252-encoding with one byte per character.
The compiler encodes the string "åäö" as:
0xEF 0xBF 0xBD 0xEF 0xBF 0xBD 0xEF 0xBF 0xBD 
which is UTF-8 for "replacement character". This seems to point out that Arduino/Visual Micro cannot handle characters above 0x7f which suggests that you have to use UTF-8 (which breaks the code in another way). Strange, as VS Code & PlatformIO performs ok with those characters.
I use Visual Studio with Visual Micro using Arduino IDE 2 or Visual Micro (no IDE).
I'm using a 1.8 TFT display with 
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
which works ok with VS Code & PlatformIO with the .ino file saved with Windows-1252-encoding.

Edit:
I also tried with Arduino IDE stand-alone. It works as well. It is only Visual Micro which refuses to understand character codes above 0x7f if not encoded as UTF-8 (which then will not work with the display).
« Last Edit: Dec 17th, 2024 at 2:59pm by Johnny_J »  
Back to top
 
IP Logged
 
Simon@Visual Micro
Administrator
*****
Offline


Posts: 2496
Joined: Feb 13th, 2019
Re: Compiler always encodes in UTF-8?
Reply #3 - Dec 17th, 2024 at 4:52pm
Print Post  
Thanks for clarifying.

We will release an update in the coming day and update this thread when it is available. 

It has an additional setting which ensures the encoding the file is saved with is preserved through the compilation process.

  
Back to top
IP Logged
 
Simon@Visual Micro
Administrator
*****
Offline


Posts: 2496
Joined: Feb 13th, 2019
Re: Compiler always encodes in UTF-8?
Reply #4 - Dec 18th, 2024 at 4:07pm
Print Post  
Can you install the latest release from the top of the below board:
https://www.visualmicro.com/forums/YaBB.pl?board=VS_ARDUINO_EXT_RELEASES

Then if you add a local board.txt to your project (vMicro > Add Code > Add Local Board.txt) and paste in the below entry:
vm.compiler.use_file_own_encoding=true

Also ensure the INO file (and any others affected) are saved with the correct ANSI encoding as desired (using File > Save As > Save with Encoding).

Then if you restart Visual Studio and rebuild your project, the encoding should persist through the compilation process.
  
Back to top
IP Logged
 
Johnny_J
Newbies
*
Offline


Posts: 4
Joined: Apr 22nd, 2024
Re: Compiler always encodes in UTF-8?
Reply #5 - Dec 19th, 2024 at 8:31am
Print Post  
Working now but it is pretty ridiculous that you need to add an exception to get a reasonable and default behavior from Visual Micro like these platforms do from the beginning:
Arduino IDE
Visual Studio
Visual Studio Code
PlatformIO


So the "vm.compiler.use_file_own_encoding=true" should really be the default with Visual Micro as well!
« Last Edit: Dec 19th, 2024 at 1:51pm by Johnny_J »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12166
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Compiler always encodes in UTF-8?
Reply #6 - Dec 19th, 2024 at 1:49pm
Print Post  
The setting will most likely become default after we have tested with different IO boards. Windows/linux programs and an embedded program have different constraints to be careful of.
  
Back to top
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint