Reading text file with Asian fonts in Codesys results in garbage

AlfredoQuintero

Lifetime Supporting Member
Join Date
Feb 2015
Location
Yokohama
Posts
1,551
Hello. I have a problem which may be common in this part of the world. My CoDeSys program reads data from a text file that I generate from the program itself with a system call for Windows text console in the form of "dir <PATH> /B > <PATH>dir_list.txt", which generates a text file with the filenames in that directory, separated by line feed characters. If the filenames are pure ASCII everything is fine. But if the filenames contain Asian fonts (in this case Japanese fonts), then what I read from the program is garbage display, as I show below.
Before I tell my customer that he can only use filenames in ASCII so I can continue with the development (and make him get quite grumpy), I though I would fire a question to the forum, to see if someone would be familiar wit this problem and could suggest a fix, in which case I will be as ever very grateful.
Thanks.

2021-08-05_AsianFontReadingPrblem.png
 
Yes, thanks I though this is where the problem comes from. What I do not know is how to solve this problem on the CoDeSys program. Codesys has a WSTRING type Unicode. But the file functions only support STRING. Unless there are file functions that I am unaware of that will work with WSTRING.
 
Is this in the HMI program ?
Is it a script language ?

My own experience with VBS in Siemens WinCC is that you need to tell the file operations that it must read unicode.

i.e.:
Code:
Const Unicode = -1
Const forreading = 1
Set ts = fso.OpenTextFile(str_Path_and_File, forreading , False , Unicode)
SmartTags("mytextstring") = ts.readline
 
Don't ask me questions on this, I don't use Codesys, but I am interested in understanding how to use Unicode, so I did some searching:

https://forge.codesys.com/forge/talk/Engineering/thread/3608e375a7/

https://faq.codesys.com/display/CDSFAQ/SysFile:+Saving+Files+in+UTF-8+Format

https://forge.codesys.com/forge/talk/Visualization/thread/aac699818f/
Particularly this bit:
Interesting. When the first two characters of a text file are ÿþ, that is a notice to the text editor that it is a UTF-16 LE encoded file (is unicode). More details on Wikipedia.
 
Is this in the HMI program ?
Is it a script language ?

My own experience with VBS in Siemens WinCC is that you need to tell the file operations that it must read unicode.

i.e.:
Code:
Const Unicode = -1
Const forreading = 1
Set ts = fso.OpenTextFile(str_Path_and_File, forreading , False , Unicode)
SmartTags("mytextstring") = ts.readline
I am using CoDeSys in Windows so the PLC and the HMI are both contained in the PLC application.
 
Don't ask me questions on this, I don't use Codesys, but I am interested in understanding how to use Unicode, so I did some searching:

https://forge.codesys.com/forge/talk/Engineering/thread/3608e375a7/

https://faq.codesys.com/display/CDSFAQ/SysFile:+Saving+Files+in+UTF-8+Format

https://forge.codesys.com/forge/talk/Visualization/thread/aac699818f/
Particularly this bit:
Interesting. When the first two characters of a text file are ÿþ, that is a notice to the text editor that it is a UTF-16 LE encoded file (is unicode). More details on Wikipedia.


BryanG, thanks for these articles. I think I know what I need todo. The way I am generating the text file is the problem. I will generate the text file as indicated in one of the articles. Too late here in Japan. I hope I can get this fixed tomorrow.
 
Gentlemen, In think I have seen the light and it costs only EUR 50.

This morning I was discussing with a potential customer the possibility of using CoDeSys for a project and to my astonishment, while I was showing them the CoDeSys website, I discovered a "software package “IIoT Libraries SL” contains libraries for “IIoT communication” and libraries for reading and writing of data structures." I have just purchased this package. It has libraries for reading and writing CSV files an INI files. I am interested in the CSV file funtion. Just by reading the datasheet of the product I immediately realized that I would need weeks to code these functions myself. Will give them a try if anyone is interested, I can post some feedback.

https://store.codesys.com/en/iiot-libraries-sl.html
 

Similar Topics

This is my first post and I think this is a great website. I am currently trying to read a .txt file from a remote computer on the network, into...
Replies
3
Views
5,655
Hello I have a s7-1200 and I would like to read the tags present in this controller with my controllogix controller. The two controllers don't use...
Replies
5
Views
142
Hi all, i have 8 CJ2m plc units that show different numbers on the plc display and i am stuck on reading the info. my unit has an ip address of...
Replies
3
Views
98
Hi Everyone, I am not proficient in RSLogix 500 so I have a question regarding the evaluation of N7:0 data as an input. So as I understand in...
Replies
1
Views
87
Trying to setup a message read via Ethernet. I have the path setup as 1, 1, 2, 192.168.66.10 I get an error code 1, ext err 315. I am beating...
Replies
9
Views
233
Back
Top Bottom