Copyright © https://mongoose-os.com

Mongoose OS Forum

frame
ATTENTION! This forum has moved to:

https://community.mongoose-os.com

Do not post any new messages.

Reading from File using mjs giving \xfa\xfa\xfa\xfa\xfa\xfa\xfa\xfa\xfa\xfa] for first 10 characters

edited November 2017 in Mongoose OS

Hello All,

I am using mjs to read from a file using 1.20.1, but it also seems to occur in 1.19.6. I have a file called flush_30.json. I decided to write manually [1,2,3,4,5] and I get the following when trying to retrieve it's contents using the File.read(fileName) method, \xfa\xfa\xfa\xfa\xfa\xfa\xfa\xfa\xfa\xfa]. It seems to be the first 10 characters that the \xfa happens with. I reproduced the issue on multiple devices. Any possible reason for this or solution? I can provide more details if needed. Anyone else run into a similar issue? Thanks!

Comments

  • SergeySergey Dublin, Ireland

    show your code for writing and for reading, please

  • edited November 2017

    Sorry Sergey. More detail is provided below!

    So I did some further debugging and this is what is happening (with code). I think it has to do with a scope issue or File closing issue because of closing the device prematurely while writing the file in the first place, but I need to do further debugging over the next few days to validate and I will report back.

    When writing, I was writing inside a timer and I realized if it took more than 200 milliseconds to write, it was causing issues. I realized I needed to fix this and so I added a flag in newer code but this was the original code.

    Timer.set(200, true, function() {
      if (waitACK === 0) {
       File.write(JSON.stringify(myString), "flush_30.json", "w");
       shutdown(); //custom method
      }
    }
    

    The device would sometimes cause read issues with the first block of code, the second block seemed ok with all the testing I did.

    //The code for writing below.
    //this block of code failed some of the time
    execute();
    
    function execute(){
      let file1String = File.read("flush_30.json");
      //will check to see if string is fine over here. 
      //returns null if no file found 
      if(file1String !== null){
        //the string was bad in here. 
        let file1StringJSON = JSON.parse(file1String);
      }
    
    }
    

    But if I do something like read within the scope, it worked with the same file that I was having trouble reading before.

    //this block of code succeeded
    execute();
    
    function execute(){
      let file1String = File.read("flush_30.json");
      //returns null if no file found
      if(file1String !== null){
       //the string worked in here
        let file1StringJSON = JSON.parse(File.read("flush_30.json")); 
      }
    
    }
    
Sign In or Register to comment.