3

I'm using a macro to create a CNC program.
To create the ".spf" file the machine is using I use:

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

When I try to open the program on the machine I get a error "Cannot open binary files".
But If I manually copy the content from the "m2_path"-file into another one and then try to open it, I don't get the error message.

Is there something wrong with the formatting of the text file?

Machine is using SINUMERIK 840d sl.

Thanks in advance
Regards

EDIT:
Thanks to @ashleedawg

ashleedawg
  • 20,365
  • 9
  • 72
  • 105
rosi97
  • 243
  • 3
  • 18
  • The first thing that's missing is double quotes around the path. And, I gather the machine is expect a text file? – ashleedawg Nov 18 '17 at 19:03
  • Fixed that. Yes, with the ending .spf. (file format) – rosi97 Nov 18 '17 at 19:26
  • Did that fix the problem? If not, are you able to post a sample file generated by your code? – ashleedawg Nov 18 '17 at 19:30
  • 1
    Have you seen page 29 of [this document](https://cache.industry.siemens.com/dl/files/881/49913881/att_62227/v1/siemense_operate_26_sp1_hf4.pdf)? – ashleedawg Nov 18 '17 at 19:43
  • This helped me, thanks! – rosi97 Nov 18 '17 at 20:07
  • `Is there something wrong with the formatting of the text file?` the answer is yes. but it is impossible to say what that is. you did not post enough information. .... can you post the first few likes fro a working spf file and a few lines fro your spf file? – jsotola Nov 18 '17 at 21:29
  • did you get it figured out? – ashleedawg Nov 19 '17 at 00:21
  • 1
    Please either you or @ashleedawg, post the answer as an answer and remove it from the question. Is it depending on writing the text with an ANSI encoding when UTF-8 is required (which does work for characters in the [C0 Controls and Basic Latin](http://www.unicode.org/charts/nameslist/index.html) block only)? – Tom Blodget Nov 19 '17 at 01:22
  • @Tom -- _done_. – ashleedawg Nov 19 '17 at 07:44
  • 1
    @rosi97 -- if that's working for you now, feel free to "accept" my answer (with the checkmark below on the left), which I moved from your Edit as per Tom's request. Good luck with the CNC! (Coincidentally, my uncle worked on the first PLC's & CNC's for Siemens in Berlin about 50 years ago.) – ashleedawg Nov 19 '17 at 07:50

1 Answers1

3

Good to hear you had success with the change:

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).

Reference: 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.

ashleedawg
  • 20,365
  • 9
  • 72
  • 105