Hi,
Here I am again, just learning C# and always wanting to learn the hard
things first. As you might already know from other posts I'm trying to
convert c++ code to C#.
The problem I'm running into now is the creation and handling of an
interrupt. In c++ it is done this way: -
int InitInterruptHandling32(void)
-
{
-
int ret;
-
if (NULL == (threadData.events[INT_EVENT] = CreateEvent(NULL, FALSE,
-
FALSE, NULL)))
-
{
-
printf("-->Error creating interrupt event 0x%X\n", GetLastError());
-
return(-1);
-
}
-
-
ResetEvent(threadData.events[INT_EVENT]);
-
-
if (NULL == (threadData.events[END_EVENT] = CreateEvent(NULL, FALSE,
-
FALSE, NULL)))
-
{
-
printf("-->Error creating thread end event 0x%X\n",
-
GetLastError());
-
CloseHandle(threadData.events[INT_EVENT]);
-
return(-1);
-
}
-
-
if (CANPC_OK != (ret =
-
CANPC_set_interrupt_event(threadData.events[INT_EVENT])))
-
{
-
printf("-->Error set interrupt event 0x%X\n", ret);
-
CloseHandle(threadData.events[INT_EVENT]);
-
CloseHandle(threadData.events[END_EVENT]);
-
return(-1);
-
}
-
-
if (NULL == (intThread = (HANDLE) _beginthreadex(NULL, 0,
-
interruptThread,
-
(void *)
-
&threadData, 0, &tid)))
-
{
-
printf("-->Error create interrupt thread 0x%X\n", GetLastError());
-
INIPC_close_board();
-
CloseHandle(threadData.events[INT_EVENT]);
-
CloseHandle(threadData.events[END_EVENT]);
-
return(-1);
-
}
-
-
InitializeCriticalSection(&CriticalSectionForInterrupt);
-
-
return(0);
-
}
-
And in main there is this code after the previous function: -
do // Inner loop
-
{
-
-
// Loop till user request
-
while (!kbhit())
-
{
-
if (!bInterruptFlag) ReadBusEvent(); //Polling mode chosen -->
-
Poll CANPC_read_ac
-
}// end while
-
-
custom=getch();
-
-
// User request
-
#ifdef WIN32
-
if (bInterruptFlag)
-
EnterCriticalSection(&CriticalSectionForInterrupt);
-
#else
-
if (bInterruptFlag) disable_interrupt();
-
#endif
-
switch (op_mode)
-
{
-
case 'd':
-
ret=UserRequestDynObjBuf(custom);
-
break;
-
-
case 's':
-
ret=UserRequestStatObjBuf(custom);
-
break;
-
-
default:
-
ret=UserRequestFIFO(custom);
-
break;
-
} // End switch
-
-
#ifdef WIN32
-
if (bInterruptFlag)
-
LeaveCriticalSection(&CriticalSectionForInterrupt);
-
#else
-
if (bInterruptFlag) enable_interrupt();
-
#endif
-
-
-
if (ret < 0)
-
{
-
printf("-->User request failed \n");
-
INIPC_close_board();
-
return(-1);
-
}
-
}
-
while ((custom) != 'q' && custom != 'i'); // End inner loop
-
CANPC_reinitialize();
-
#ifdef WIN32
-
if (bInterruptFlag) ExitInterruptHandling32();
-
#else
-
if (bInterruptFlag) ExitInterruptHandling16();
-
#endif
-
}
-
while (custom == 'i'); // End outer loop
-
INIPC_close_board();
-
return(0);
-
}
-
How do I best convert this? Enter critical section, leave it, ...
I have the feeling it is easier in C#, but then again, who am I
I found some stuff regarding Thread.Interrup t Method but don't fully
understand how to implement with an interrupt that comes from hardware
Waiting for help,
kind regards, Jef 2 7062
You should be able to use an unsafe code block for this.
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition
<bv*********@gm ail.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. . Hi,
Here I am again, just learning C# and always wanting to learn the hard things first. As you might already know from other posts I'm trying to convert c++ code to C#.
The problem I'm running into now is the creation and handling of an interrupt. In c++ it is done this way:
- int InitInterruptHandling32(void)
- {
- int ret;
- if (NULL == (threadData.events[INT_EVENT] = CreateEvent(NULL, FALSE,
- FALSE, NULL)))
- {
- printf("-->Error creating interrupt event 0x%X\n", GetLastError());
- return(-1);
- }
- ResetEvent(threadData.events[INT_EVENT]);
- if (NULL == (threadData.events[END_EVENT] = CreateEvent(NULL, FALSE,
- FALSE, NULL)))
- {
- printf("-->Error creating thread end event 0x%X\n",
- GetLastError());
- CloseHandle(threadData.events[INT_EVENT]);
- return(-1);
- }
- if (CANPC_OK != (ret =
- CANPC_set_interrupt_event(threadData.events[INT_EVENT])))
- {
- printf("-->Error set interrupt event 0x%X\n", ret);
- CloseHandle(threadData.events[INT_EVENT]);
- CloseHandle(threadData.events[END_EVENT]);
- return(-1);
- }
- if (NULL == (intThread = (HANDLE) _beginthreadex(NULL, 0,
- interruptThread,
- (void *)
- &threadData, 0, &tid)))
- {
- printf("-->Error create interrupt thread 0x%X\n", GetLastError());
- INIPC_close_board();
- CloseHandle(threadData.events[INT_EVENT]);
- CloseHandle(threadData.events[END_EVENT]);
- return(-1);
- }
- InitializeCriticalSection(&CriticalSectionForInterrupt);
- return(0);
- }
-
And in main there is this code after the previous function: - do // Inner loop
- {
- // Loop till user request
- while (!kbhit())
- {
- if (!bInterruptFlag) ReadBusEvent(); //Polling mode chosen -->
- Poll CANPC_read_ac
- }// end while
- custom=getch();
- // User request
- #ifdef WIN32
- if (bInterruptFlag)
- EnterCriticalSection(&CriticalSectionForInterrupt);
- #else
- if (bInterruptFlag) disable_interrupt();
- #endif
- switch (op_mode)
- {
- case 'd':
- ret=UserRequestDynObjBuf(custom);
- break;
- case 's':
- ret=UserRequestStatObjBuf(custom);
- break;
- default:
- ret=UserRequestFIFO(custom);
- break;
- } // End switch
- #ifdef WIN32
- if (bInterruptFlag)
- LeaveCriticalSection(&CriticalSectionForInterrupt);
- #else
- if (bInterruptFlag) enable_interrupt();
- #endif
- if (ret < 0)
- {
- printf("-->User request failed \n");
- INIPC_close_board();
- return(-1);
- }
- }
- while ((custom) != 'q' && custom != 'i'); // End inner loop
- CANPC_reinitialize();
- #ifdef WIN32
- if (bInterruptFlag) ExitInterruptHandling32();
- #else
- if (bInterruptFlag) ExitInterruptHandling16();
- #endif
- }
- while (custom == 'i'); // End outer loop
- INIPC_close_board();
- return(0);
- }
-
How do I best convert this? Enter critical section, leave it, ... I have the feeling it is easier in C#, but then again, who am I I found some stuff regarding Thread.Interrup t Method but don't fully understand how to implement with an interrupt that comes from hardware
Waiting for help,
kind regards, Jef
<bv*********@gm ail.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. . Hi,
Here I am again, just learning C# and always wanting to learn the hard things first. As you might already know from other posts I'm trying to convert c++ code to C#.
The problem I'm running into now is the creation and handling of an interrupt. In c++ it is done this way:
- int InitInterruptHandling32(void)
- {
- int ret;
- if (NULL == (threadData.events[INT_EVENT] = CreateEvent(NULL, FALSE,
- FALSE, NULL)))
- {
- printf("-->Error creating interrupt event 0x%X\n", GetLastError());
- return(-1);
- }
- ResetEvent(threadData.events[INT_EVENT]);
- if (NULL == (threadData.events[END_EVENT] = CreateEvent(NULL, FALSE,
- FALSE, NULL)))
- {
- printf("-->Error creating thread end event 0x%X\n",
- GetLastError());
- CloseHandle(threadData.events[INT_EVENT]);
- return(-1);
- }
- if (CANPC_OK != (ret =
- CANPC_set_interrupt_event(threadData.events[INT_EVENT])))
- {
- printf("-->Error set interrupt event 0x%X\n", ret);
- CloseHandle(threadData.events[INT_EVENT]);
- CloseHandle(threadData.events[END_EVENT]);
- return(-1);
- }
- if (NULL == (intThread = (HANDLE) _beginthreadex(NULL, 0,
- interruptThread,
- (void *)
- &threadData, 0, &tid)))
- {
- printf("-->Error create interrupt thread 0x%X\n", GetLastError());
- INIPC_close_board();
- CloseHandle(threadData.events[INT_EVENT]);
- CloseHandle(threadData.events[END_EVENT]);
- return(-1);
- }
- InitializeCriticalSection(&CriticalSectionForInterrupt);
- return(0);
- }
-
And in main there is this code after the previous function: - do // Inner loop
- {
- // Loop till user request
- while (!kbhit())
- {
- if (!bInterruptFlag) ReadBusEvent(); //Polling mode chosen -->
- Poll CANPC_read_ac
- }// end while
- custom=getch();
- // User request
- #ifdef WIN32
- if (bInterruptFlag)
- EnterCriticalSection(&CriticalSectionForInterrupt);
- #else
- if (bInterruptFlag) disable_interrupt();
- #endif
- switch (op_mode)
- {
- case 'd':
- ret=UserRequestDynObjBuf(custom);
- break;
- case 's':
- ret=UserRequestStatObjBuf(custom);
- break;
- default:
- ret=UserRequestFIFO(custom);
- break;
- } // End switch
- #ifdef WIN32
- if (bInterruptFlag)
- LeaveCriticalSection(&CriticalSectionForInterrupt);
- #else
- if (bInterruptFlag) enable_interrupt();
- #endif
- if (ret < 0)
- {
- printf("-->User request failed \n");
- INIPC_close_board();
- return(-1);
- }
- }
- while ((custom) != 'q' && custom != 'i'); // End inner loop
- CANPC_reinitialize();
- #ifdef WIN32
- if (bInterruptFlag) ExitInterruptHandling32();
- #else
- if (bInterruptFlag) ExitInterruptHandling16();
- #endif
- }
- while (custom == 'i'); // End outer loop
- INIPC_close_board();
- return(0);
- }
-
How do I best convert this? Enter critical section, leave it, ... I have the feeling it is easier in C#, but then again, who am I I found some stuff regarding Thread.Interrup t Method but don't fully understand how to implement with an interrupt that comes from hardware
Waiting for help,
kind regards, Jef
Take a look at the System.Threadin g namespace, this include all the stuff
you need to convert this to C#.
For instance Critical sections can be implemented using Monitor.Enter /
Monitor.exit, CreateEvent see WaitHandle and it's derived classes like
ManualResetEven t.
getch(); equivalent is available in v2.0 of the System.Console class, when
running v1.x you'll have to PInvoke some conio functions (like __getch).
Some questions remain however:
- what are you doing in : ReadBusEvent() ??
- why do you want to convert this to C#?
Willy. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jane Austine |
last post by:
As far as I know python's threading module models after Java's.
However, I can't find something equivalent to Java's interrupt and
isInterrupted methods, along with InterruptedException.
"somethread.interrupt()" will wake somethread up when it's in
sleeping/waiting state.
Is there any way of doing this with python's thread? I suppose thread
interrupt is a very primitive functionality for stopping a blocked
thread.
|
by: Marco |
last post by:
Hallo,
I have made a microcontroller with keyboard (16 key).
I have a function to handle interrupt that comes from keyboard when a key is
pressed.
I should make a C software (not graphic) with a menu.
I thought to make into main.c a cicle like this:
while (1)
|
by: LordHog |
last post by:
Hello all,
I have a little application that will be used for test environment
that utilizes the CAN Messaging. The application will capture and then
decode the CAN message that are received. In the API reference material
the device will generate an interrupt which the user much provide an
interrupt service routine with the entry pointed at the interrupt 0x16
vector ( Address = 0x0083 ). Is it possible to write an interrupt
service...
|
by: tomhr |
last post by:
I have a Borland Turbo C++ compiler (though I never use the "plus-plus"
part), copyright 1990. I use this compiler to write simple programs,
one of which I am quite dependent on.
A month ago, my parallel-port-output printer died, and I got a Samsung
printer that takes info from the USB port. Every time I go into DOS
mode and try to send something to that printer, whether from a command
line ("dir>prn"), or from one of my programs, I get...
|
by: Hartmut |
last post by:
Hi guys out there...,
I am not shure if this is the right forum for my Question.
Have a problem using my own Keyboard interrupt handler. The handler
works
fine as long as i do not press keys like pause, arrow keys etc. My
system
returns with a stack overflow.
Is there something i have overseen in my keyboard Interrupt Service
| |
by: =?Utf-8?B?QnJ1Y2UgSFM=?= |
last post by:
I'm using VS2005 Winforms. I want a method to allow the user to be able to
interrupt an SQL query if he decides he doesn't want to wait for it any
longer.
I've used IAsyncResult to open an async connection that runs an
ExecuteNonQuery, but this method doesn't allow interruption
(EndExecuteNonQuery gets blocked until the execute finishes), and ideally I'd
like to interrupt a Query rather than a NonQuery.
It seems to me this is a...
|
by: mani |
last post by:
Hi all.
Is their any function which can associate the irqno with interrupt
handller.
and function should not be the kernal function. and more interrupt
related
function like enable irq and disable irq....
(example in Vxworks IntConnect is for that)
|
by: simon.tran.ca |
last post by:
Good Morning folks,
Our DB2 servers currently complains about the below error, "User
interrupt detected". I've been researching for quite long and I
haven't got any good explanation nor solution on this.
Could someone give me a hint please?
Thanks in advance
|
by: BlueBird |
last post by:
Hi,
I have a program with a master thread and several slave threads.
Whenever an exception occurs, in the master thread or in one of the
slave threads, I would like to interrupt all the threads and the main
program. Threading API does not seem to provide a way to stop a
thread, is there anyway to achieve that ?
The closest thing I found is thread.interrupt_main() but it's far from
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |