!Initial demo program for AlphaMicro TrueGui interface !Gui commands as well as their arguments are case-sensitive ! ! [024] 23Feb08 Add debug application forms folder ! [023] 31Aut06 Cleand up EXIT routines/mwt ! [022] 16Aug06 Fixed program flow error with TgGetReply:/mwt ! [021] 28Jul06 Adding FTP example/mwt ! [014] 19May06 Added: OuterLimitsText'Echo: so echos to OuterSpaceText.Text/mwt ! [015] 19May06 Switched to BASIC Plus to simplify CodePage testing/mwt ! Special to test Chinese Big for Dick Wilcox/mwt ! [016] 3Jun06 Added: Validation: /mwt ! NOTE: VALADATION: The EventData.Cancel DOES NOT WORK!! - apparently too much time passes! print "$$EnterTrueGuiMode$$" ! make sure in TrueGuiMode!! STRSIZ 100 Map1 TgInput$,S ! read the raw input into this string variable Map2 TgTypeCode$,S,1 ! this character will be the type code Map2 TgText$,S ! this string has the rest of the input Map3 TgErrorCode$,S,3 ! if type 1, the 3 character error code Map3 TgComma$,S,1 ! if type 1, this is a comma Map3 TgErrorMessage$,S,500 ! if type 1, this has the error message Map1 TgInput,x,500,@TgInput$ ! type x (raw) Map1 TgInputB(500),b,1,@TgInput$ ! byte array overlay Map1 TgText,x,500,@TgText$ ! type x (raw) Map1 TgTextB(500),b,1,@TgText$ ! byte array overlay map1 Event$,s,100 ! big enough for most anything map1 Control$,s,300 ! big enough for most anything map1 sd$,s,5 ! For TESTING version 112o and later ! sd$ = chr$(144) ! made a string for easy testing. 220o 144. 90h "Device Control String" ! !!sd$ = chr$(130) ! !!sd$ = "q" sd$ = "`" ! reset to default !Display a message to the trace window !All terminal output when not enclosed within curly braces will be displayed in the User Debug Window !The color of these trace messages when not in "TrueGui" mode will be in black text print "Starting GUITST.RUN .B22" print "{ PurgeEvents() }" ! make sure we are starting fresh in case print "{ PurgeErrors() }" ! been here before in this session. !Load the CsForms.exe Assembly file print "{ TrueGui.LoadAssembly(`CsForms`) }" !! Get the explicit directory which holds the icons/images [024] INPUT "{TrueGui.FormsDirectory?}",TgInput !Create an instance of Form1 calling it "MyForm" print "{ MyForm = New CsForms.Form1() }" !Show MyForm print "{ MyForm.Show() }" ! The following is for TESTING revisions 112o and later: ! print "{ StringDelimiter='"+sd$+"'}" ! print "{ StringDelimiter? }" ! call TgGetReply ! print "{ OuterSpaceText.Text="+sd$+"The Deliminator!"+sd$+" }" ! print "{ StringDelimiter='`' }" ! end of 112o test section ! Read the current global string delimiter characters print "{ TrueGui.BeginCommand? }" call TgGetReply ! ALWAYS call for input!!!! print "! BeginCommand = "+TgText$ print "{ TrueGui.EndCommand? }" call TgGetReply ! ALWAYS call for input!!!! print "! EndCommand = "+TgText$ ! Read the listView Anchor property which may contain commas print "{ lv.Anchor? }" call TgGetReply ! ALWAYS call for input!!!! print "! ListView Anchor is "; TgText$ ! Add the 12 months to the combo box print "{ comboBox1.Items.Add("+sd$+"January"+sd$+") }" print "{ comboBox1.Items.Add("+sd$+"February"+sd$+") }" print "{ comboBox1.Items.Add("+sd$+"March"+sd$+") }" print "{ comboBox1.Items.Add("+sd$+"April"+sd$+") }" print "{ comboBox1.Items.Add("+sd$+"May"+sd$+") }" print "{ comboBox1.Items.Add("+sd$+"June"+sd$+") }" print "{ comboBox1.Items.Add("+sd$+"July"+sd$+") }" print "{ comboBox1.Items.Add("+sd$+"August"+sd$+") }" print "{ comboBox1.Items.Add("+sd$+"September"+sd$+") }" print "{ comboBox1.Items.Add("+sd$+"October"+sd$+") }" print "{ comboBox1.Items.Add("+sd$+"November"+sd$+") }" print "{ comboBox1.Items.Add("+sd$+"December"+sd$+") }" !! call Add'Validating ! turn it on ! Display a message box telling him we will wait until BigButton on Page 3 is clicked ![023] print "{ MessageBox.Show("+sd$+"Guitst will now loop until you click the BigButton on page 3"+sd$+", "+sd$+"Guitst Message"+sd$+") }" print "{ MessageBox.Show("+sd$+"Guitst will now loop until you click the BigButton on page 3; [X] Aborts"+sd$+", "+sd$+"Guitst Message"+sd$+") }" ! [023] print "! Looping..." ! Wait for BigButton (on tab page 3) to be clicked General'Input'Loop: call TgGetNext ! all Leave Events handled from TgGetNext ! all Validating Events handled from TgGetNext ! if Event$ = "Validating" GOTO Validating'Event if Event$ = "Closed" GOTO Closed'Event if Event$ <> "Click" goto General'Input'Loop ! 10 ! else IS Click: if Control$ = "MyForm.BigButton" goto Exit'Program ! BigButton if Control$ = "MyForm.exitToolStripMenuItem" goto Abort'Program ! File Menu item print "! Not the BigButton - control name is "; Control$ GOTO General'Input'Loop ! 10 Closing'MyForm: !! print "{ MessageBox.Show("+sd$+"Do you really want to close this form?"+sd$+", "+sd$+"Closing MyForm"+sd$+",MB_YESNO) }" print "{ MessageBox.Show("+sd$+"Closing this form!"+sd$+", "+sd$+"Closing MyForm"+sd$+") }" ![023] begin Exit'Program: ! Exit the program print "! Exiting the Guitst program" print "{ CloseProgram() }" print "{ PurgeEvents() }" print "{ PurgeErrors() }" !! print "{ Reset() }" print "{ LeaveTrueGuiMode() }" CHAIN "Sys:SET.LIT ECHO" ! Turn it back on END Abort'Program: ! Exit the program & close TrueGUI print "{ MessageBox.Show("+sd$+"Aborting from this form!"+sd$+", "+sd$+"X'ing MyForm"+sd$+") }" print "{ CloseTelnet() }" print "{ CloseServer() }" print "{ AbortSession() }" CHAIN "Sys:SET.LIT ECHO" ! Turn it back on END ![023] end ! The OuterLimitsText routines ================================================= ! This routine takes input from OuterLimitsText and echoes it in OuterSpaceText! OuterLimitsText'Echo: PRINT "{ OuterLimitsText.Text? }" call TgGetReply ! ALWAYS call for input!!!! PRINT "{ OuterSpaceText.Text = "+sd$+TgText$+sd$+" }" return ! ============================================================================== ! The DateTimePicker routines ================================================== ! NOTE: The EventData.Cancel DOES NOT WORK!! - apparently too much time passes! !DateTimePicker'Validating: ! print "{ dt.Checked? }" ! ask for the status ! call TgGetReply ! wait for some data ! ! NOTE: If it comes back with some other type, we may be screwed ! if TgText$ = "False" print "{ EventData.Cancel = True } " ! do not accept the validation ! NOTE: The EventData.Cancel DOES NOT WORK!! - apparently too much time passes! ! GOTO TgGetNext ! keep looping there ! to go back to the outer application, RETURN ! ============================================================================= ! =========== FTP Example =================================================== FTP'Get'File: task$ = "FTP RemoteIP" print "{ FtpRemoteIP.Text? }" call TgGetReply !!? "! Len:"+len(TgText$) !! if len(TgText$ = 0) GOTO FTP'Parameter'Error print "{ host1 = "sd$+TgText$+sd$+" }" task$ = "FTP User ID" print "{ FtpUserID.Text? }" call TgGetReply !! if len(TgText$ = 0) GOTO FTP'Parameter'Error print "{ user1 = "sd$+TgText$+sd$+" }" task$ = "FTP Password" print "{ FtpPassword.Text? }" call TgGetReply !! if len(TgText$ = 0) GOTO FTP'Parameter'Error print "{ pass1 = "sd$+TgText$+sd$+" }" task$ = "FTP File" print "{ FtpFile.Text? }" call TgGetReply !! if len(TgText$ = 0) GOTO FTP'Parameter'Error print "{ file1 = "sd$+TgText$+sd$+" }" task$ = "Clean from last time" print "{ client1? }" call TgGetReply !! if TgText$ # "null" then print "{ FTPClient client1 = null }" print "{ client1 = new FTPClient(host1) }" print "{ client1.Login(user1, pass1) }" print "{ client1.TransferType = FTPTransferType.BINARY }" print "{ client1.ConnectMode = FTPConnectMode.ACTIVE }" print "{ client1.Get(file1,file1) }" print "{ client1.Login(user1, pass1) }" print "{ client1.Quit() }" GOTO TgGetNext ! continue waiting FTP'Parameter'Error: print "{ MessageBox.Show("+sd$+task$+" is required - please complete all fields!"+sd$+", "+sd$+"Guitst Message"+sd$+") }" GOTO TgGetNext ! continue waiting ! ============================================================================= ! =========== Customized Event handling ===================================== Leave'Event: !------------------------------------------------- if Control$ = "MyForm.OuterLimitsText" CALL OuterLimitsText'Echo GOTO TgGetNext ! keep waiting Closed'Event: ![023] if Control$ = "MyForm" GOTO Closing'MyForm if Control$ = "MyForm" GOTO Abort'Program GOTO TgGetNext ! keep waiting Click'Event: !-------------------------------------------------- if Control$ = "MyForm.FtpGetFile" then GOTO FTP'Get'File ! side task ! Because the "General'Input'Loop:" or the outer (application) is handling all Clicks RETURN ! return to what called TgGetNext ! To simply ignore: ! GOTO TgGetNext ! not important - continue waiting ! ============================================================================== !Validating'Event: !-------------------------------------------------- ! if Control$ = "MyForm.dt" GOTO DateTimePicker'Validating ! ! here for any other controls that actually need validation ! GOTO TgGetNext ! did all that was necessary for Validate, ! ! so back to waiting for input. ! !Add'Validating: ! because not defaulted on ! print "{ AddEventsByForm("+sd$+"Validating"+sd$+", MyForm) }" ! Turn on validation ! RETURN ! ============================================================================== !============ TrueGUI Get Input =================================== ! ! This routine loops until some section has data for the caller, then ! that routine does a RETURN ! TgGetNext: PRINT "{NextEvent?}" ! Ask for the next thing from TrueGUI TgGetReply: TgInput$ = "" ! clean it out INPUT LINE TgInput ! Wait for TrueGUI to reply ! call Data'Input ! for testing control character input with BASIC-Plus !!!! print "! Server Got """+TgInput$+"""" print "! Got TypeCode "+TgTypeCode$+"="""+TgText$+""", length: "+len(TgInput$) Dump'Text = -1 if Dump'Text then call Dump'TgText ON TgTypeCode$ GOTO & TgErrorHandler & ,TgDataHandler & ,TgEventHandler ! else fall through: Unknow input - perhaps log it and continue: PRINT #log'channel, "?Unknown TrueGUI Error: " + TgInput$ GOTO TgGetNext ! loop to continue (or abort) TgErrorHandler: ! TgErrorCode$ & TgErrorMessage$ are set, so PERHAPS: PRINT #log'channel, "?TrueGUI Error: "+TgErrorCode$+": "+TgErrorMessage$ GOTO TgGetNext ! loop to continue (or abort) TgDataHandler: ! The requested data is in TgText$ RETURN ! pass the data back to the caller TgEventHandler: ! Something else happened! X = INSTR(1, TgText$, ",") ! find the comma separator Event$ = TgText$[1, X-1] ! get the event name Control$ = TgText$[X+1, -1] ! and the control name print "! Event: """+Event$+""" Control: """+Control$+"""" ! Check for universal events: (Could also be done in Click'Events) ! To set up for pre-existing escape code processing in original application: IF Event$ = "Click" AND Contol$ = "Cancel" & THEN TgText$ = chr$(27) ! put a real Escape (0x1b) & : RETURN ! to who called for input ! OR To go to an existing trap routine: ! IF Event$ = "Click" AND Contol$ = "Cancel" & ! THEN GOTO Exit'Program ! NOTE: both of the above test both Event$ and Control$ ! OR ! Handle the events based on Control$ ! print "! Dispatching in TgGetNext based on Control" ! if Control$ = "Cancel" GOTO Cancel'Handeling ! if Control$ = "dt" GOTO DateTimePicker'Handling ! OR ! Handle the events based on Event$ print "! Dispatching in TgGetNext based on Event" if Event$ = "Leave" GOTO Leave'Event if Event$ = "Click" GOTO Click'Event if Event$ = "Closed" GOTO Closed'Event ! if Event$ = "Validating" GOTO Validating'Event GOTO TgGetNext ! something we can ignore. ! OR ! to have the outer (application) layer can handle, replace GOTO with ! RETURN ! pass it to TgGetNext CALLER! !============ Generalized Byte by Byte input handler ============== ! ! WORKS only with BASIC-Plus ! ! Loops until ^C (for aborting a test failure), CR, or LF ! to test for handling control characters. Data'Input: pointer = 0 Data'Input'Loop: pointer = pointer + 1 x = getkey(-1) ! wait for the next keystroke TgInputB(pointer) = x ! put it into the string overlay if x = 3 then GOTO Exit'Program ! ^C - Exit ! looking for pair, but TrueGUI only sends the ! if x = 10 ! line feed ! if pointer > 1 ! if TgInputB(pointer-1) = 13 ! ? ! TgInputB(pointer-1) = 0 ! - mark that as the end ! else ! TgInputB(pointer) = 0 ! mark that as the end ! endif ! endif ! endif ! So, if x = 13 or x = 10 TgInputB(pointer) = 0 ! CR or LF - mark as end if TgInputB(pointer) # 0 GOTO Data'Input'Loop ! not done return !============ Debugging Dump =========================================================== Dump'TgText: RETURN ! not needed right now ? ? "! Dumping current TgText: " for Dump'x = 1 to 16 ? "!"; ((Dump'x*16)-16) using "##: "; for Dump'y = 1 to 16 decimal = TgTextB(((Dump'x - 1) * 16) + Dump'y) call Convert'Decimal'To'Hex ? hex$ + " "; if hex$ = "00" then Dump'y = 16 ! end of string? next Dump'y ? tab(56); TgText$[((Dump'x-1)*16)+1;16] ! and the text, letting basic filter out stuff if hex$ = "00" then Dump'x = 16 ! end of string? next Dump'x return ? "! Testing for delimiters: " Delimiter$ = "'\}{""" for Dump'x = 1 to 256 Dump'y = instr(1,Delimiter$,TgText$[Dump'x;1]) if Dump'y ? " Byte: "+Dump'x+" is "+Delimiter$[Dump'y;1] next Dump'x return Convert'Decimal'To'Hex: ! decimal = decimal value ! hex is a work varialbe ! hex$ is the result hex'decode$ = "0123456789abcdef" ! hex = int(decimal/16) ! get high digit hex$ = hex'decode$[hex+1;1] hex = int(decimal - (hex * 16)) ! the low digit hex$ = hex$ + hex'decode$[hex+1;1] return !==========================================================================================