
adccommunitymod (AutomationDirect) asked a question.
Created Date: April 09,2010
Created By: jgreen
**** This post has been imported from our legacy forum. Information in this post may be outdated and links contained in the post may no longer work.****
Hello, I'm communicating with an Air-handler temp/humidity controller. I'm using a DL06 PLC with a CP128 BASIC Coprocessor module. I also have a C-More touch panel for the user interface. I'm am changing the rum state by sending the command string "=OO ". When I send the command the run state toggles from one state to the other. When it switches off it sends back multiple strings. First, it sends back the command that it received. Then it sends back an empty string (maybe spaces?) then the third string it sends back is the current run state ( "OFF "). When it switches on it sends back even more strings but the 3rd string is still the run state. In my BASIC code I 've been able to isolate the third string. I'm trying to use this string (string3 $(3)) to control the status bit (C21) of the PLC. If $(3)= "ON " I want C21 to come on. If $(3)= "OFF " I want C21 to turn off. In troubleshooting I "parsed " 2 characters from the string into string9 and ended up with string9 being either ON or OF. I'm then tried to use string9 to control status bit C21. I think my problem is that I don't know how to use strings in IF THEN statements. Here's where I'm at with the code: 10 REM*** 20 REM Program for communicating with PGC air handler 30 REM*** 40 STRING 2551,254 50 SETPORT 1,9600,N,8,1,N 60 SETPORT 3,9600,N,8,1,N 70 SETINPUT 1,1,13,0,1000,1000 80 REM*** 90 PRINT1 "Waiting for trigger " 95 CLEAR 100 REM*** 110 DO:UNTIL S06_C(6) 112 GOTO 116 114 REM*** 116 REM*** 118 S06_C(6)=0 120 REM*** 128 PRINT1 "Sending Run State Change Command " 130 PRINT3 "=OO ",CR, 131 DELAY 20 132 REM*** 133 INPUT3 ,$(0),$(2),$(3),$(4),$(5),$(6),$(7),$(8) 138 PRINT1 "Response= ",$(3) 140 $(9)=MID$($(3),2,2) 141 PRINT1 "Parsed data= ",$(9) 142 IF $(9)= "ON " THEN S06_C(21)=1 ELSE S06_C(21)=0 146 REM*** 148 GOTO 60 Any help would be much appreciated.
Created Date: April 09,2010
Created by: MacS
Hello jgreen,
This statement:
142 IF $(9)= "ON " THEN S06_C(21)=1 ELSE S06_C(21)=0
Will only compare the first character of string 9 to the first character of the literal string ( "O ").
You need to use the INSTR statement to do a full string matching.
I would recommend adding more debug statements to see exactly what response you are getting.
132 REM***
133 INPUT3 ,$(0),$(2),$(3),$(4),$(5),$(6),$(7),$(8)
134 PRINT1 "$(0)= ",$(0)
135 PRINT1 "$(2)= ",$(2)
136 PRINT1 "$(3)= ",$(3)
137 PRINT1 "$(4)= ",$(4)
138 PRINT1 "$(5)= ",$(5)
139 PRINT1 "$(6)= ",$(6)
140 PRINT1 "$(7)= ",$(7)
141 PRINT1 "$(8)= ",$(8)
150 $(9)=MID$($(3),2,2) : REM Parse 2nd and 3rd character into string 9
151 PRINT1 "Parsed data= ",$(9)
152 IF INSTR($(9), "ON ") THEN S06_C(21)=1 ELSE S06_C(21)=0
156 REM***
158 GOTO 60
>When I send the command the run state toggles from one state to the other. When it switches off it sends back multiple strings. First, it sends back the command that it received. Then it sends back an empty string (maybe spaces?) then the third string it sends back is the current run state ( "OFF "). When it switches on it sends back even more strings but the 3rd string is still the run state. In my BASIC code I 've been able to isolate the third string.
Are all of these responses CR terminated?
If not it would most likely be simpler to input the whole response into one string and parse out what you need.
Created Date: April 09,2010
Created by: jgreen
Cp128 basic module programming help
MacS,
Thank you very much. I was able to simply isolate the N or F from the string and use that for my IF THEN statement. It's working perfectly.
Best Regards,
Jack Green
Mechanical Engineer
Flow Sciences, Inc.
Created Date: April 09,2010
Created by: jgreen
Hello,
I'm communicating with an Air-handler temp/humidity controller. I'm using a DL06 PLC with a CP128 BASIC Coprocessor module. I also have a C-More touch panel for the user interface.
I'm am changing the rum state by sending the command string "=OO ". When I send the command the run state toggles from one state to the other. When it switches off it sends back multiple strings. First, it sends back the command that it received. Then it sends back an empty string (maybe spaces?) then the third string it sends back is the current run state ( "OFF "). When it switches on it sends back even more strings but the 3rd string is still the run state. In my BASIC code I 've been able to isolate the third string.
I'm trying to use this string (string3 $(3)) to control the status bit (C21) of the PLC. If $(3)= "ON " I want C21 to come on. If $(3)= "OFF " I want C21 to turn off.
In troubleshooting I "parsed " 2 characters from the string into string9 and ended up with string9 being either ON or OF. I'm then tried to use string9 to control status bit C21.
I think my problem is that I don't know how to use strings in IF THEN statements. Here's where I'm at with the code:
10 REM***
20 REM Program for communicating with PGC air handler
30 REM***
40 STRING 2551,254
50 SETPORT 1,9600,N,8,1,N
60 SETPORT 3,9600,N,8,1,N
70 SETINPUT 1,1,13,0,1000,1000
80 REM***
90 PRINT1 "Waiting for trigger "
95 CLEAR
100 REM***
110 DO:UNTIL S06_C(6)
112 GOTO 116
114 REM***
116 REM***
118 S06_C(6)=0
120 REM***
128 PRINT1 "Sending Run State Change Command "
130 PRINT3 "=OO ",CR,
131 DELAY 20
132 REM***
133 INPUT3 ,$(0),$(2),$(3),$(4),$(5),$(6),$(7),$(8)
138 PRINT1 "Response= ",$(3)
140 $(9)=MID$($(3),2,2)
141 PRINT1 "Parsed data= ",$(9)
142 IF $(9)= "ON " THEN S06_C(21)=1 ELSE S06_C(21)=0
146 REM***
148 GOTO 60
Any help would be much appreciated.