Announcement

Collapse
No announcement yet.

Web Server

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Web Server

    Hi

    I made the following function to create a file. I read serial data and i put them in a *.json (special format) because i need to read the data with a javascript.
    I open my html program and i try to read the data. The data are in the file *.json. I can not read them but the file seems good. After that, i open the file. I make nothing, I just save the file without changes and i read one more time the file with the javascript and it works very good.

    Could you please guide me, i dont know what is that. Is something wrong in my function sampleDataRead()? I made the same function in Visual and there is not problems with the file. I made that with Paradigm and it doesn't work, only if i open and save the file.

    Thanks a lot.



    static void sampleDataRead()
    {

    const int readDelayMs = 800; /* milliseconds*/
    FILE * pFile;
    char *buffer1;
    char *buffer2;
    int rC;

    buffer1 = Malloc(10,"test1");
    buffer2 = Malloc(10,"test2");

    SerialOpen(0);

    pFile = fopen("http/datoNIR.json","a");
    fwrite("{label: 'NIR',data: [[", 22, 1, pFile);

    for(rC=1;rC<20;rC++) {

    SerialRead(0,(uint8_t *)buffer1,5, readDelayMs, TRUE);


    if (pFile!=NULL)
    {

    sprintf(buffer2,"%i", rC);
    fwrite(buffer2, 2, 1, pFile);
    fwrite(",", 1, 1, pFile);
    fwrite(buffer1, 6, 1, pFile);
    fwrite("],[", 3, 1, pFile);
    }
    }

    SerialRead(0, (uint8_t *)buffer1,5, readDelayMs, TRUE);
    sprintf(buffer2, "%i", rC);
    fwrite("20", 2, 1, pFile);
    fwrite(",",1,1, pFile);
    fwrite(buffer1, 6, 1, pFile);
    fwrite("]]}", 4,1, pFile);

    fclose (pFile);

    Free(buffer2);
    Free(buffer1);

    SerialClose(0);

    }

  • #2
    Where are all of these programs? Is all of this running on the Lantronix, or is the file getting read by a program on another platform?

    Comment


    • #3
      Probably you should check the return value of SerialOpen() and SerialRead() first, it might give you some lead.

      -James

      Comment


      • #4
        Thanks for the answer. Yes, it is all the Code that i have in the Lantronix. I will look the return value.
        But now i must development a Tunneling aplication with the Lantronix.

        Thanks a lot.

        Comment


        • #5
          I experienced something similar when a file was not getting closed properly, but you don't have any path of program execution that would skip that command, so I don't think that's it.

          Just to make sure I have the sequence correct:
          1. Create file with function on Lantronix
          2. Open file with webbrowser?? (File is empty??)
          3. Close connection with web browser
          4. Open again with browser and save to PC (file is ok)

          Comment

          Working...
          X