In the Main function of this script I have two if statements, each having two conditions that should be met before running. In the first if statement both conditions are met but the code is not running. Below is the code and the output. Any insight would be valuable!
$port= new-object system.io.ports.serialport com4
$port.open()
$gpi= 0
$toggle1 = 0
$toggle2 = 0
function read-com{
$port.write("gpio read 0`r")
$dump = $port.readline()
$script:gpi = $port.readline()
}
function low-com{
C:\Users\ccrcmh1djg\Videos\Reel\default.m4v
}
function high-com{
C:\Users\ccrcmh1djg\Videos\Reel\on-air.m4v
}
function main{
do{
read-com
sleep -m 500
'read-com'
$toggle1
$gpi
if(($gpi -eq 0) -and ($toggle1 -eq 0)){
$toggle1 = 1
$toggle2 = 0
low-com
'low-com conditions met'
}else{write-host 'low-com condition not met'}
$toggle1
$gpi
if(($gpi -eq 1) -and ($toggle2 -eq 0)){
$toggle1 = 0
$toggle2 = 1
high-com
'high-com conditions met'
}Else{Write-Host 'high-com condition not met'}
'loop'
}while ($port.IsOpen)
}
main
Output:
read-com
0
0
low-com condition not met
0
0
high-com condition not met
loop
Thanks!