Windows programming

Moderators: None (Apply to moderate this forum)
Number of threads: 3711
Number of posts: 9173

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Win95-programming on serial port Posted by HubiF on 27 Nov 2003 at 4:38 PM
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
Report
Re: Win95-programming on serial port Posted by jtcoelho on 2 Dec 2003 at 10:58 AM
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 \r rather than \n */
strcpy(str, "at\r");
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
:

Report
Re: Win95-programming on serial port Posted by HubiF on 4 Dec 2003 at 9:24 AM
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



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.