PicoSearch

[ Home ] [ Products ] [ Data Sheets ] [ Support ] [ FAQ ] [ Sales Offices ] [ Request Catalog ] [ Contact duTec ]

duTec logo and link to home page

BASIC Program


10 REM This is a demo program for the duTec I/O PLEXER Controller.
20 REM Many of the tools needed to construct GWBASIC programs to
30 REM interact with the IOP have been included. They key to the actual
40 REM IOP commands may be found in the DATA statements.
50 REM Although this may not be the most efficient algorthim, it does
60 REM serve to demonstrate each step in communicating with IOP.
70 REM An IV10 analog input module must be installed in position #1
80 REM of IOP in order for the program to function properly. When the
90 REM analog input is varied the output to the screen should indicate
95 REM the change.
100 CLS
110 DIM DIGIT$(15)
120 GOSUB 610 : REM initialize HEX digit array for future use.
130 INPUT "COMMUNICATION BAUDRATE=";BAUD
140 OPEN "COM1:"+STR$(BAUD)+",N,89,1,DS,CD,CS,ASC" FOR
RANDOM AS #1
150 REM ***************************************
155 REM * Here to send first transmission to I/O plexer *
157 REM ***************************************
160 ADDR$="80": REM Hex address for analog functions in I/O Plexer
as shipped from factory
170 CMD$="A": REM Power-up-clear command for first trans. to
I/O Plexer.
180 POSITION$="": REM No position field required for power-up-clear
185 GOSUB 400 : REM Build the command with the above values
190 PRINT #1,MSG$ : REM send the command to IOP.
*
200 GOSUB 890 : REM wait for the response from IOP.
210 IF FLAG=1 THEN GOTO 190
220 REM ***********************
222 REM * Print the table header *
224 REM ***********************
230 CLS
240 PRINT "RAW HEX VALUE";TAB(20);"COMPUTED INPUT VOLTS"
250 PRINT "= = = = = = = = = = = = = = = = = = = = "
252 REM *********************************************
254 REM * Here to send the request for analog data to I/O Plexer *
256 REM *********************************************
260 ADDR$="80": REM Hex address for analog functions in I/O
Plexer as shipped from factory
270 CMD$="L" : REM command letter to read analog inputs
272 POSITION$="0002" : REM Positions field indicating module
position #1
280 GOSUB 400
290 PRINT #1,MSG$
300 GOSUB 890
305 IF FLAG=1 THEN GOTO 290
340 REM *********************************************
350 REM * Here to convert raw module HEX into decimal and print. *
360 REM *********************************************
370 HEX.ANALOG.DATA$=MID$(RESPONSE$,2,4) : REM if
in-range get the actual data
375 TOTAL=0
380 FOR I=0 TO 15 : REM
382 IF MID$(HEX.ANALOG.DATA$,1,1)=DIGIT$(I) THEN
TOTAL=TOTAL+(I*4096) : REM MSB
384 IF MID$(HEX.ANALOG.DATA$,2,1)=DIGIT$(I) THEN
TOTAL=TOTAL+(I*256)
386 IF MID$(HEX.ANALOG.DATA$,3,1)=DIGIT$(I) THEN
TOTAL=TOTAL+(I*16)
388 IF MID$(HEX.ANALOG.DATA$,4,1)=DIGIT$(I) THEN
TOTAL=TOTAL+(I*1) : REM LSB
390 NEXT I
392 TOTAL=TOTAL-4096 : REM Adjust for range character "rxxx"
in response
394 VOLTS=(TOTAL/4095)*10
396 PRINT HEX.ANALOG.DATA$;TAB(20);VOLTS
398 GOTO 290 : REM continue getting data and printing it out
410 REM * Here to assemble message string and calculate
checksum.*
415 REM build the message
416 REM checksum=total ASCII value of all characters
417 REM excluding the ">" such that the subtotal after adding each
418 REM character does not exceed 255. Convert checksum into hex
419 REM value append checksumH to the command
430 MSG$=">"+ADDR$+CMD$+POSITION$
440 CHKSUM=0
450 FOR J=2 TO LEN(MSG$)
460 CHKSUM=CHKSUM+ASC(MID$(MSG$,J,1))
470 IF CHKSUM>255 THEN CHKSUM=CHKSUM-256
480 NEXT J
490 GOSUB 520
500 MSG$=MSG$+HEXSUM$
510 RETURN
520 REM *************************************
530 REM * Here to turn CHKSUM into a hex value. *
540 REM *************************************
550 HEXSUM$=HEX$(CHKSUM)
560 IF LEN(HEXSUM$)<2 THEN HEXSUM$="0"+HEXSUM$
600 RETURN
610 REM *************************************
620 REM * Here to build hex digit array. *
630 REM *************************************
640 DIGIT$(0)="0"
650 DIGIT$(1)="1"
660 DIGIT$(2)="2"
670 DIGIT$(3)="3"
680 DIGIT$(4)="4"
690 DIGIT$(5)="5"
700 DIGIT$(6)="6"
710 DIGIT$(7)="7"
720 DIGIT$(8)="8"
730 DIGIT$(9)="9"
740 DIGIT$(10)="A"
750 DIGIT$(11)="B"
760 DIGIT$(12)="C"
770 DIGIT$(13)="D"
780 DIGIT$(14)="E"
790 DIGIT$(15)="F"
830 RETURN
890 REM ******************************
900 REM * Here to receive a response from IOP. *
910 REM ******************************
920 RESPONSE$="": R$="":FLAG=0
930 DELAY=1
940 T1=TIMER
950 IF LOC(1) THEN R$=INPUT$(LOC(1),1):GOTO 970
960 IF TIMER-T1>DELAY THEN GOTO 990 ELSE GOTO 950
970 RESPONSE$=RESPONSE$+R$
980 IF RIGHT$(RESPONSE$,1)=CHR$(13) THEN RETURN ELSE
GOTO 950
990 PRINT "No response from I/O Plexer--retrying":FLAG=1
1000 RETURN


[ Home ] [ Products ] [ Data Sheets ] [ Support ] [ FAQ ] [ Sales Offices ] [ Request Catalog ] [ Contact duTec ]

Copyright 1996-2001 duTec
e-mail comments or questions to webmaster@dutec.net