Dhatri Maddipati
Dhatri Maddipati

Reputation: 31

Send SCPI Commands through Powershell using VISA

I have to open a session the connection Address similar to GPIB::5::INSTR and Fire the SCPI command "*IDN?" I need to do it through Powershell.

I found only one article : http://kckoay.blogspot.com/2008/07/use-powershell-to-send-scpi-command-to.html and its not working

Any help Please!!

Upvotes: 0

Views: 1360

Answers (2)

zwaggoner
zwaggoner

Reputation: 11

A little bit late, but you can get the example you linked working with some minor modifications - the comment in the original code RE: the PowerShell v1.0 bug was the hint to fixing the issue:

function New-Instrument() {
    param(
        [Parameter(Mandatory)]
        [ValidateNotNullOrEmpty()]
        [string] $RscStr
    )

    $Instance = New-Object PSObject
    
    # Instancing local Variable
    $_RM = New-Object -ComObject VISA.GlobalRM
    $_Sess = $_RM.Open($RscStr)
    $_WriteString = ([Ivi.Visa.Interop.IMessage]).GetMember("WriteString")[0]
    $_ReadString = ([Ivi.Visa.Interop.IMessage]).GetMember("ReadString")[0]
    $_Close = ([Ivi.Visa.Interop.IMessage]).GetMember("Close")[0]

    # Class Field/Property
    $Instance | Add-Member NoteProperty Sess $_Sess
    $Instance | Add-Member NoteProperty _WriteString $_WriteString
    $Instance | Add-Member NoteProperty _ReadString $_ReadString
    $Instance | Add-Member NoteProperty _Close $_Close
    #Methods
    $Instance | Add-Member -MemberType ScriptMethod WriteString {
        param([string]$Command)
        if ($Command -eq $null) {
            throw "Command cannot be null"
        }
        $this._WriteString.Invoke($this.Sess, $Command) >$null
    }

    $Instance | Add-Member ScriptMethod ReadString {
        param([int] $Length = 1024)
        if ($Length -eq $null) {
            $Length = 1024
        }
        return $this._ReadString.Invoke($this.Sess, $Length)
    }

    $Instance | Add-Member ScriptMethod Query {
        param([string] $Command)
        if ($Command -eq $null) {
            throw "Command cannot be null"
        }
        $this.WriteString($Command)
        return $this.ReadString()
    }

    $Instance | Add-Member ScriptMethod Close {
        $this._Close.Invoke($this.Sess, $null)
    }

    return $Instance
}

$Inst = New-Instrument("GPIB0::6::INSTR")
$Inst.WriteString("*IDN?")
$Inst.ReadString()
$Inst.Query("*IDN?")
$Inst.Close()

Upvotes: 1

John Doe
John Doe

Reputation: 1

I will be a similar thing soon, but no visa, only bit banging. I did find this today on forums ni, "Default GPIB termination character" it is very important to get the instrument to respond. Back in 1987, I did need to connect a logic analyzer to the IEEE-488 bus to isolate a failure where one master would send CR LF LF LF, it was working, the other master only sent CR the instrument would not respond. The above discussion might help.

Upvotes: 0

Related Questions