Serial Link Manager
 

 < Home   < Developers   < Development Support   < Documentation

68 Serial Link Manager


 Table of Contents  |  < Previous  |  Next >  |  Index
   
   

Title -
Palm OS® Programmer's API Reference

Part III: Communications

68 Serial Link Manager

Serial Link Manager Functions

SlkClose

SlkCloseSocket

SlkFlushSocket

SlkOpen

SlkOpenSocket

SlkReceivePacket

SlkSendPacket

SlkSetSocketListener

SlkSocketPortID

SlkSocketSetTimeout

       

This chapter provides reference material for the serial link manager API. The header file SerialLinkMgr.h declares the serial link manager API. For more information on the serial link manager, see the chapter "Serial Communication" in the Palm OS Programmer's Companion, vol. II, Communications.

Serial Link Manager Functions

SlkClose

Purpose

Close down the serial link manager.

Prototype

Err SlkClose (void)

Parameters

None.

Result

0No error.
slkErrNotOpenThe serial link manager was not open.

Comments

When the open count reaches zero, this routine frees resources allocated by serial link manager.

SlkCloseSocket

Purpose

Closes a socket previously opened with SlkOpenSocket.

The caller is responsible for closing the communications library used by this socket, if necessary.

Prototype

Err SlkCloseSocket (UInt16 socket)

Parameters

socketThe socket ID to close.

Result

0No error.
slkErrSocketNotOpenThe socket was not open.

Comments

SlkCloseSocket frees system resources the serial link manager allocated for the socket. It does not free resources allocated and passed by the client, such as the buffers passed to SlkSetSocketListener; this is the client's responsibility. The caller is also responsible for closing the communications library used by this socket.

See Also

SlkOpenSocket

SlkFlushSocket

Purpose

Flush the receive queue of the communications library associated with the given socket.

Prototype

Err SlkFlushSocket (UInt16 socket, Int32 timeout)

Parameters

-> socketSocket ID.
-> timeoutInterbyte timeout in system ticks.

Result

0No error.
slkErrSocketNotOpenThe socket wasn't open.

SlkOpen

Purpose

Initialize the serial link manager.

Prototype

Err SlkOpen (void)

Parameters

None.

Result

0No error.
slkErrAlreadyOpenNo error.

Comments

Initializes the serial link manager, allocating necessary resources. Return codes of 0 (zero) and slkErrAlreadyOpen both indicate success. Any other return code indicates failure. The slkErrAlreadyOpen function informs the client that someone else is also using the serial link manager. If the serial link manager was successfully opened by the client, the client needs to call SlkClose when it finishes using the serial link manager.

SlkOpenSocket

Purpose

Open a serial link socket and associate it with a communications library. The socket may be a known static socket or a dynamically assigned socket.

Prototype

Err SlkOpenSocket (UInt16 portID, UInt16 *socketP, Boolean staticSocket)

Parameters

portIDComm library reference number for socket.
socketPPointer to location for returning the socket ID.
staticSocketIf TRUE, *socketP contains the desired static socket number to open. If FALSE, any free socket number is assigned dynamically and opened.

Result

0No error.
slkErrOutOfSocketsNo more sockets can be opened.

Comments

The communications library must already be initialized and opened (see SerOpen). When finished using the socket, the caller must call SlkCloseSocket to free system resources allocated for the socket. For information about well-known static socket IDs, see The Serial Link Protocol.

SlkReceivePacket

Purpose

Receive and validate a packet for a particular socket or for any socket. Check for format and checksum errors.

Prototype

Err SlkReceivePacket (UInt16 socket, Boolean andOtherSockets, SlkPktHeaderPtr headerP, void* bodyP, UInt16 bodySize, Int32 timeout)

Parameters

-> socketThe socket ID.
-> andOtherSocketsIf TRUE, ignore destination in packet header.
<-> headerPPointer to the packet header buffer (size of SlkPktHeaderType).
<-> bodyPPointer to the packet client data buffer.
-> bodySizeSize of the client data buffer (maximum client data size which can be accommodated).
-> timeoutMaximum number of system ticks to wait for beginning of a packet; -1 means wait forever.

Result

0No error.
slkErrSocketNotOpenThe socket was not open.
slkErrTimeOutTimed out waiting for a packet.
slkErrWrongDestSocketThe packet being received had an unexpected destination.
slkErrChecksumInvalid header checksum or packet CRC-16.
slkErrBufferClient data buffer was too small for packet's client data.

If andOtherSockets is FALSE, this routine returns with an error code unless it gets a packet for the specific socket.

If andOtherSockets is TRUE, this routine returns successfully if it sees any incoming packet from the communications library used by socket.

Comments

You may request to receive a packet for the passed socket ID only, or for any open socket which does not have a socket listener. The parameters also specify buffers for the packet header and client data, and a timeout. The timeout indicates how long the receiver should wait for a packet to begin arriving before timing out. If a packet is received for a socket with a registered socket listener, it will be dispatched via its socket listener procedure. On success, the packet header buffer and packet client data buffer is filled in with the actual size of the packet's client data in the packet header's bodySize field.

SlkSendPacket

Purpose

Send a serial link packet via the serial output driver.

Prototype

Err SlkSendPacket (SlkPktHeaderPtr headerP, SlkWriteDataPtr writeList)

Parameters

<-> headerPPointer to the packet header structure with client information filled in (see Comments).
-> writeListList of packet client data blocks (see Comments).

Result

0No error.
slkErrSocketNotOpenThe socket was not open.
slkErrTimeOutHandshake timeout.

Comments

SlkSendPacket stuffs the signature, client data size, and the checksum fields of the packet header. The caller must fill in all other packet header fields. If the transaction ID field is set to 0 (zero), the serial link manager automatically generates and stuffs a new non-zero transaction ID. The array of SlkWriteDataType structures enables the caller to specify the client data part of the packet as a list of noncontiguous blocks. The end of list is indicated by an array element with the size field set to 0 (zero). This call blocks until the entire packet is sent out or until an error occurs.

SlkSetSocketListener

Purpose

Register a socket listener for a particular socket.

Prototype

Err SlkSetSocketListener (UInt16 socket, SlkSocketListenPtr socketP)

Parameters

-> socketSocket ID.
-> socketPPointer to a SlkSocketListenType structure.

Result

0No error.
slkErrBadParamInvalid parameter.
slkErrSocketNotOpenThe socket was not open.

Comments

Called by applications to set up a socket listener.

Since the serial link manager does not make a copy of the SlkSocketListenType structure, but instead saves the passed pointer to it, the structure

must not be an automatic variable (that is, local variable allocated on the stack)

may be a global variable in an application

may be a locked chunk allocated from the dynamic heap

The SlkSocketListenType structure specifies pointers to the socket listener procedure and the data buffers for dispatching packets destined for this socket. Pointers to two buffers must be specified: the packet header buffer (size of SlkPktHeaderType), and the packet body (client data) buffer. The packet body buffer must be large enough for the largest expected client data size. Both buffers may be application global variables or locked chunks allocated from the dynamic heap.

The socket listener procedure is called when a valid packet is received for the socket. Pointers to the packet header buffer and the packet body buffer are passed as parameters to the socket listener procedure.


NOTE: The application is responsible for freeing the SlkSocketListenType structure or the allocated buffers when the socket is closed. The serial link manager doesn't do it.

SlkSocketPortID

Purpose

Get the port ID associated with a particular socket; for use with the new serial manager.

Prototype

Err SlkSocketPortID (UInt16 socket, UInt16 * portIDP)

Parameters

-> socketThe socket ID.
<-> portIDPPointer to location for returning the port ID.

Result

0No error.
slkErrSocketNotOpenThe socket was not open.

Compatibility

Implemented only if New Serial Manager Feature Set is present.

SlkSocketSetTimeout

Purpose

Set the interbyte packet receive-timeout for a particular socket.

Prototype

Err SlkSocketSetTimeout (UInt16 socket, Int32 timeout)

Parameters

-> socketSocket ID.
-> timeoutInterbyte packet receive-timeout in system ticks.

Result

0No error.
slkErrSocketNotOpenThe socket was not open.