Q&A

  • quick basic 소스좀 delphi로 풀어주세요...
manual에 quick basic으로 이런 소스가 있는데 문법을 뒤져봐도 해석이 잘 되지 않아서요. 죄송하게 고수님의 손을 빌리고자 합니다. 도와주셔요...



RS232->RS485 converter를 사용해서 pc로 주변 장치를 control하게 되어 있습니다.



그럼 소스 올리겠습니다. 더위 조심하세요.





Example of the Program Created Using Microsoft Quick BASIC Version 7.1

1000 ' === Main routine ===

1010 STX$=CHR$(2) ‘ Define

1020 ETX$=CHR$(3) ‘ Define

1030 CR$=CHR$(13) ‘ Define

1040 RCVCHR$= ““ ‘ Initialize receive character string

1050 fRCVEND=0 ‘ Initialize flag

1060 fTIMEOUT=0 ‘ Initialize flag

1070 '

1080 SEND$=STX$+“01010WRDD0003,03”+ETX$ ‘ Create character string for send

1090 ' ‘

1100 OPEN “COM1:9600,N,8,1,ASC” FOR RANDOM AS #1 ‘ Open a port

1110 ON COM(1) GOSUB receivechr ‘ Specify interruption processing during receiving

1120 ON TIME(5) GOSUB timeout ‘ Specify interruption processing at timeout

1130 '

1140 PRINT #1,SEND$ ‘ Send

1150 COM(1) ON ‘ Permit interruption during receive

1160 TIMER ON ‘ Start timer

1170 '

1180 DO ‘ Wait for receive end or timeout

1190 LOOP WHILE fRCVEND=0 AND fTIMEOUT=0 ‘

1200 '

1210 TIMER OFF ‘ Stop timer

1220 COM(1) OFF ‘ Prohibit interruption during receiving

1230 CLOSE #1 ‘ Close the port

1240

1250 PRINT “>”+SEND$ ‘ Display sent character string on screen

1260 PRINT “<”+RCVCHR$ ‘ Display received character string on screen

1270 END ‘ END

1280 '

1290 ' === subroutine ===

1300 receivechr: ‘ Interruption processing during receiving

1310 CHR1$=INPUT(1,#1) ‘ Fetch characters from receive buffer one by one

1320 IF CHR1$=CR$ THEN ‘ If received character string is “CR,”

1330 IF RCVCHR$=SEND$ THEN ‘ If received character string is the same

as sent command,

1340 RCVCHR$=“” ‘ received character string is initialized

(echo-back).

1350 fRCVEND=0 ‘ receiving end flag remains initialized at 0.

1360 ELSE ‘ If received character string is different

from sent command,

1370 fRCVEND=1 ‘ receiving end flag is set.

1380 END IF ‘

1390 ELSE ‘ If it is a character other than CR,

1400 fRCVEND=0 ‘ receiving end flag remains initialized at 0.

1410 RCVCHR$=RCVCHR$+CHR1$ ‘ Create received character string

1420 END IF

1430 RETURN

1440 '

1450 timeout: ‘ Timeout processing

1460 fTIMEOUT=1 ‘ Set timeout flag

1470 RCVCHR$=“Time out ! (5 sec)”+CR$ ‘ Character string for display on screen

“Time out! (5 sec)”

1480 RETURN

0  COMMENTS