Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have an issue. I have to detect a slow TTL sign and measure the time between to signs. I do not want to build a circuit for this. My idea would be to connect the source of the sign to a COM port (USB/RS232). Change on any of the control line (DTR, RTS) causes an interrupt. Hooking the IRQ I can ask for the system time (in milli sec). Every second call I can tell the time between two signals. I have couple of problems with this plan:

1. Hook the IRQ become difficult. Back to DOS area it was easy. So I need help how to do this. I've downloaded Visual Studio Express 2010. I would be really grateful for a source code, that I can build too.

2. I am not sure if the whole concept is good. Can someone tell me if this could work? Any better idea that requires no PCB building to detect sign and measure then is welcome.

Thanks,
Akos
Posted

1 solution

This is not how Win32 works. There is no such thing as direct access to interrupts. The development paradigm has little to do with old DOS time. No, it's not even a Question of good or bad concept — it does not go along with Win32 paradigm.

Your further steps depends on what you want to achieve. Very basically, you need to use reading and/or writing thread for you serial port and use a blocking call reading a serial stream. Your thread is truly blocked at such call: it is switched off by OS and not scheduled back to execution (using zero CPU time just as in interrupt-driven programming) until awaken by data ready state in the serial channel (or terminated). Next statement after you got some data could send a message to other thread if you want.

This CodeProject article will give you pretty good idea: Serial library for C++[^].

—SA
 
Share this answer
 
v3
Comments
Espen Harlinn 18-Apr-11 18:11pm    
Nice reply, my 5
Sergey Alexandrovich Kryukov 18-Apr-11 22:30pm    
Thank you, Espen.
--SA
Akos Szabo 19-Apr-11 3:30am    
Thanks for the advise. I've checked the File based serial programing. I just wonder if the idea is good at all? I mean switching a TTL H (5V) to any of the pin (CTS, DSR, RI, DCD) on the serial port that may cause an IRQ and catch it is a good approach at all?
What do you think?
Sergey Alexandrovich Kryukov 19-Apr-11 3:37am    
Are you serious?! I would not do it :-)
Interrupt it interrupt. Are you familiar with CPU ring-based security? Interrupt is in the inner ring (last time I was reading about Windows use of Intel architecture, only two rings were used). The only thing you can do it replacing the serial port kernel-mode driver with your own version written for kernel mode using DDK. (To be honest, even though I programmed CPU on a very low system level, I never did it.)
--SA
Akos Szabo 21-Apr-11 13:15pm    
Well, in the '90s among other hardware stuffs I developed a video digitizer and a data register too. For these I implemented many low level things in Assembly, like DMA and interrupt redirection. It was fine. Since then I haven't been dealing with such HW development. And I just wonder how the OS hide and protect the HW from the users nowadays. And how complicated to do anything. I have to move to PIC if I want to do any HW related development. Earlier it was a few command only, like get the interrupt vector, save it, replace it with the address of my routine. That was all.
Anyway, as a plan B according to my problem I've developed a small extension to a K8055 card and solved the issue. Using a PIC would be the perfect solution, but now I have no time to learn everything from the beginning.
So thanks again for the help.
Akos

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900