hyperterminal to text file


hey guys.
i have code recieved chars hyperterminal convert string , write on text file
when use monitor instead of hyperterminal work when switch hyper dosent work
i can not find problem in code
i happy if help
thanks in advance.

code: [select]
#include <spi.h>
#include <sd.h>
char indata;
string datastring;
file datafile();
void setup()
{
  serial.begin(9600);
  while (!serial.available()); // wait serial port connect. needed native usb port only
  if (!sd.begin(4)) // see if card present , can initialized.
  {
    serial.println("initialization failed!");
    while (1); // don't more.
  }
}

void loop()
{
  if (serial.available())
  {
    while (serial.available() > 0)
    {
      pinmode(3,high);
      datastring = "";
      indata = serial.read();
      datastring += string(indata);
      /*if (indata == '\n')
        {
        datastring += "\n";
        }*/
      // open file. note 1 file can open @ time,
      // have close 1 before opening another.
      file datafile = sd.open("datalog.txt", file_write);

      // if file available, write it:
      if (datafile)
      {
        datafile.print(datastring);
        datafile.close();
        // print serial port too:
        serial.print(datastring);
      }
      // if file isn't open, pop error:
      else
      {
        serial.println("error opening datalog.txt");
      }
    }
  }
}


serial monitor sends data when hit "send".
hyperterm sends data 1 character @ time.

robin2's serial handling basics tutorial should solve problem


Arduino Forum > Using Arduino > Programming Questions > hyperterminal to text file


arduino

Comments

Popular posts from this blog

Error compiling for board Arduino/Genuino Uno.

Installation database is corrupt

esp8266 (nodemcu 0.9) client.write très lent ???