TweetFollow Us on Twitter

Jun 97 - Newton Q and A

Volume Number: 13 (1997)
Issue Number: 6
Column Tag: develop

Newton Q&A: Ask the Llama

by Apple Developer Technical Support Group

Q: I'm probably missing something obvious, but when I try to use an asynchronous output call in some situations, I get an exception, while synchronous calls seem to work fine. For instance, this code fails consistently with bus errors:

endpoint:output(headerCache,
   nil,
   {async: true,
   form: 'string,
   completionScript: func(ep, options, result)
      self:SendData(endpoint, qfCursor)});

On the other hand, this code works fine:

endpoint:output(headerCache, nil, nil);
self:SendData(endpoint, qfCursor);

I'd really prefer to use asynchronous calls, but I keep running into problems. Do you have any suggestions?

A: The key thing you're missing is that self (that is, the receiver) is not what you expect in your asynchronous callback. In your first example, you pass a completion frame as the third argument of the Output message. It's this frame that will be self (that is, that will be the context of the completionScript). This means that you send the sendData message to that completion frame.

What you probably want is to send the message to the ep argument passed to the completionScript. This will be the endpoint to which you sent the Output message. In general, you will have set this endpoint to have a _parent slot that points to your application. Assuming that the sendData method is in either the endpoint or your application, you would modify the body of the completionScript to be

ep:sendData(endpoint, qfCursor);

The same restrictions apply for Input and Option calls as well.


Q: I have a pop-up view that has an icon with some text, and I'd like the user to be able to edit the icon. I call MakeShape on the icon and draw it into a bitmap. I then have an interface for the user to modify the icon. The problem occurs when I try to display the modified icon in the pop-up. It either doesn't show up, has incorrect bounds, or throws an exception. Before I modify the icon, it looks like something that would be returned by GetPictAsBits:

{data: <bits, Length 42>, bounds: {0,0,15,15}, }

Once I call MakeShape on the icon, it looks like this:

{class: bitmap, bounds: <boundsRect, Length 8>,
   data: <pixels, Length 54>, }

The pop-up chokes on this when I try to display it. First it threw an exception because it was expecting a frame instead of a binary object in the bounds frame. So I called SetBounds to set the bounds frame to {0,0,15,15}. This enabled the pop-up to open, but the icon wasn't in the right place. Fiddling with the bounds frame didn't seem to help. So I'm guessing that the next problem is that I have pixels instead of bits in the data slot. I tried calling SetClass on the slot to change it from pixels to bits. That actually didn't throw an exception, but the length is still different and it didn't look right. How can I get my shape or bitmap back into a form that the pop-up will be happy with?

A: The basic problem is that the binary object used by MakeShape to represent the picture (that is, <pixels, Length 54>) is not the same as that used in the bitmap structure (<bits, Length 42>). You have a couple of choices. Since the formats are documented, you can write some code to convert the object returned by MakeShape into a NewtonScript bitmap object. The other option, which seems more complex but is probably easier to implement, is to use the MakeShape representation only for your icon editor. Let the user modify the MakeShape representation, but keep track of the changes and use them to modify the bitmap. So, while the user is editing the icon, there will be two data objects: the original icon representation using the bitmap data structure and the MakeShape representation that the user sees and modifies. As the user changes the MakeShape object, your code is also modifying the bitmap object.

As a related side note, you can use DrawIntoBitmap to get the bits that represent the shape.


Q: In an application I'm building, I want to keep a serial communication session open with a GPS unit 24 hours a day, unattended by the user. Both the MessagePad and the GPS unit are powered by the car. The GPS unit sends out data approximately every two seconds. I'm using the "Basic Serial" Newton DTS sample code as the starting point. The communications code in the application works fine except that occasionally I get a -18003 exception, which results in a kMessage_BufferOverrun message. I've tried turning on useSoftFlowControl and useHardFlowControl in the kCMOInputFlowControlParms parameter frame inside the MBuildConfigOptions method, but that doesn't seem to help.

Can you explain when/why this exception is raised? Can I safely ignore the exception by revising the MNotifyError method? What can I do to prevent the occurrence of the exception in the first place?

A: A -18003 error can indicate several things, including bad parity or a framing error. Usually it indicates that the Newton's UART (SCC chip) buffer has overrun. You can just ignore this error, repost the input specification, and go on your merry way.

To repost the input specification, call the endpoint's SetInputSpec with the relevant input specification. Before reposting the input specification, you may also want to flush the communication tools buffers using the serial discard data option (kCMOSerialDiscard) and flush the NewtonScript buffer with FlushInput. Regardless of whether you flush, you will have lost some data in the process, although for most GPS applications that should be fine. You may also want to try increasing the size of the serial input buffer; this might give you just enough time to process all the data.

A better solution would be to have the GPS receiver support some type of flow control, though this will depend on the manufacturer of the unit.


Q: I have a view with a protoKeyboard button. The input lines within the view all take numeric input, and when the user double-taps, the numeric keypad pops up. But the keyboard button brings up the full QWERTY keyboard instead. How can I make the button open the numeric keypad?

A: The keyboard button is behaving correctly. If you don't specify which keyboard to open, it will always open the global alphanumeric keyboard. There are two ways you can get the behavior you want:

  • Override the 'defaultKeyboard slot in your protoKeyboardButton. This slot contains the keyboard that you want to use. In this case you want the symbol 'numericKeyboard, which specifies the default numeric keyboard.
  • Override the buttonClickScript in the protoKeyboardButton. You can use the OpenKeypadFor function and specify your input line as the view. This will usually do the right thing since calling OpenKeypadFor has just about the same effect as the user's double-tapping in an input line.

Q: I noticed that the NTK project preferences dialog lets you compress your application. How much slower will the application run if I do this?

A: Unfortunately, there's no simple answer to this question. The speed of execution depends on a number of factors, including how many times the system has to uncompress pages from your application into a cache and how full the system heap is.

The best way to find out is to try your application with the three different compression options: none, compressed, or faster compression. Make sure that you perform your tests a number of times and under different memory-loading conditions. If your application will be doing communications, that's a good thing to test. You can also use HeapShow (which comes with NTK) to fill the system and NewtonScript heaps to simulate low-memory conditions.

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

PUBG Mobile teams up with global phenome...
Since launching in 2019, SpyxFamily has exploded to damn near catastrophic popularity, so it was only a matter of time before a mobile game snapped up a collaboration. Enter PUBG Mobile. Until May 12th, players will be able to collect a host of... | Read more »
Embark into the frozen tundra of certain...
Chucklefish, developers of hit action-adventure sandbox game Starbound and owner of one of the cutest logos in gaming, has released their roguelike deck-builder Wildfrost. Created alongside developers Gaziter and Deadpan Games, Wildfrost will... | Read more »
MoreFun Studios has announced Season 4,...
Tension has escalated in the ever-volatile world of Arena Breakout, as your old pal Randall Fisher and bosses Fred and Perrero continue to lob insults and explosives at each other, bringing us to a new phase of warfare. Season 4, Into The Fog of... | Read more »
Top Mobile Game Discounts
Every day, we pick out a curated list of the best mobile discounts on the App Store and post them here. This list won't be comprehensive, but it every game on it is recommended. Feel free to check out the coverage we did on them in the links below... | Read more »
Marvel Future Fight celebrates nine year...
Announced alongside an advertising image I can only assume was aimed squarely at myself with the prominent Deadpool and Odin featured on it, Netmarble has revealed their celebrations for the 9th anniversary of Marvel Future Fight. The Countdown... | Read more »
HoYoFair 2024 prepares to showcase over...
To say Genshin Impact took the world by storm when it was released would be an understatement. However, I think the most surprising part of the launch was just how much further it went than gaming. There have been concerts, art shows, massive... | Read more »
Explore some of BBCs' most iconic s...
Despite your personal opinion on the BBC at a managerial level, it is undeniable that it has overseen some fantastic British shows in the past, and now thanks to a partnership with Roblox, players will be able to interact with some of these... | Read more »
Play Together teams up with Sanrio to br...
I was quite surprised to learn that the massive social network game Play Together had never collaborated with the globally popular Sanrio IP, it seems like the perfect team. Well, this glaring omission has now been rectified, as that instantly... | Read more »
Dark and Darker Mobile gets a new teaser...
Bluehole Studio and KRAFTON have released a new teaser trailer for their upcoming loot extravaganza Dark and Darker Mobile. Alongside this look into the underside of treasure hunting, we have received a few pieces of information about gameplay... | Read more »
DOFUS Touch relaunches on the global sta...
After being a big part of a lot of gamers - or at the very least my - school years with Dofus and Wakfu, Ankama sort of shied away from the global stage a bit before staging a big comeback with Waven last year. Now, the France-based developers are... | Read more »

Price Scanner via MacPrices.net

Sunday Sale: 13-inch M3 MacBook Air for $999,...
Several Apple retailers have the new 13″ MacBook Air with an M3 CPU in stock and on sale today for only $999 in Midnight. These are the lowest prices currently available for new 13″ M3 MacBook Airs... Read more
Multiple Apple retailers are offering 13-inch...
Several Apple retailers have 13″ MacBook Airs with M2 CPUs in stock and on sale this weekend starting at only $849 in Space Gray, Silver, Starlight, and Midnight colors. These are the lowest prices... Read more
Roundup of Verizon’s April Apple iPhone Promo...
Verizon is offering a number of iPhone deals for the month of April. Switch, and open a new of service, and you can qualify for a free iPhone 15 or heavy monthly discounts on other models: – 128GB... Read more
B&H has 16-inch MacBook Pros on sale for...
Apple 16″ MacBook Pros with M3 Pro and M3 Max CPUs are in stock and on sale today for $200-$300 off MSRP at B&H Photo. Their prices are among the lowest currently available for these models. B... Read more
Updated Mac Desktop Price Trackers
Our Apple award-winning Mac desktop price trackers are the best place to look for the lowest prices and latest sales on all the latest computers. Scan our price trackers for the latest information on... Read more
9th-generation iPads on sale for $80 off MSRP...
Best Buy has Apple’s 9th generation 10.2″ WiFi iPads on sale for $80 off MSRP on their online store for a limited time. Prices start at only $249. Sale prices for online orders only, in-store prices... Read more
15-inch M3 MacBook Airs on sale for $100 off...
Best Buy has Apple 15″ MacBook Airs with M3 CPUs on sale for $100 off MSRP on their online store. Prices valid for online orders only, in-store prices may vary. Order online and choose free shipping... Read more
24-inch M3 iMacs now on sale for $150 off MSR...
Amazon is now offering a $150 discount on Apple’s new M3-powered 24″ iMacs. Prices start at $1149 for models with 8GB of RAM and 256GB of storage: – 24″ M3 iMac/8-core GPU/8GB/256GB: $1149.99, $150... Read more
15-inch M3 MacBook Airs now on sale for $150...
Amazon is now offering a $150 discount on Apple’s new M3-powered 15″ MacBook Airs. Prices start at $1149 for models with 8GB of RAM and 256GB of storage: – 15″ M3 MacBook Air/8GB/256GB: $1149.99, $... Read more
The latest Apple Education discounts on MacBo...
If you’re a student, teacher, or staff member at any educational institution, you can use your .edu email address when ordering at Apple Education to take up to $300 off the purchase of a new MacBook... Read more

Jobs Board

Retail Assistant Manager- *Apple* Blossom Ma...
Retail Assistant Manager- APPLE BLOSSOM MALL Brand: Bath & Body Works Location: Winchester, VA, US Location Type: On-site Job ID: 04225 Job Area: Store: Management Read more
Housekeeper, *Apple* Valley Village - Cassi...
Apple Valley Village Health Care Center, a senior care campus, is hiring a Part-Time Housekeeper to join our team! We will train you for this position! In this role, Read more
Sonographer - *Apple* Hill Imaging Center -...
Sonographer - Apple Hill Imaging Center - Evenings Location: York Hospital, York, PA Schedule: Full Time Sign-On Bonus Eligible Remote/Hybrid Regular Apply Now See Read more
Senior Software Engineer - *Apple* Fundamen...
…center of Microsoft's efforts to empower our users to do more. The Apple Fundamentals team focused on defining and improving the end-to-end developer experience in Read more
New RN Case Manager *Apple* Valley ,CA 40 h...
$50-55/hr Apple Valley, CA Amergis HEALTHCARE STAFFING NEW RN Case Manager is responsible for coordinating continuum of care activities for assigned patients and Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.