Jump to content

Why won't my PowerShell Script work

Hi !

Does anyone know why this doesn't work?

$port= new-Object System.IO.Ports.SerialPort COM4,9600,None,8,one
$port.Open()
while($true) {
 
$line = $port.ReadLine()

echo $line


If ($line -eq "1"){
    echo "Hello"
}


}


If it recieves a 1 it doesn't print Hello.

Link to comment
Share on other sites

Link to post
Share on other sites

are you sure the com port is right? and -eq means it is equal. if it receives a one it will print hello. and thridly is it string being sent or int? if it is integer it should just be 

If ($line -eq 1){
    echo "Hello"
}

 

Link to comment
Share on other sites

Link to post
Share on other sites

I found out there is an invisible sign if you print it as hex

the 33 is the number as hex but there is this invisible 0D.

Do you know how to remove this or just compare without it.

powershell_9KrvyIXWAQ.png

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×