Home > Palm > Tutorial > Serial
 
  Palm Tutorial
Serial

Palm Tutorial

 Objective

To use Serial Manager to send and receive data over the serial port.

 Concepts

Serial communication

Like in any form of communication, you need senders and receivers. Here, we'll deal with one client that sends requests to a server, which in turn sends a reply to the client. Each of those two guys will have to send and receive something.

APIs

Here's the small collection of APIs we'll use. It's only a subset of Serial Manager's APIs, but it's actually the functions that you will most likely use for serial comms:

  • SrmOpen(logical_port, baud_rate, &port)
  • SrmSend(port, buffer, number_of_bytes, &error_code)
  • SrmReceive(port, buffer, number_of_bytes, timeout_ticks, &error_code)
  • SrmSendFlush(port)
  • SrmReceiveFlush(port, timeout)
  • SrmClose(port)

 Exercise

Download the ZIP file.

This apps runs on POSE as a client. The server is written in Java and is included in the tutorial. On client UI, you'll be able to request current date, current time, or simulate a communication error with the server. The server replies accordingly by sending date, time or an error message. Server UI just displays incoming requests and outgoing replies.

In serial.h:

  • add following IDs for our buttons: MainDownloadDate, MainDownloadTime, MainDownloadCrap
  • add that one for our reply field: MainReply

In serial.rcp:

  • add "Date" button with ID MainDownloadDate (refer to how UI looks on top of this page)
  • add "Time" button with ID MainDownloadTime
  • add "Crap" button with ID MainDownloadCrap
  • add "Reply" field with ID MainReply (it's LEFTALIGN NONEDITABLE UNDERLINED and MAXCHARS 100)
  • add VERSION 1 "1.0.0"
  • add LAUNCHERCATEGORY ID 1000 "Tutorial"

In serial.c:

  • declare variable port as a UInt16 and set it to zero
  • in MainFormHandleEvent()/case MainDownloadDate, flush receive port: SrmReceiveFlush(port, 0);
  • and send "DATE" request: SrmSend(port, "DATE\n", 5, &err);
  • a bit further, flush send port: SrmSendFlush(port);
  • and receive data: SrmReceive(port, ptr, 1, 10, &err)
  • in MainFormHandleEvent()/case MainDownloadTime, flush receive port as above
  • and send "TIME" command
  • in AppStart(), add this blocklet of code to open port and launch main form:
    if ((retcode = SrmOpen(serPortCradlePort, 115200, &port)) == 0)
       FrmGotoForm(MainForm);
  • in AppStop(), close all open forms and close comm port:
    FrmCloseAllForms();
    retcode = SrmClose(port);

In Serial.java:

  • you don't need to do anything, it's ready to use :)

Make the app. On your desktop double-click on Serial.bat (or run 'java Serial <port>' from a command prompt) to execute the server Java class, THEN run this client app on POSE. Argument <port> must match POSE setting (usually 6416).

 Solution

Here's the ZIP file.

And here's how the app should like:

Server
(Desktop)
Client
(Palm)
Palm Tutorial
Palm Tutorial

Next topic

 
[ Copyright © 2000- Eric Poncet - All rights reserved ]

[ Stage de musique classique | Stage de musique baroque | Stage de musique de chambre | Stage de musique latine ]
[ Stage de jazz | Stage de musiques actuelles | Stage de funk | Stage de metal | Stage de pop | Stage de reggae | Stage de rock ]
[ Stage d'improvisation | Colonie musicale ]