VBA 二进制文件 - cnc 程序
VBA binary file - cnc program
我正在使用宏创建 CNC 程序。
要创建机器正在使用的“.spf”文件,我使用:
Dim m2_path as string
m2_path = T:\Production\Cavity-Line\Eric R\Excel\PARAMETER.spf
Dim text as string
text = 'my data
Dim fso As Object
Dim Fileout As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set Fileout = fso.CreateTextFile(m2_path, True, True)
Fileout.Write text
Fileout.Close
当我尝试在机器上打开程序时出现错误 "Cannot open binary files"。
但是,如果我手动将 "m2_path" 文件中的内容复制到另一个文件中,然后尝试打开它,我不会收到错误消息。
文本文件的格式有问题吗?
机器正在使用 SINUMERIK 840d sl.
提前致谢
此致
编辑:
感谢@ashleedawg
很高兴听到您的更改取得了成功:
From :
Set Fileout = fso.CreateTextFile(m2_path, True, True)
to :
Set Fileout = fso.CreateTextFile(m2_path, True, False)
to create a ASCII file instead of Unicode (which could not be read by
the machine).
参考:Siemens SINUMERIK 840D sl CNC Software 2.6 SP1 HF4 Installation/Operating Manual, Page 29
Text files can be edited using the SINUMERIK Operate Editor if the
text files use the LF character (0aH) or the character string CRLF
(0d0aH) as line or end of block identifier. The editor cannot open
binary files. ... Files that are newly generated from the SINUMERIK
Operate Editor are UTF-8-coded - and have the LF characters as end of
block identifier. For UTF-8-coded files, all special characters are
correctly displayed. When opening files, the SINUMERIK Operate Editor
assumes that the files are UTF-8-coded. If files with another coding
are opened, e.g. with Windows page coding, then the special characters
are only correctly displayed if the SINUMERIK Operate was changed over
to the appropriate system language. This also involves e.g. files that
were generated using the HMI-Advanced Editor. When opening with the
SINUMERIK Operate Editor, the coding of such files is not changed.
There is no automatic conversion into UTF-8-coding. If files we re
generated or processed with an external editor (e.g. Notepad under
Windows) and not the SINUMERIK Operate Editor, then it should be noted
that the file is saved, UTF-8-coded. When using Notepad, and when
saving the file as encoding select "UTF-8" in the “Save As” dialog
box. If special characters are not being used, then "ANSI" can also be
specified as encoding.
我正在使用宏创建 CNC 程序。
要创建机器正在使用的“.spf”文件,我使用:
Dim m2_path as string
m2_path = T:\Production\Cavity-Line\Eric R\Excel\PARAMETER.spf
Dim text as string
text = 'my data
Dim fso As Object
Dim Fileout As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set Fileout = fso.CreateTextFile(m2_path, True, True)
Fileout.Write text
Fileout.Close
当我尝试在机器上打开程序时出现错误 "Cannot open binary files"。
但是,如果我手动将 "m2_path" 文件中的内容复制到另一个文件中,然后尝试打开它,我不会收到错误消息。
文本文件的格式有问题吗?
机器正在使用 SINUMERIK 840d sl.
提前致谢
此致
编辑:
感谢@ashleedawg
很高兴听到您的更改取得了成功:
From :
Set Fileout = fso.CreateTextFile(m2_path, True, True)
to :
Set Fileout = fso.CreateTextFile(m2_path, True, False)
to create a ASCII file instead of Unicode (which could not be read by the machine).
参考:Siemens SINUMERIK 840D sl CNC Software 2.6 SP1 HF4 Installation/Operating Manual, Page 29
Text files can be edited using the SINUMERIK Operate Editor if the text files use the LF character (0aH) or the character string CRLF (0d0aH) as line or end of block identifier. The editor cannot open binary files. ... Files that are newly generated from the SINUMERIK Operate Editor are UTF-8-coded - and have the LF characters as end of block identifier. For UTF-8-coded files, all special characters are correctly displayed. When opening files, the SINUMERIK Operate Editor assumes that the files are UTF-8-coded. If files with another coding are opened, e.g. with Windows page coding, then the special characters are only correctly displayed if the SINUMERIK Operate was changed over to the appropriate system language. This also involves e.g. files that were generated using the HMI-Advanced Editor. When opening with the SINUMERIK Operate Editor, the coding of such files is not changed. There is no automatic conversion into UTF-8-coding. If files we re generated or processed with an external editor (e.g. Notepad under Windows) and not the SINUMERIK Operate Editor, then it should be noted that the file is saved, UTF-8-coded. When using Notepad, and when saving the file as encoding select "UTF-8" in the “Save As” dialog box. If special characters are not being used, then "ANSI" can also be specified as encoding.