Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Bailey O.H.Embedded systems.Desktop integration.2005

.pdf
Скачиваний:
73
Добавлен:
23.08.2013
Размер:
9.53 Mб
Скачать

460

Chapter 11 / Cross-Platform Application Development

 

 

To fully understand how to access a USB device please review the code listings in the Chapter 11\USB folder available from the download sites. Each listing is very detailed and the C++Builder project files are included so you can get a feel for how to implement true cross-platform libraries in code.

Comparing Delphi/Kylix to C++BuilderX

This topic both concludes developing our middle-tier interface software and serves to lead into developing the user application layer. The products that we’ve used up to this point are all excellent products in their own right. Choosing code development over using a visual editor is not an easy decision to make. Several factors weighed heavily in using C++BuilderX over Delphi/Kylix for the middleware device interface.

The first item was the fact that Kylix does not generate native machine code that can be executed at the device driver level. Kylix has quite a few support libraries that make it an excellent user application development tool. Those same libraries, however, can wreak havoc when attempting to develop kernel or device driver level code.

The second compelling reason for selecting C++BuilderX for the device layer was the ability to add additional compilers along with the numbers of native compilers supported out of the box. The Borland code generators produce code that is of excellent quality. In my years of experience I’ve found Borland’s code quality and execution speed is second to none. But the ability to add other third-party compilers like GNU and even Microsoft Visual C and Intel make it a very versatile product. The flexibility in the C++BuilderX IDE in adding cross-compilers and scripts make it very attractive for the developer who is doing exactly what we are — developing cross-platform libraries from a sin- gle-source code base.

Chapter 11 / Cross-Platform Application Development

461

 

 

The End User Application Layer

Well, we’ve reached the final topic for this book. Our choices for application layer development are somewhat greater than for developing the device interface layer. We can use an integrated IDE like Delphi/C++Builder/Kylix, or an application framework such as wxWindows. C++BuilderX has a preview feature for wxWindows but is far from a full implementation. So let’s examine the pros and cons of each of these development methods.

Delphi/C++Builder/Kylix

These are proven products that are known to work on Linux and Windows and a single-source code base is attainable using the CLX controls. When we venture away from Linux to FreeBSD the certainty of the program executing becomes a bigger question mark. This issue can easily be eliminated by using a product named InstallMade, which rolls up all the required libraries and shared objects to be installed along with the application. As long as the BSD operating system is running in Linux compatibility mode, our program will run.

C++BuilderX

This product is an excellent choice for code-based cross-platform development. Since we are developing a user interface we would need to use an external tool to develop our user interface.

C++Builder allows outside tool integration, so we could integrate a third-party GUI builder. This would allow us to develop the user interface on any platform and simply port it to the other platforms for cross-compilation.

Chapter 11

462

Chapter 11 / Cross-Platform Application Development

 

 

Mono and the .NET Framework

This is a brand new approach to development. Mono 1.1 is currently available, and I have successfully compiled C# code ported from the .NET framework without modifications. A lot of care has to be taken, however, in the use of the available .NET framework features available under Linux. This is a good approach but the framework isn’t quite ready for us.

wxWidgets and DialogBlocks

The wxWindows cross-platform development library for application development was recently renamed wxWidgets. DialogBlocks is a GUI application designer. The output from DialogBlocks can be compiled on any platform that supports the wxWidgets libraries. wxWidgets are strictly C++ so if you’re uncomfortable with C++, don’t use wxWidgets or DialogBlocks.

As you build the user interface with DialogBlocks the header and C++ source files are updated to reflect your changes. An application class is created (sound familiar?) and once your design is finished all that is left is to fill in your event handler code. DialogBlocks is a very powerful designer and is much improved over many commercial products. DialogBlocks runs on the same platforms that wxWidgets supports, including the IBM S390 mainframes.

It’s Time to Develop the User Application

Well, we’re down to the final task of creating the user application. Here is where the payoff of separating the device interface layer from the user application really shows. We are going to take two approaches to the user interface application. One will use the Kylix/Delphi/C++ Builder approach and the other will use the DialogBlocks/wxWidgets/C++BuilderX approach. With the Delphi/Kylix approach we will write a small application using the CLX component libraries. We will demonstrate how to build and distribute an application using this method for both Windows and

Chapter 11 / Cross-Platform Application Development

463

 

 

Linux/UNIX. The second approach will use DialogBlocks to develop a simple application and C++BuilderX to maintain the finished result.

The Delphi Development Effort

There are several versions of Delphi currently on the market. For cross-platform development between Linux and Windows, we will employ Delphi 7 on Windows and Kylix 3 on Linux. Once the applications are developed we will deploy the Windows version using an open source product called the Nullsoft Install System. On Linux we will use a product called InstallMade to package and distribute our program.

1.On Windows, start Delphi 7 and close the current default application. Since it’s empty, don’t save it.

2.Next, choose File | New | CLX Application.

3.Add a file menu, edit box, memo box, push button, and status bar to the application.

4.Double-click the status bar and add two status panels. Next, double-click the menu bar icon and add a new item to the drop-down. Name the main menu item File and the dropdown item Exit.

5.With Exit item selected, choose Events and double-click the OnClick event handler. A new procedure will be generated. At the cursor add the following line:

Application.Terminate;

This will exit the application.

6.Now select the button component and change the text to Add. Again select Events, and double-click on the OnClick event handler and add the following lines:

Memo1.Lines.Add(Edit1.Text);

StatusBar1.Panels.Items[0].Text:= IntToStr(memo1.Lines.Count);

Chapter 11

464

Chapter 11 / Cross-Platform Application Development

 

 

This will add the text in the edit box to the memo box and update the count of lines on the status bar.

7.Now it’s time to run the application. Add some text to the edit box and press Add. You should see the text added to the memo box and the line count incremented in the status bar. Figure 11-5 shows the Windows version.

Figure 11-5

8.Copy (or save) the project to a Linux machine with Kylix 3 installed. Start Kylix and open the project. You will receive an error that Unit1.pas cannot be located in the path. Ignore the error and manually open Unit1.pas. If there is a path in the uses clause, eliminate the path so the line for Unit1 simply says Unit1.

9.Next, compile and run the program. The following should be displayed.

Figure 11-6

Chapter 11 / Cross-Platform Application Development

465

 

 

The program should run unchanged and look similar to the above output. Add text to the memo box and the program should function identically to the Windows version. Remember earlier we created a Windows DLL and Linux shared library for the device interface layer. To access the hardware layer we will add the shred objects to the project along with the definition files if required and write the logic to access the serial, Ethernet, and USB ports.

The wxWidgets Development Effort

Now, we will develop a simple application using wxWidgets and DialogBlocks. To begin we will design the user interface in DialogBlocks.

1.Start DialogBlocks and select Sample Projects from the main screen. A list of projects will be displayed. I chose the NoteBook dialog project shown in Figure 11-7.

Chapter 11

Figure 11-7

466

Chapter 11 / Cross-Platform Application Development

 

 

The far left window pane in Figure 11-7 shows the available components in our current project, the middle pane is our designer, and the right pane contains properties associated with the currently selected design element. The tabs across the top hold the editor, header, source code file, variable definitions, and event handlers. Anything defined within the DialogBlocks context will be in the source files. To add source and header files you need to generate the associated classes; otherwise you will not see any code created. The next step in the process is to create a C++BuilderX project and add the source and header files we just created as shown in the following figure.

Figure 11-8

To compile and build the program with C++BuilderX, we need to also add the wxWidget libraries and add any remaining code and source files. When the project is complete, compile the project and link to the native wxWidget libraries for the chosen platform. wxWidgets takes a slightly different approach to development from Delphi/Kylix. I like to work with both and find Delphi and Kylix excellent products for developing solid

Chapter 11 / Cross-Platform Application Development

467

 

 

applications quickly. I like to use wxWidgets and DialogBlocks when I have to support platforms that Delphi/Kylix don’t support.

Distributing the End Results

Once the hardware prototypes are finished it’s time to distribute the beta kits. There are many products that can be used to create install programs. If you want something that is quick and requires little effort, InstallShield is an excellent Windows product. If you want an installer that makes it easy to distribute and install Kylix programs, InstallMade is a must. InstallMade wraps the program and any required libraries into a single file for distribution and installation. The best part of InstallMade is that it will handle the distribution of OS libraries as well, which itself can be a task for Kylix.

The Sky Is the Limit

I hope this book has started your creative juices flowing. There are endless possibilities on what you can accomplish with the right knowledge. I hope this book combined with the companion files has provided you, the reader, with new ideas and fresh approaches.

Chapter 11

Index

1-Wire devices, 217-220

1-Wire interface, 221-223 connecting to BASIC Stamp 2p,

331-334 implementing, 373-374 PSoC, 420-421 testing, 224-226

3-Wire interface, connecting to BASIC Stamp 2p, 334-341

3-Wire protocol, 220

A

ActiveX controls, 92 alarm,

output, 269-271 wiring, 271-272

application layer, developing, 461-462 ARCNET protocol, 45

asynchronous serial communications, 35-37, 38

B

BASIC Stamp 2p, 253-256 connecting to 1-Wire interface,

331-334

connecting to 3-Wire interface, 334-341

connecting to RS-232 interface, 341-343

connecting to SB72, 309-319 finishing, 343-344

I2C communications support, 264-266

implementation strategy, 258 vs. PIC, 346-347

BASIC Stamp 2p24 device, using, 257 BASIC Stamp board, developing,

259-263

block devices, 71 byte ordering, 35

C

C/C++, considerations for using, 107-109

C++, 136

C++Builder, 134-135, 450, 461 C++BuilderX, 109, 139-141, 451, 461

using, 456-458 vs. Delphi, 460 character devices, 71

circuit boards, building, 192-193

creating printed, 246-251 keyboard, 234-242 RS-232, 203-211

techniques for soldering, 191-192 time and temperature, 217-234 tools for building, 189-191

types of, 186 COM, 92 COM+, 92

communication protocol, 169 communications interface,

implementing, 280-282 communications methods, 32-34 Component Object Model, see COM cross-platform

alternatives, 455 compilers, 131-138

development considerations, 89 development environment, 139-146 language considerations, 103-110 tools, 147-151

cross-platform application development, 447 alternatives to, 101-103

468

Index 469

D

data functions, 84-86 Delphi, 132-133, 450, 461

considerations for using, 107-109 developing user applications with,

463-465

vs. C++BuilderX, 460 design document, 153

embedded system, 154-165 desktop software requirements, 13-14 desktop system functions, 49-50 device driver

design, 59-61 development, 28

portability considerations, 57-58 portability requirements, 74-77 types, 71-74

device interface development, 8 layer, 452-453 requirements, 12-13

device protocol, designing, 49-50 DialogBlocks, 462

DLL, 91 DS2404 chip,

adding to network, 227-229 testing, 229-232

using, 275-277

dsPIC development environment, 359 dsPIC peripheral libraries, 361-365 dsPIC30F2010 processor, 356-357 DSR/DTR handshake, 198 dynamic-link library, see DLL

E

EEPROM vs. static RAM, 279-280 Emacs, 109, 141-144

embedded device, requirements, 11 functional layout, 19-20

embedded processor design, 30-31 embedded system,

communicating with, 32-34 data flow in, 46-49

design, 3-6, 8-9

design document, 154-165 development considerations, 16-18 functional definition, 31 functionality of, 170-179 functions, 49

implementing Ethernet interface in, 282-286

protocol in, 42-45 protocol responses, 52-55 requirements for, 15

etched circuit board, 186 Ethernet interface, 22-25, 166-167

considerations for using, 12-13 functions, 79-80

implementing, 374-375, 453-455 implementing in embedded system,

282-286

OS support for, 63-65 testing, 303-309 using, 358

using with PSoC, 439-444 Ethernet protocol, 45 EZ-USB chip, 406-407

using with PSoC, 429-439

F

fan control output, 269-271 functions,

device-specific, 78-82 Ethernet interface, 79-80 generic, 77-78

I2C, 419

in embedded systems, 49-50 LCD display, 266-268 RS-232 interface, 78-79 USB interface, 80-82

G

GCC, 136-138

GDB, 144-146

GNU Compiler Collection, see GCC GNU compilers, 451

GNU debugger, see GDB GNU licensing, 106 GPL licensing, 106

Index

Соседние файлы в предмете Электротехника