none
OpenTextFileWriter transparent header problem in VB.NET

    Question

  • I am writing a simple text file of commands to be picked up by a machine controller using the code below. The very first line of the text file causes an unknown command error in the machine controller. I'm guessing here, but is it possible the operating system and/or the .NET framework is adding a security permissions header and/or an encoder header to the file that is transparent to user of VB.NET? Is it possible to prevent this from happening.

    File =

    My.Computer.FileSystem.OpenTextFileWriter(FileName, False)

    For I = 1 To PathCtr

    File.WriteLine(PathBuild(I))

     

    'Debug.Print(PathBuild(I))

     

    'Debug.Print(Len(PathBuild(I)))

     

    Next I

    File.Close()

     

    Tuesday, November 02, 2010 3:47 PM

Answers

  • Trevor,

    I found the answer on the internet. Problem appeared to be the BOM (Byte Order Mark). It appears you can turn this off for older interfaces by setting the UTF8Encoding to false.

    Dim

     

    utf8EmitBOM As New UTF8Encoding(False)

    File =

    My.Computer.FileSystem.OpenTextFileWriter(FileName, True, utf8EmitBOM)

     

    'File.WriteLine()

     

    For I = 1 To PathCtr

    File.Write(PathBuild(I))

     

    Next I

    File.Close()

     

    Thanks

    Sorry for the trouble

    Monday, November 08, 2010 1:29 PM

All replies

  • This is a Robotics forum, so it's not really the appropriate place to ask this question.

    However, since you are writing a text file, why don't you just open it in Notepad and see what is in there?

    Trevor

     

    Thursday, November 04, 2010 5:39 AM
    Owner
  • Trevor,

    I didn't see anything in NotePad, but I did see characters in Word. Since I can't control the source code of the machine control manufacturer, I'm trying to find out what they are for, and how to get around the problem. I'm guessing that it is either "file permissions" prefixed by the operating system and/or encoding. I copied and pasted the contents of NotePad to the clipboard, read them back into the program that wrote them, and found there are more bytes in the "file" created by OpenTextFileWriter that there was output by the program. I copied and pasted the Word contents to the clipboard, and the extraneous characters were ignored. (I haven't yet found a way to get a handle on the "handle," and I've been playing with "peekchar" without results.)

    Again, I'm just guessing here, but to the casual observer; it would appear that if the extraneous characters needed by the operating system but not the program were "appended" at the end of the text file as opposed to "prefixed", the program would still be "backwards compatible." I called the manufacturer, and they need the "delimeter" of the last character of whatever was prefixed in order to fix the problem. What is happening is the program that interpretes the text file includes the "prefix" into the command line, and the program is therefore unable to recognize the command.

    I didn't mean to intrude on the forum, but I thought you guys may have run into this before. Thank you sincerely for your response.

    Thursday, November 04, 2010 1:21 PM
  • I don't know what your data looks like. Many control characters (usually binary data) will appear invisible in Notepad. You might want to get a Hex Editor. There are plenty of public domain ones.

    Writing out a Text File, as opposed to a binary file, will insert extra characters for line endings so that you always have Carriage Return followed by Linefeed. This is a MS-DOS / Windows thing. Perhaps if you have one or both of these characters in your datastream there are additional characters being inserted and that might not be acceptable to the machine you are trying to control.

    There are no file headers on a Text file.

    No need to apologize for your post. My comment was more about picking a forum where you might find more people to help you. Robotics might not be the best, that's all.

    Trevor

     

    Friday, November 05, 2010 5:26 AM
    Owner
  • Trevor,

    I found the answer on the internet. Problem appeared to be the BOM (Byte Order Mark). It appears you can turn this off for older interfaces by setting the UTF8Encoding to false.

    Dim

     

    utf8EmitBOM As New UTF8Encoding(False)

    File =

    My.Computer.FileSystem.OpenTextFileWriter(FileName, True, utf8EmitBOM)

     

    'File.WriteLine()

     

    For I = 1 To PathCtr

    File.Write(PathBuild(I))

     

    Next I

    File.Close()

     

    Thanks

    Sorry for the trouble

    Monday, November 08, 2010 1:29 PM