' ' ' #################### ' ##### PROLOG ##### ' #################### ' PROGRAM "MyFirst" ' 1-8 char program/file name without .x or any .extent VERSION "0.0001" ' version number - increment before saving altered program ' ' You can stop the PDE from inserting the following PROLOG comment lines ' by removing them from the prolog.xxx file in your \xb\xxx directory. ' ' Programs contain: 1: PROLOG - no executable code - see below ' 2: Entry function - start execution at 1st declared func ' * = optional 3: Other functions - everything else - all other functions ' ' The PROLOG contains (in this order): ' * 1. Program name statement PROGRAM "progname" ' * 2. Version number statement VERSION "0.0000" ' * 3. Import library statements IMPORT "libName" ' * 4. Composite type definitions TYPE ... END TYPE ' 5. Internal function declarations DECLARE/INTERNAL FUNCTION Func (args) ' * 6. External function declarations EXTERNAL FUNCTION FuncName (args) ' * 7. Shared constant definitions $$ConstantName = literal or constant ' * 8. Shared variable declarations SHARED variable ' ' ****** Comment libraries in/out as needed ***** ' IMPORT "xma" ' Math library : SIN/ASIN/SINH/ASINH/LOG/EXP/SQRT... IMPORT "xcm" ' Complex library : complex number library (trig, etc) IMPORT "xst" ' Standard library : required by most programs IMPORT "xgr" ' GraphicsDesigner : required by GuiDesigner programs IMPORT "xui" ' GuiDesigner : required by GuiDesigner programs ' IMPORT "kernel32" IMPORT "user32" DECLARE FUNCTION Entry () ' ' ###################### ' ##### Entry () ##### ' ###################### ' ' Programs contain: ' 1. A PROLOG with type/function/constant declarations. ' 2. This Entry() function where execution begins. ' 3. Zero or more additional functions. ' FUNCTION Entry () 'declarations DCB dcb COMMTIMEOUTS cto 'settings PcCommPort$ = "COM1" cto.ReadIntervalTimeout = 1000 cto.ReadTotalTimeoutMultiplier = 0 cto.ReadTotalTimeoutConstant = 1000 cto.WriteTotalTimeoutMultiplier = 0 cto.WriteTotalTimeoutConstant = 1000 'define some Rex 6000 commands and characters tx1 = 0xFF tx2$ = "DSBS0000EC"+CHR$(10) tx3$ = "DSVR3F"+CHR$(10) 'initialize some variables we will need numwritten = 0 numread = 0 outbuffer$ = CHR$(0,8192) 'open port hCom = CreateFileA(&PcCommPort$,ULONG($$GENERIC_READ)| ULONG($$GENERIC_WRITE), 0, 0, ULONG($$OPEN_EXISTING), 0, 0) 'dont know SetCommMask(hCom,1) 'set buffer sizes ? SetupComm(hCom,8192,8192) 'set timeouts dummy = SetCommTimeouts(hCom,&cto) IF (dummy<>1) THEN PRINT "SetCommTimeouts : Failed" ELSE PRINT "SetCommTimeouts : Succeded" ENDIF 'get current state of the port GetCommState(hCom,&dcb) 'and set it to what we want dcb.BaudRate = 57600 dcb.Parity = 0 dcb.StopBits = 0 dummy = SetCommState(hCom,&dcb) IF (dummy<>1) THEN PRINT "SetCommState : Failed" ELSE PRINT "SetCommState : Succeded" ENDIF ' write first character to port dummy = WriteFile(hCom,&tx1,ULONG(1),&numwritten,0) IF (dummy<>1) THEN PRINT "Write 1st FF : Failed" ELSE PRINT "Write 1st FF : Succeded" ENDIF 'write second character to port dummy = WriteFile(hCom,&tx1,ULONG(1),&numwritten,0) IF (dummy<>1) THEN PRINT "Write 2nd FF : Failed" ELSE PRINT "Write 2nd FF : Succeded" ENDIF 'this might clear the current error ?register? 'I have no clue whether I am clearing the right thing, but it works ' lpError = $$CE_BREAK ' lpStatus = ULONG(0) ' dummy = ClearCommError(hCom,&lpError,&lpStatus) ' PRINT "error ", dummy 'write the actual command to the Rex dummy = WriteFile(hCom,&tx2$,ULONG(11),&numwritten,0) IF (dummy<>0) THEN PRINT "Write command : Succeded" ELSE PRINT "Write command : Failed" ENDIF dummy = FlushFileBuffers(hCom) IF (dummy<>0) THEN PRINT "Flush buffer : Succeded" ELSE PRINT "Flush buffer : Failed" ENDIF 'read what we got dummy = ReadFile(hCom,&outbuffer$,5,&numread,0) IF (dummy<>0) THEN PRINT "Read buffer : Succeded" ELSE PRINT "Read buffer : Failed" ENDIF PRINT "Read :",outbuffer$ 'write the actual command to the Rex dummy = WriteFile(hCom,&tx3$,ULONG(7),&numwritten,0) IF (dummy<>0) THEN PRINT "Write command : Succeded" ELSE PRINT "Write command : Failed" ENDIF FlushFileBuffers(hCom) IF (dummy<>0) THEN PRINT "Read buffer : Succeded" ELSE PRINT "Read buffer : Failed" ENDIF 'read what we got dummy = ReadFile(hCom,&outbuffer$,18,&numread,0) IF (dummy<>0) THEN PRINT "Read buffer : Succeded" ELSE PRINT "Read buffer : Failed" ENDIF PRINT "Read :",outbuffer$ 'close the port CloseHandle(hCom) END FUNCTION END PROGRAM