Handshaking With Device

Welcome Forums General PowerShell Q&A Handshaking With Device

This topic contains 1 reply, has 2 voices, and was last updated by

 
Participant
2 years, 1 month ago.

  • Author
    Posts
  • #57364

    Participant
    Points: 0
    Rank: Member

    Serial COM port communication works great on all my devices except one. None of them use handshaking and I can't get the one that requires handshaking to work. Am I setting this up correctly? Right now I'm just using the following commands

    $port=new-object system.io.ports.serialport COM5, 9600, None, 8, one
    $port.handshake="XOnXOff"
    $port.open()
    

    But it gives the following error

    Exception calling "Open" with "0" argument(s): "Access to the port 'COM5' is denied."
    At line:1 char:11
    + $port.open < <<< ()
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : DotNetMethodException
    

    I can use software or hardware handshaking on the device. Right now I am trying to use the software handshaking option, but it isn't working. Can anyone tell me what I'm doing wrong? Thank you for your time!

  • #57467

    Participant
    Points: 25
    Rank: Member

    Is something else using the port?

    If you run

    $port=new-object system.io.ports.serialport COM5, 9600, None, 8, one
    $port.handshake="XOnXOff"
    $port.open()
    
    $port2=new-object system.io.ports.serialport COM5, 9600, None, 8, one
    $port2.handshake="XOnXOff"
    $port2.open()
    

    You get the same access denied error when you call the open() method on port 2. This would imply that something is already using the port. You should be able to check with WMI by querying the IsBusy value:

    Get-WmiObject Win32_SerialPortConfiguration -Filter 'Caption = "COM5"' | Select IsBusy
    

    If that returns true something else is using COM5.

The topic ‘Handshaking With Device’ is closed to new replies.