Mode 3 Cls rem ***************** rem ctLab routinen rem ***************** sub ct_init() rem globale variablen ct_debug=0 ct_add =-1 ct_par =-1 ct_wert =-1 ct_wstr$="" ct_new=0 ct_inp$="" ct_inplen=0 ct_out$="" Open "com1:19200" As #1 end sub sub ct_close() close #1 end sub sub ct_sendWert(add,par,wert) local s1$,s2$,s3$ s1$ =str$(add) s2$ =str$(par) s3$ =str$(wert) ct_out$ =s1$+":"+s2$+"="+s3$ Print #1,ct_out$ end sub sub ct_sendCmd(add,par) local s1$,s2$,s3$ s1$ =str$(add) s2$ =str$(par) ct_out$ =s1$+":"+s2$ Print #1,ct_out$ end sub function ct_read() ct_inplen =Loc(#1) if ct_inplen>0 then ct_inp$ = Input$(ct_inplen,#1) endif ct_read=ct_inplen end function function ct_readln() local c$, i ct_inp$ ="" for i=0 to 100 if Loc(#1)>0 then c$ =Input$(1,#1) if (Asc(c$)=10) or (Asc(c$)=10) then exit for else ct_inp$=ct_inp$+c$ endif else pause(20) ' max 2s warten endif next ct_inplen = len(ct_inp$) ct_readln=ct_inplen end function sub ct_parse() local l_c$, i, state, wstr$, err if ct_debug then print ct_inp$ endif for i=1 to len(ct_inp$) l_c$=mid$(ct_inp$,i,1) If state =0 Then If l_c$="#" Then state =1 ct_add=-1 ct_par=-1 ct_val=-1 wstr$="" err=1 Else state=0 EndIf ElseIf state =1 Then If isnum(l_c$)=1 Then ct_add=Val(l_c$) state=2 Else state=-1 EndIf ElseIf state =2 Then If l_c$=":" Then state=3 Else state=-1 EndIf ElseIf state =3 Then If l_c$="=" Then If Len(wstr$)>0 And Len(wstr$)<4 Then ct_par=Val(wstr$) wstr$="" state=4 Else state=-1 EndIf Else wstr$=wstr$+l_c$ EndIf ElseIf state =4 Then If (l_c$=" ") Or (Asc(l_c$)=13) Then If Len(wstr$)>0 Then ct_wert=Val(wstr$) state =5 Else state=-1 EndIf Else wstr$=wstr$+l_c$ EndIf ElseIf state=5 Then ct_neu=1 state=0 ElseIf state=-1 Then Print "err" state=0 EndIf next i end SUB Function isnum(s$) isnum=0 If s$ ="0" Then isnum=1 If s$ ="1" Then isnum=1 If s$ ="2" Then isnum=1 If s$ ="3" Then isnum=1 If s$ ="4" Then isnum=1 If s$ ="5" Then isnum=1 If s$ ="6" Then isnum=1 If s$ ="7" Then isnum=1 If s$ ="8" Then isnum=1 If s$ ="9" Then isnum=1 End Function Function isnumqual(s$) isnum=0 If s$ ="+" Then isnum=1 If s$ ="-" Then isnum=1 If s$ ="." Then isnum=1 End Function rem ***************** rem Grafik routinen rem ***************** numww=220 numhh=180 numwo=MM.HRes-numww numho=45+1 ' wo=10 ' ho=MM.VRes-4*sh-10 Sub setnumfeld 'btn 10-20 Local i,j,sw,sh sw=numww\3 sh=numhh\4 Touch size sw,sh For i=0 To 2 For j=0 To 2 Touch create i*3+j+11,j*sw+numwo,(2-i)*sh+numho,Str$(i*3+j+1),Blue,b Next j Next i Touch create 0+10,0*sw+numwo,3*sh+numho,Str$(0),Blue,b Touch create (10+10),1*sw+numwo,3*sh+numho,"<",Blue,b Touch create (11+10),2*sw+numwo,3*sh+numho,">",Blue,b End Sub Sub clrnumfeld Local i,j For i=10 To 20 Touch remove i Next i Line (numwo,numho)-(numwo+numww,numho+numhh),Black,fb End Sub okww=numww okhh=45 okwo=MM.HRes-okww okho=MM.VRes-okhh-2 Sub setoknok 'btn 0-ok, 1-nok Local sw,sh,wo,ho sw=okww\2 sh=okhh Touch size sw,sh Touch create 0,okwo+sw,okho,"OK",Green,b Touch create 1,okwo,okho,"NOK",Red,b End Sub Sub clroknok Touch remove 0 Touch remove 1 Line (okwo,okhh)-(okwo+okww,okho+okhh),Black,fb End Sub editww=numww edithh=numhh\4 editwo=numwo editho=0 Sub setedit Local txt$ Line (editwo,editho)-(editwo+editww-1,editho+edithh),Yellow,b End Sub Sub clredit Line (editwo,editho)-(editwo+editww,editho+edithh),Black,bf End Sub Sub eddi(lbtn,ini) Local txt$,v If lbtn>=10 And lbtn<=19 Then v=lbtn-10 If mode=2 Then txt$=Format$(edval,"%06.3f") ElseIf mode=3 Then txt$=Format$(edval,"%06.1f") EndIf edval = Val(Left$(txt$,edpos)+Str$(v)+Right$(txt$,5 - edpos)) edpos = edpos+1 If edpos>5 Then edpos=5 If mode=2 Then If edpos=2 Then edpos=3 txt$=Format$(edval,"%06.3f") ElseIf mode=3 Then If edpos=4 Then edpos=5 txt$=Format$(edval,"%06.1f") EndIf EndIf If lbtn=20 Then '< edpos=edpos-1 If edpos=2 And mode=2 Then edpos=1 ElseIf edpos=4 And mode=3 Then edpos=3 ElseIf edpos<0 Then edpos=0 EndIf elseIf lbtn=21 Then '> edpos=edpos+1 If edpos=2 And mode=2 Then edpos=3 ElseIf edpos=4 And mode=3 Then edpos=5 ElseIf edpos>5 Then edpos=5 EndIf EndIf If ini=1 Then 'Erstaufruf If mode=2 Then txt$=Format$(edval,"%06.3f") ElseIf mode=3 Then txt$=Format$(edval,"%06.1f") EndIf EndIf wa=editwo+editww\2-3*25 ha=editho+7 Print @(wa,ha) txt$ Line (wa,ha)-(wa+6*25,ha-1),Black,fb Line (wa+edpos*25,ha)-(wa+edpos*25+24,ha-1),Yellow,fb End Sub btn =-1 btnval=0 wist=10 wwist=250 histU=10 histI=60 hhist=100 Sub dispist(U_ist,I_ist) Local txt$ txt$ = Format$(U_ist,"%6.3f") Print @(wist,histU) txt$ txt$ = Format$(I_ist,"%6.1f") Print @(wist,histI) txt$ End Sub Sub initdisp ' *** 2 - U *** ' *** 3 - I *** Local txt$ Line (0,0)-(wwist,hhist),Yellow,b Line (2,2)-(wwist+2,hhist+2),Blue,b Touch size wwist,hhist\2 Touch create 2,0,0,"",Black Touch create 3,0,hhist\2,"",Black Font 2,1 Print @(wist+6*25,histU-1) "V" Print @(wist+6*25,histI-1) "mA" 'Touch size 6*13+25,25 'Touch create 5,wist+6*25+30,histU,"00.000",Blue,b 'Touch create 6,wist+6*25+30,histI,"0000.0",Blue,b ''Touch size 6*25,25 ''Touch create 5,wist,histU+38,"00.000",Black,b ''Touch create 6,wist,histI+40,"0000.0",Black,b txt$=Format$(U_soll,"%06.3f") Print @(wist+6*25,histU+16) txt$ txt$=Format$(I_soll,"%06.1f") Print @(wist+6*25,histI+16) txt$ Font 3 End Sub U_ist=-1 I_ist=-1 U_soll=5 I_soll=20 sub getser rem dcg U soll 0, U ist 10 rem dcg I soll 2 mA, I ist 12 mA local cmd cmd = 10 ct_sendCMD (2,cmd) if ct_readln() then ct_parse() if (ct_add=2) and (ct_par=cmd) then U_ist=ct_wert endif endif cmd = 12 ct_sendCMD (2,cmd) if ct_readln() then ct_parse() if (ct_add=2) and (ct_par=cmd) then I_ist=ct_wert endif endif rem U_ist=U_soll+0.1*(0.5-Rnd()) rem I_ist=I_soll+0.5*(0.5-Rnd()) End Sub Sub setser(m,val) rem dcg U soll 0, U ist 10 rem dcg I soll 2 mA, I ist 12 mA local cmd if m=2 then cmd = 0 ct_sendWert (2,cmd,val) if ct_readln() then ct_parse() if (ct_add=2) and (ct_par=cmd) then U_soll=ct_wert endif endif elseif m=3 then cmd = 2 ct_sendWert (2,cmd,val) if ct_readln() then ct_parse() if (ct_add=2) and (ct_par=cmd) then I_soll=ct_wert endif endif endif End Sub Sub chkkey Local i btn = Touched(#i) If btn>-1 Then If Touched(btn) Then If (btn>=0) And (btn<=20) Then 'push buttons TouchVal(btn)=0 Else btnval=TouchVal(btn) EndIf Else btn=-1 EndIf EndIf End Sub Rem *** main *** 'init initdisp 'clrnumfeld ct_init() mode =0 'normal Do getser dispist(U_ist,I_ist) chkkey If mode=0 Then If btn=2 Or btn=3 Then 'soll editieren mode=btn setnumfeld setoknok setedit edpos=0 If mode =2 Then edval=U_soll ElseIf mode=3 Then edval=I_soll EndIf Eddi(-1,1) EndIf ElseIf mode=2 Or mode=3 Then 'edit If btn=0 Or btn=1 Then 'aufraeumen If btn=0 Then 'ok If mode=2 Then U_soll=edval ElseIf mode=3 Then I_soll=edval EndIf 'mode setser(mode,edval) initdisp endif 'ok clrnumfeld clroknok clredit mode=0 else Eddi(btn,0) EndIf EndIf Pause(250) Loop Rem *********** Ablauf ********** initgraph initser