ublo

bogdanel's (micro)blog

updates from RSS

  • 12:50:54 pm on January 28, 2012 | 0 | # |
    Tags:

    căutam ceva pe harddisk-ul cu arhive și am dat de un document la care am lucrat acum un an și ceva, având la bază structura cursului conf. dr. Gabriel Gâjâilă de la USAMV însă cu conținutul compilat din mai multe cursuri open (dintre care menționez Cellular and Molecular Immunology din MIT OCW și Undergraduate Immunology al lui Mike Clark de la Universitatea din Cambridge).

    cursul nu l-am terminat deoarece și-a atins scopul. în plus, pentru cei interesați de preluarea suportului și folosirea lui pentru educație (și aici mă refer la personalul didactic) pot pune la dispoziție în schimbul unei adrese de email, documentul în format editabil (Open Office Impress).

     
  • 10:35:42 am on January 26, 2012 | 2 | # |
    Tags:

    n-am fost niciodată vocal în legătură cu industria online din românia, deși am avut partea mea de experiențe în domeniu. știu mizeriile care se întâmplă, știu cum se fac banii, știu ce înseamnă rebate și cât de găunoasă e o regie. știu că dacă ți-ai ratat cariera una dintre cele mai ușoare soluții e să te transformi în consultant new media. am văzut pseudo-vedete venind și plecând.

    ce mă enervează e că jegul a acoperit ultimul colțișor care spunea lucrurilor pe nume, zoso.ro/update. mie personal o să-mi lipsească. deja renunțasem la ziare online și site-uri de știri în favoarea lui. vali, sper să revi asupra deciziei și să ții minte comentariul meu. poate ar trebui să închizi blogul pentru gușteri și să-l păstrezi doar pentru cei care sunt dispuși să plătească.

     
  • 12:42:01 am on January 8, 2012 | 0 | # |
    Tags:

    jack white & black milk – royal mega

     
  • 11:20:33 pm on January 7, 2012 | 0 | # |
    Tags:

    Should we expect a new revolution in physics, this time with logic arguments and not for justifying huge funds with flipping coins and counting particles (link)? Here’s a recent paper describing how gravity can be considered a consequence of the information, not as a fundamental force. In my humble opinion, this idea has the necessary beauty to kick us beyond Einstein’s general relativity.
    Erik P. Verlinde – On the Origins of Gravity and the Laws of Newton
    Multiwavelength image of M81 galaxy (courtesy of NASA Images)
    (image courtesy: nasaimages.org)

     
  • 03:30:56 pm on December 20, 2011 | 0 | # |
    Tags:

    yesterday, i’ve posted my wrapper library for the windows COM port with the promise of posting the actual C program that uses it. to compile it you need mingw (see here my tutorial on how to get it up and running). the program is simple and writes in the text.txt file whatever it receives on the serial interface, but no more than MAXLINES lines (in this case, 10 lines). you need to save the previous code as “serial.h” in the same directory as the code below. then, compile it and that’s it! =)

    ask whatever questions here, and i will answer.

    #include <stdio.h>
    #include <windows.h>
    #include "serial.h"
    // the number of lines read from the serial interface.
    // good for data acquisition for a specified amount of time.
    #define MAXLINES 10
    
    int main (int argc, int ** argv) {
        HANDLE comPort;
        FILE * f;
        char buffer[32];
        unsigned short int readbits = 0;
        unsigned long int lines = 0;
        unsigned short int c;
    
        // my COM port is COM15. be sure to change it accordingly
        if ((comPort = openSerialConsole("\\\\.\\COM15")) == (void *) NULL) {
            printf ("Error: COM Port!\n");
            return 1;
            }
    
        // open the file "text.txt". change it for a different file
        f = fopen ("test.txt", "w+");
    
        // read online MAXLINES lines
        while (lines < MAXLINES) {
            // readbits is the number of bytes read from the COM port
            while ((readbits = readFromSerialConsole(comPort, buffer, 32)) != 0) {
                // a good thing to check that the readbits+1 character marks the end
                // of the string. saves you from "Segmentation fault!" errors
                buffer[readbits] = 0;
    
                // check buffer for ENDL character
                for (c = 0; c<readbits; c++)
                    if (buffer[c] == '\n') {
                        lines++;
                        if (lines == MAXLINES) buffer[c] = 0;
                        }
    
                // output to the standard IO, and
                printf("%s", buffer);
                // to the file
                fprintf(f, "%s", buffer);
                }
            }
    
        // close the file handle
        fclose (f);
    
        // close the COM port
        closeSerialConsole(comPort);
    
        return 0;
        }

     
  • 06:00:46 pm on December 19, 2011 | 1 | # |
    Tags:

    searching for a way to read the serial port in windows using C (usually i do my programming under linux), i found a cute little wrapper for the serial port here. i don’t like .NET that’s why i’ve wanted a pure C implementation. here’s the code (most of it from the source). read the comments as it saved me a lot of problems accessing higher COM ports. remember to escape the characters in the string!

    HANDLE openSerialConsole (LPCSTR p) {
    // LPCSTR p is a string containing the name of the device
    // in Windows namespace, the safest way to access the COM ports
    // is to use the \\.\COMxx syntax. remember, p is a string
    // and \ escapes characters so p should really be "\\\\.\\COMxx"
        HANDLE h;
        DCB params = {0};
        COMMTIMEOUTS timeouts = {0};
    
        h = CreateFile ( p,
            GENERIC_READ | GENERIC_WRITE, // the way we want to interact with the COM port
            0, // not the wisest way to open the device as it takes exclusive control over
            NULL, // no security attributes, meaning no child process access
            OPEN_EXISTING, // only if we have a COM port
            0, // some things i didn't understood completely
            NULL);
        if (h == INVALID_HANDLE_VALUE) {
            printf("Error: Could not create handle!\n");
            return (void *) NULL;
            }
    
        params.DCBlength = sizeof(params);
        if (!GetCommState(h, &params)) {
            printf("Error: Setting COM State!\n");
            CloseHandle (h);
            return (void *) NULL;
            }
    
        // 9600 bauds, with a 8N1 format
        params.BaudRate=CBR_9600;
        params.ByteSize=8;
        params.Parity=NOPARITY;
        params.StopBits=ONESTOPBIT;
        if (!SetCommState(h, &params)) {
            printf("Error: Setting BAUD!\n");
            CloseHandle (h);
            return (void *) NULL;
            }
    
        // timeouts, avoid hanging
        timeouts.ReadIntervalTimeout=50;
        timeouts.ReadTotalTimeoutConstant=50;
        timeouts.ReadTotalTimeoutMultiplier=10;
        timeouts.WriteTotalTimeoutConstant=50;
        timeouts.WriteTotalTimeoutMultiplier=10;
        if (!SetCommTimeouts(h, &timeouts)) {
            printf("Error: Setting timeouts!\n");
            CloseHandle (h);
            return (void *) NULL;
            }
    
        return h;
        }
    
    unsigned long int readFromSerialConsole ( HANDLE h, char * buffer, int size ) {
        unsigned long int bytes = 0;
        COMSTAT status;
        unsigned long int errors;
    
        ClearCommError (h, &errors, &status);
    
        if (status.cbInQue > 0) {
            size = status.cbInQue > size ? size : status.cbInQue;
            if (ReadFile(h, buffer, size, &bytes, NULL) && bytes != 0)
                return bytes;
            }
        return bytes;
        }
    
    unsigned long int writeToSerialConsole(HANDLE h, char * buffer, int size) {
        unsigned long int bytes = 0;
        if (!WriteFile(h, buffer, size, &bytes, NULL));
        return bytes;
        }
    
    void closeSerialConsole (HANDLE h) {
        CloseHandle (h);
        }

     
  • 01:31:41 am on December 18, 2011 | 0 | # |
    Tags:

    ken hensley – lady in black

     
  • 11:28:59 pm on December 17, 2011 | 1 | # |
    Tags:

    first time i heard about mingw was from florin manea, then a lecturer at the university of bucharest, faculty of mathematics. i didn’t pay to much attention to it as i was a dedicated gentoo user. time has passed, and the table turned, me being the one to teach a small course on physical computing at the physics faculty. student’s have various backgrounds but none comes from a computer science oriented faculty, so i had to show them how to connect the μC serial output to their windows environment.

    (More …)

     
Next Page »