Win95-programming on serial port - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Win95-programming on serial port

Hello & Greetz from Germany!

At first, please, excuse my surely horrible English, thanks.

I'm quite a Newbie on programming in C++ using the Borland C++-Builder (Ver. 4) under Win95 and I want to remake a project which I made with TurboPascal some time ago...

I've a selfmade sensor on a serial port, that gives impulses in a frequency of 15 to 750 Hz to the RingIndicator (register offset+6, bit 6). It's a very simple sensor, just an oscillator with an OP, so, there's no built-in interface or a controller using the known protocols on data-I/O, like Kermit, Xmodem or things like that. In fact, there is also no baudrate, parity or word-length to use. The supply-voltage is given by DTR and RTS (offset+4, bit 0 + 1).

To the program: I want to count the incoming impulses on the RS232 and evaluate these every 5 or 6 seconds. In my Pascal-Program, under pure MS-DOS it works more then fine, in a fantastic way, but it's only monotasking. Now I try to realize it in a similar way under Win95. It's no problem to take acces on the ports by using DLPortIO (freeware: http://diskdude.cjb.net/), but it's no good to use while-loops, like the way I tried; the whole OS is busy, nothing works in a correct way and even the impulse-counting has errors. I'm at the beginning, I don't use any threads, ignore any interrupts, and some questions to other forums just gave back, that it's very heavy to realize satisfactorily.

But I guess, it's possibly! It should work like the mouse, in the background, without taking all performance of the OS. But how? Should I write a thread? Should I use an interrupt? Why using the total performance of the CPU? I only want to register the impulses and query them every some seconds. Must I dive into assembler? Or could I solve all my problems by programming the UART of the RS232 to use it's interrupt-possibility? Do I use the wrong component? Is there a shell by Windows on the hardware access?

How would YOU write a mouse-application without using the standard mouse programs given by microsoft?

Many questions, any answers?

I hope so and I say THANK YOU to everybody making her/his thoughts on my questions!

Nice greetings...

Hubi

Comments

  • jtcoelhojtcoelho Posts: 44Member
    Hi
    don't know if this will help at all but there are some functions you can look at for the serial port. i had to do some serial port communictions and used these functions.
    Here it is:
    CreateFile("COM3",
    GENERIC_READ|GENERIC_WRITE,
    0, 0, OPEN_EXISTING,
    FILE_ATTRIBUTE_NORMAL, 0);
    To get the current settings of the COMM port
    GetCommState(comHandle, &dcb);
    To modify the baud rate, etc.
    dcb.BaudRate = 2400;
    dcb.ByteSize = 8;
    dcb.Parity = NOPARITY;
    dcb.StopBits = ONESTOPBIT;

    To apply the new comm port settings
    success = SetCommState(comHandle, &dcb);

    To change the ReadIntervalTimeout so that
    ReadFile will return immediately. See help file

    timeouts.ReadIntervalTimeout = MAXDWORD;
    timeouts.ReadTotalTimeoutMultiplier = 0;
    timeouts.ReadTotalTimeoutConstant = 0;
    timeouts.WriteTotalTimeoutMultiplier = 0;
    timeouts.WriteTotalTimeoutConstant = 0;
    SetCommTimeouts( comHandle, &timeouts );
    /* Set the Data Terminal Ready line */
    EscapeCommFunction(comHandle, SETDTR);

    /* Send an "at" command to the modem */
    /* Be sure to use
    rather than
    */
    strcpy(str, "at
    ");
    success = WriteFile(comHandle, str, strlen(str),
    &numWrite, 0);
    And so on. I hope this did not confuse more than clarify.
    : Hello & Greetz from Germany!
    :
    : At first, please, excuse my surely horrible English, thanks.
    :
    : I'm quite a Newbie on programming in C++ using the Borland C++-Builder (Ver. 4) under Win95 and I want to remake a project which I made with TurboPascal some time ago...
    :
    : I've a selfmade sensor on a serial port, that gives impulses in a frequency of 15 to 750 Hz to the RingIndicator (register offset+6, bit 6). It's a very simple sensor, just an oscillator with an OP, so, there's no built-in interface or a controller using the known protocols on data-I/O, like Kermit, Xmodem or things like that. In fact, there is also no baudrate, parity or word-length to use. The supply-voltage is given by DTR and RTS (offset+4, bit 0 + 1).
    :
    : To the program: I want to count the incoming impulses on the RS232 and evaluate these every 5 or 6 seconds. In my Pascal-Program, under pure MS-DOS it works more then fine, in a fantastic way, but it's only monotasking. Now I try to realize it in a similar way under Win95. It's no problem to take acces on the ports by using DLPortIO (freeware: http://diskdude.cjb.net/), but it's no good to use while-loops, like the way I tried; the whole OS is busy, nothing works in a correct way and even the impulse-counting has errors. I'm at the beginning, I don't use any threads, ignore any interrupts, and some questions to other forums just gave back, that it's very heavy to realize satisfactorily.
    :
    : But I guess, it's possibly! It should work like the mouse, in the background, without taking all performance of the OS. But how? Should I write a thread? Should I use an interrupt? Why using the total performance of the CPU? I only want to register the impulses and query them every some seconds. Must I dive into assembler? Or could I solve all my problems by programming the UART of the RS232 to use it's interrupt-possibility? Do I use the wrong component? Is there a shell by Windows on the hardware access?
    :
    : How would YOU write a mouse-application without using the standard mouse programs given by microsoft?
    :
    : Many questions, any answers?
    :
    : I hope so and I say THANK YOU to everybody making her/his thoughts on my questions!
    :
    : Nice greetings...
    :
    : Hubi
    :

  • HubiFHubiF Posts: 9Member
    Thank You!

    I've heard about this way programming the serial port by using MS-Functions. Perhaps it'll be possible to realize my project by going this way, I'll try it!

    Have a nice day!

    Hubi
Sign In or Register to comment.