Pages: [1]   Go Down
Author Topic: Arduino logs data to a hard drive  (Read 700 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi! I have attached a simple program and a source code for data logging onto the hard drive. Should one doesn't have a micro SD shield, this might be an alternative option currently. The program could be started either through start.bat file or typing in ReadCOM.exe com4 (or com400 whatsoever). The baud rate equals 9600 bps.
Well, this is a quite simple sketch, just to try out. I have compiled the program by means of MSVS 2008 as a console application with precompiled headers.
Feel free to develop the source further and enjoy!
Regards...

// ReadCOM.cpp : Defines the entry point for the console application.

#include "stdafx.h"
#include "windows.h"

int _tmain(int argc, _TCHAR* argv[]) {
DCB dcb;
HANDLE hCom;
BOOL fSuccess;
COMMTIMEOUTS CommTimeouts;
DWORD dwBytesTransferred;
//BYTE Byte[1];
char Byte[1];
Byte[0] = '0';
//int TimePakIn = 0;
FILE *filehandler;

    LPCWSTR pcCommPort = argv[1];
    hCom = CreateFile(pcCommPort, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);

    if (hCom == INVALID_HANDLE_VALUE) {
       printf("Cannot open serial port first!\n"); getc(stdin);
       return 1;
    }//if

    //Build on the current configuration, and skip setting the size of the input and output buffers with SetupComm.
    fSuccess = GetCommState(hCom, &dcb);
    if (!fSuccess) {
       printf("Cannot open serial port second!\n"); getc(stdin);
       return 1;
    }//if

    //Fill in DCB: 9600 bps, 8 data bits, no parity, and 1 stop bit.
    dcb.BaudRate = CBR_9600;  //CBR_115200;//set the baud rate
    dcb.ByteSize = 8;         //data size, xmit, and rcv
    dcb.Parity   = NOPARITY;  //no parity bit
    dcb.StopBits = ONESTOPBIT;//one stop bit

    fSuccess = SetCommState(hCom, &dcb);

    if (!fSuccess) {
       printf("Cannot open serial port third!\n"); getc(stdin);
       return 1;
    }//if

    CommTimeouts.ReadIntervalTimeout         = 100;
    CommTimeouts.ReadTotalTimeoutMultiplier  = 0;
    CommTimeouts.ReadTotalTimeoutConstant    = 4000;
    CommTimeouts.WriteTotalTimeoutConstant   = 0;
    CommTimeouts.WriteTotalTimeoutMultiplier = 0;

    fSuccess = SetCommTimeouts(hCom, &CommTimeouts);

    //Start sampling
    WriteFile(hCom, "s", 1, &dwBytesTransferred, 0);

    if((filehandler = fopen("dataout.txt", "w+")) == NULL) printf( "The file 'dataout.txt' was not opened\n" );
    else printf("The file 'dataout.txt' was opened\n");

    for (;smiley-wink {
        //TimePakIn = GetTickCount();
        ReadFile(hCom, Byte, 1, &dwBytesTransferred, 0);
        printf("%c", Byte[0]);
        fprintf(filehandler, "%c", Byte[0]);
    }

    //Unreachable code unless for loop is finite
    fclose(filehandler);
    //Stop sampling
    WriteFile(hCom, "e", 1, &dwBytesTransferred, 0);

    return 0;

}

* Pla.zip (17.17 KB - downloaded 6 times.)
« Last Edit: August 12, 2012, 04:54:11 am by samolet4e » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 46042
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That for loop near the bottom appears to be non-standard syntax. Is that something that Microsoft supports?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That was just not very funny. Just replace the smiley with another semicolon and right parenthesis like this: for(;;) {}
In order to get data logged properly, you must provide output by means of Serial.write(str).
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 46042
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Just replace the smiley with another semicolon and right parenthesis like this: for(;smiley-wink {}
As opposed to you posting code properly? I don't think so.
Logged

Pages: [1]   Go Up
Jump to: