// © Copyright 1994 Apple Computer, Inc, All Rights Reserved // Basic constants that we may or may not need constant kAppName := '|SerialEx:PIEDTS|; constant kAppSymbol := '|SerialEx:PIEDTS|; // This is our protoEndpoint specification. Note we are // using DefConst so the symbol is known as a constant when // we compile the proto, and later use it during runtime. DefConst('protoLlamaPEndpoint, { // basic endpoint proto _proto: protoEndpoint, // Options (array stored inside the configOptions slot. configOptions: [ // basic serial port { label: kCMSAsyncSerial, type: 'service, opCode: opSetRequired }, // basic serial port options { label: kCMOSerialIOParms, type: 'option, opCode: opSetNegotiate, data: { bps: k9600bps, dataBits: k8DataBits, stopBits: k1StopBits, parity: kNoParity } }, // flow control (XON/XOFF) { label: kCMOInputFlowControlParms, type: 'option, opCode: opSetNegotiate, data: { xonChar: unicodeDC1, xoffChar: unicodeDC3, useSoftFlowControl: true, useHardFlowControl: nil } }, ], // Our exception handler (asynch exceptions from the endpoint). exceptionHandler: func(exception) begin print("Got the exception from Abort, ignoring it for the time being"); end, // Our state machines: // WaitForAck, main dispatcher, waits for the first ACK from the other side. waitForACK: { InputForm: 'string, endCharacter: $?, // ACK? expected discardAfter: 200, // scan buffer size InputScript: func(endpoint, s) begin if (StrPos(s, "ACK?", 0)) then // send response (help instructions in this case) begin endpoint:Output("Send any of the following commands:" & unicodeCR & unicodeLF, nil); endpoint:Output("PLAY! -- will play a tone on the Newton" & unicodeCR & unicodeLF, nil); endpoint:Output("Add more comments if more functions...." & unicodeCR & unicodeLF, nil); endpoint:FlushOutput(); endpoint:SetInputSpec(endpoint.waitForFUNCTION); // the main dispatch loop end end, }, // This is the generic dispatcher state, send something ending with ! and // the Newton will serve. waitForFUNCTION: { InputForm: 'string, endCharacter: $!, // expects a '!' as part of the command discardAfter: 200, // scan buffer size InputScript: func(endpoint, s) begin if(StrPos(s, "PLAY!", 0)) then // play function begin PlaySound(ROM_funbeep); endpoint:Output(unicodeCR, nil); endpoint:Output(unicodeLF, nil); endpoint:FlushOutput(); end; end; }, }); // ---- End Project Data ---- // ---- File baseView.t ---- baseView := {title: "Serial Example 1.0", viewBounds: {left: 0, top: 2, right: 236, bottom: 334}, viewFormat: 83951953 , viewSetupFormScript: func() begin // Make sure the screen is adjusted to MP and MP110. constant kMaxAppWidth := 240 ; // original MP width constant kMaxAppHeight:= 336 ; // original MP height local b := GetAppParams() ; // Make view no bigger than the original MP. viewBounds := RelBounds(b.appAreaLeft, b.appAreaTop, MIN(b.appAreaWidth, kMaxAppWidth), MIN(b.appAreaHeight, kMaxAppHeight)); end, ep: nil, DisposeEndpointScript: // Dispose our endpoint gracefully func() begin :DisplayInfo("About to flush..."); ep:FlushInput (); ep:FlushOutput (); :DisplayInfo("Flush OK, now zap inputspecs"); ep.nextInputSpec := nil; ep:SetInputSpec(nil); :DisplayInfo("InputSpec handling OK, now Abort"); ep:Abort(); :DisplayInfo("Abort OK, now delayed action later..."); AddDelayedAction(func() begin // let the endpoint clean up from the abort before disconnecting and disposing ep:Disconnect(); ep:Dispose(); ep := nil; end, [], 1000); end, viewQuitScript: func() begin if ep <> nil then :DisposeEndpointScript(); // get rid of any active endpoints end, displayInfo: func(string) begin SetValue(infoView, 'text, string); end, _proto: protoApp, debug: "baseView" }; ConnectButton := /* child of baseView */ {text: "Connect", buttonClickScript: // Make the initial connection and start listening/sending. func() begin local anErr := nil; if commState = 'Disconnected then // create a new connectioin :ConnectScript(); else if commState = 'Connected then // we want to disconnect the connection begin :DisconnectScript(); end; end, viewBounds: {left: 66, top: 218, right: 158, bottom: 238}, commState: // this keeps track of our current communication state 'Disconnected, ConnectScript: func() begin // Create an endpoint for our use, protoLlamaPEndpoint is // defined inside the Project Data file. ep := {_proto: protoLlamaPEndpoint, _parent: self}; // We added the parent slot for parent inheritance inside // the endpoint frame. if ep = nil then :Notify(kNotifyAlert, EnsureInternal("SerialEx"), EnsureInternal("Could not create an endpoint in RAM")); else :DisplayInfo("Created an endpoint in RAM"); :DisplayInfo("About to Instantiate"); // Initialize the endpoint. anErr := ep:Instantiate(ep, nil); if anErr then begin :Notify(kNotifyAlert, EnsureInternal("SerialEx"), EnsureInternal("Sorry, serial port in use!")); return; end; else :DisplayInfo("Initialized the endpoint."); // Do a Connect. anErr := ep:Connect(nil,nil); if anErr then begin :Notify(kNotifyAlert, EnsureInternal("SerialEx"), EnsureInternal("Couldn't connect, check cable and other end!")); return; end; else :DisplayInfo("Connected to the other side."); // Set the Next Input Specification. ep:SetInputSpec(ep.waitForACK); // We are using one single button, so change the text to disconnect SetValue(self, 'text, "Disconnect"); commState := 'Connected; end, DisconnectScript: func() begin :DisposeEndpointScript(); // We are using one single button, so change the text to Connect SetValue(self, 'text, "Connect"); commState := 'Disconnected; end, _proto: protoTextButton, debug: "ConnectButton" }; infoView := /* child of baseView */ {text: "Information View", viewBounds: {left: 16, top: 24, right: 224, bottom: 176}, viewJustify: 0, viewFormat: 67109200, _proto: protoStaticText, debug: "infoView" }; // View infoView is declared to baseView // ---- Beginning of section for non used Layout files ---- // End of output