Home› Programming
Discussion
Back to discussions page
Sweiskittel
Posts: 4 Apprentice
String comparison always returning FALSE |
31 views
|
Answered | |
/ Most recent by Sweiskittel
in Programming
|
2 comments |

in Programming
I am using data from a TCP/IP to determine if a part passes or fails so that the UR can place it correctly. The socket works correctly throughout the rest of the program. The socket takes a command "Dio 2 ?" and returns "Dio 2 = OFF" or "Dio 2 = ON" based on the status of the output. I then concatenate the string at the 8th character: str_sub(socket_read_string("gagemate"),8). This leaves me with a string of "ON" or "OFF". When I try to compare the string to another string I always get back FALSE. I am using the popups to show the values of Part_Pass, Part_Fail, PartPassCheck, and PartFailCheck. Regardless of the values of Part_Pass and Part_Fail, the checks always return false.This method is how I have checked other inputs in the program (see below) but does not seem to be working here. Is there something else that I need to be doing or is there some simple error that I missed?
Part Status Check Part_Pass≔"OFF" Part_Fail≔"OFF" socket_send_line("Dio 2 ?","gagemate") Part_Pass=str_sub(socket_read_string("gagemate"),8) socket_send_line("Dio 3 ?","gagemate") Part_Fail=str_sub(socket_read_string("gagemate"),8) Popup Popup PartPassCheck≔Part_Pass≟"OFF" Popup PartFailCheck≔Part_Fail≟"ON" Popup If Part_Pass≟"ON" and Part_Fail≟"OFF" Popup ElseIf Part_Pass≟"OFF" and Part_Fail≟"ON" Popup Else PopupHere is a working check at a different section in the program
Check Input GM_Status≔"OFF" Loop GM_Status≟"OFF" socket_send_line("Dio 1 ?","gagemate") GM_Status=str_sub(socket_read_string("gagemate"),8) Wait: 0.01 socket_send_line("Dio 17 ON","gagemate") socket_read_string("gagemate") Wait: 0.1 socket_send_line("Dio 17 OFF","gagemate") socket_read_string("gagemate")
Best Answer
-
matthewd92 Founding Pro, Tactile Sensor Beta Testers Posts: 1,267 Handy
Comments
-
Sweiskittel Posts: 4 Apprentice
The string returned is either "ON" or "OFF". When I check with str_len() I get a value of 5, however when I send the strings to the log they are only three or two characters long. The odd thing is that the same commands are used later in the program will not work. I will try to see if only using a sub string of length 2 may work.0 · FacebookTwitter