|
|||||||
|
|
![]() |
|
|
Display AS/400 Data on a PDA by Shannon O'Donnell [The code for this article is available for download.] If your company is like many others, it is likely that your users are starting to use PDAs for such things as checking e-mail or surfing the Web. It's only a matter of time before those users come knocking on your office door requesting that you provide them with data access to your AS/400 from their PDA. In this article, I'll show you a way to retrieve and display AS/400 data on a Pocket PC 2002 PDA. The Pieces We will use a Pocket PC 2002 device to connect to an AS/400 server, via a TCP/IP Socket, and then retrieve some data and display it on a PDA. We'll develop the client (PDA) application in Microsoft eMbedded Visual Basic 3.0 (eVB) and use RPG IV on an AS/400 to build our Sockets server program. The device I used for testing for this article is a Compaq iPaq 3850 running the Windows Pocket PC 2002 operating system, although it is likely that you can use a different device running the Windows Pocket PC 2000 OS, or even the Palm PDA, and everything will work fine. One of the nice things about programming for handheld devices is that you can download the compilers and software development kits from Microsoft for free. Even better, you can download an emulator for multiple PDA operating systems (like Pocket PC 2002 or Palm) from Microsoft, also for free. To obtain the software development kit for eMbedded Visual Basic, go to the Microsoft Mobile Devices page. Simply download the eMbedded Visual Basic SDK and install it on your PC. You will want to download the emulators as well. To develop the code, you can use the free SDK you downloaded. However, to test it, you will need a PDA running the Pocket PC 2002 operating system. For most applications you develop with eVB, you can use the SDK's emulator and you'll be fine. However, there is a bug in the eVB emulator that won't allow you to test the Winsock (Windows Sockets) control. So, for this article, you'll need an actual PDA connected to your development PC. The eVB Code The code for connecting to your AS/400 from your PDA is pretty simple. It's basically an eVB form with a listbox control, a couple of label controls and a push button control on it. In addition, we'll add the Winsock control to the form and use that control to connect to the AS/400. To begin, open the eVB integrated development environment (IDE) tool and create a new project for the Windows Pocket PC 2002 operating system. Next, on the default form that appears, add a listbox control and a push button control. The control toolbox should already be visible in the IDE, so it's easy to drag and drop the controls you want onto the form. If the control toolbox is not visible, click the IDE menu item named View, then click the Toolbox submenu item. If you are not sure which control is which in the toolbox, simply move your mouse over each control and the name of that control will appear. To add the Winsock control to the toolbox, which we'll use to connect to the AS/400 via a TCP/IP Socket, click the IDE menu item named Project, then click the submenu item named Components. Select the component named Microsoft CE Winsock Control 3.0, then click the OK button. This will add the Winsock control to the toolbox. Click the Winsock control in the toolbox and drag it to the form. Finally, click the Label control and drag two instances of this control to the form. Place one instance of the Label control just above your listbox control, and the other just below it. We are now ready to add the code. Copy and paste the code into your eVB project. A Word About Sockets We will connect to the AS/400 via a TCP/IP Socket. A Socket can be thought of as a conduit or a pipeline between two TCP/IP connected devices. In this case, the two devices will be your AS/400 and your PDA. Every time you connect two TCP/IP devices, you are connecting via a Socket. When you telnet from your PC to your AS/400 using Client Access 5250, you are using a Socket, connecting on port 23. When you FTP to and from your AS/400 to a PC or to another AS/400, you are passing the data back and forth over a Socket, on port 21. A Socket is nothing more than a virtual pipe between two systems. When using a Socket, you specify what system you want to connect to and what port on that system you want to connect to. A port, then, can be thought of as a door or an entry point to that system. In the Microsoft development world, Sockets are contained in the ActiveX object named Winsock.DLL. Within that Winsock.DLL, which you added to your project earlier in this article, are properties that you can set to control which system you wish to connect to and what port you want to connect on. Now let's see how the eVB code works. The eVB Code In the Form_Load() subroutine of the code, we set the caption for the Label controls and the push button control, and we add an entry to the listbox control with the text empty. . .. This will be a visual cue to the user that there is nothing in the list when the application first starts. The Form_OKClick() subroutine is executed when the user clicks the OK button in the top-right corner of the application. Every PDA application will have this OK button, which is equivalent to the X box used for closing a Windows application. The Command1_Click() subroutine is executed when the user clicks the push button control. In this subroutine, we set the RemoteHost and RemotePort properties of the Winsock control. In this example, I am using RemoteHost and giving it a name that I've already associated with an IP address in the Windows HOSTS file. If you want, you can use the actual IP address instead. If you use the IP address, use the RemoteIP property, rather than the RemoteHost property. The port we'll use is 5090. This is an arbitrary port, and you can use anything you want here. Just make sure that whatever port you use is also the port you'll be listening on in the RPG IV Socket server program running on your AS/400 (more on that later). The next step is to connect to the server. We do that by issuing the connect property command for the Winsock control. For the connect to work, you must have a Socket server program running on the remote system and the remote port identified earlier in this subroutine. Once a connection is established, we set the caption of the second label control to indicate to our users that they are connected to the remote host. The Winsock1_Connect() subroutine is executed once you are connected to the remote system. We'll use it here to send some data to the remote server, so that it knows that we want to do something. In a "real world" application, you'd probably want some information indicating the type of data you want to retrieve, or something more appropriate. In this example, it doesn't really matter what we send, just as long as we send something. The Winsock1_DataArrival() subroutine is executed when you've connected to a remote system and that remote system has sent your device some data. Before you can use that data, you must retrieve it from the Socket. You do this by using the GetData property of the Winsock control. The rest of the code in this subroutine simply extracts the customer names from the raw data string retrieved off the Socket, and then adds it to the listbox. In our example, the customer names are sent as one long string, separated by a colon (:). You can use any scheme you like to send and parse your own data. That's it for the eVB code. Now let's take a look at the RPG IV code. The Socket Server The RPG IV program uses a few Unix-type APIs to bind to a specific TCP/IP port, which we set to port 5090 for this example, and then "listens" for requests on that port. Once a client requests a connection, the Socket server program will accept that request and read the data from the Socket. (This is the data we sent in the Winsock1_Connect() subroutine.) Since the data is coming from a PC, we must translate it from ASCII to EBCDIC before we can use it. This is accomplished via a call to the QDCXLATE translation API. Finally, the Socket server program will write, or send, the list of customer names to the remote device over the Socket, which will in turn activate the Winsock1_DataArrival() subroutine on the PDA. Note that we must first translate the data from EBCDIC back to ASCII before we send it to the remote device, in order for that data to be used on the remote device. Either that or you'll have to translate it on the PDA for the user to be able to read it. It's easier to do it on the AS/400. I did not write the RPG IV program included with this article. It was originally written by Scott Klement and presented as part of the RPG IV Sockets Tutorial on his Web site. I merely modified it for this article. For a complete understanding of what the program is doing and, more important, why the program is doing it, and to learn more about Sockets programming in general, see the RPG IV Sockets Tutorial. Bringing It All Together Compile the RPG IV program included with this article and call it from a command line or submit it to batch. Next, ensure that your Pocket PC 2002 device is in its cradle and that the cradle is connected to your development PC. Finally, click the Run menu item, from the eVB IDE. You should see a screen similar to that shown in Figure 1. When you click the List Customers button, you should get a list of the customer names from the RPG IV Sockets server program.
Once you have the project working and have tested it, compile it (Make) and export it to your company PDAs. As long as your PDA can connect to your AS/400 via some means (either wirelessly, using a wireless network card, or through a modem, using an external PDA modem), you can allow your users to retrieve data from your AS/400 and display it on their PDA. At my shop, we use a wireless network and the PDA has a special adapter for a PC card, into which we insert a wireless network card. That way we can surf the Web, check e-mail, display AS/400 DB2/400 data or whatever from the PDA, from anywhere in the office. You can take the basic technique presented in this article and expand on it to retrieve actual data from a DB2/400 database or to retrieve pretty much any other data or message or diagnostic information from your AS/400. With a little practice and a little imagination, you can take this basic example and build some unique and useful applications. Editor's Note: For more information on wireless communication between your PDA and the iSeries, check out the series of articles written by Marc Logemann.
|
Editors
Contact the Editors |
| Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved. |