Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Disable and Enable COM1 port?

com1 serial communication

This topic has been archived. This means that you cannot reply to this topic.
13 replies to this topic

#1 Hamed

Hamed

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 413 posts

Posted 10 May 2013 - 02:46 AM

Hello,

I want to Disable and Enable COM1 of my computer by using C#.

How can I do this job?


Edited by Hamed, 10 May 2013 - 06:42 AM.


#2 Luthfi

Luthfi

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1320 posts

Posted 10 May 2013 - 03:25 AM

You need to dig into system's call for this. I believe the best solution would be to use SetupApi library (those DeviceIoControl) or perhaps using WMI. To help you for this job, there is a utility from microsoft, DevCon, which comes with Windows DDK along with its source codes. DevCon allows you to do what Device Manager can do through command lines. Go study its source code, since you can not redistribute DevCon by itself.



#3 Hamed

Hamed

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 413 posts

Posted 10 July 2013 - 05:28 AM

DevCon helped thanks.

Now I need returned message:

DevCon will return an error level for use in scripts:

"0" indicates a success.
"1" indicates that a restart is required.
"2" indicates a failure.
"3" indicates a syntax error.

How can I run devcon on C# application



#4 Hamed

Hamed

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 413 posts

Posted 11 July 2013 - 04:27 AM

Any help?



#5 BlackRabbit

BlackRabbit

    CodeCall Legend

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3871 posts

Posted 11 July 2013 - 07:27 PM

Hello Hamed,

 

What you nee to use is the SetupDI API which allows your program windows hardware manager capabilities.

 

Else, you could take a look to this Hardware-Helper library .

 

In any case, your hardware management capability will be restricted to the program-runing's user permissions.



#6 Hamed

Hamed

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 413 posts

Posted 11 July 2013 - 10:54 PM

Hello,

I use DevCon and it works fine for me.

Now I want to get result of running DevCon.

 

Hello Hamed,

 

What you nee to use is the SetupDI API which allows your program windows hardware manager capabilities.

 

Else, you could take a look to this Hardware-Helper library .

 

In any case, your hardware management capability will be restricted to the program-runing's user permissions.



#7 Luthfi

Luthfi

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1320 posts

Posted 12 July 2013 - 04:23 AM

You can execute DevCon like you would with other console program. If you never done that before, try using Windows api ShellExecute to run DevCon with proper parameters when needed.

 

However, like I said earlier, DevCon is not redistributable. I recommend to dig into its source code and apply to your own project.



#8 Hamed

Hamed

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 413 posts

Posted 12 July 2013 - 05:46 AM

I use this command in bath file:

C:\devcon.exe disable *PNP05*

It works fine, Also I can use System.Diagnostics.Process.Start to run DevCon but I don't know how to get result of running devcon.



#9 Tonchi

Tonchi

    Helping the world with programming

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1249 posts

Posted 12 July 2013 - 06:48 AM

http://stackoverflow...lt-line-by-line

 

read this. it would help you.


Microsoft Student Partner, Microsoft Certified Professional


#10 Hamed

Hamed

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 413 posts

Posted 12 July 2013 - 10:30 AM

Look when I run a function I get a value as result DevCon main function return an int value just I need this value.



#11 Tonchi

Tonchi

    Helping the world with programming

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1249 posts

Posted 12 July 2013 - 11:15 AM

i don't understand you


Microsoft Student Partner, Microsoft Certified Professional


#12 Hamed

Hamed

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 413 posts

Posted 12 July 2013 - 03:52 PM

Look at this simple code:

int main()
{
    cout << "Hello world!" << endl;
    int i = 1;
    return i;
}

I need i (returned value) when I run this application in my program.






Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download