SerialMgr.h
declares the serial manager API. For more information on the new serial manager, see the chapter "Serial Communication" in the Palm OS Programmer's Companion.
DeviceInfoType
structure defines information about a serial device. This structure is returned by the
SrmGetDeviceInfo
function.
typedef struct DeviceInfoType {
UInt32 serDevCreator;
UInt32 serDevFtrInfo;
UInt32 serDevMaxBaudRate;
UInt32 serDevHandshakeBaud;
Char *serDevPortInfoStr;
UInt8 reserved[8]; // Reserved
} DeviceInfoType;
typedef DeviceInfoType *DeviceInfoPtr;
serDevCreator
| Four-character creator type for serial driver ('sdrv'). |
serDevFtrInfo
| Flags defining features of this serial hardware. Specify one of the flags described in Serial Capabilities Constants. |
serDevMaxBaudRate
| Maximum baud rate for this device. |
serDevHandshakeBaud
| Hardware handshaking is recommended for baud rates over this rate. |
serDevPortInfoStr
| Description of serial hardware device or virtual device. |
SrmCtlEnum
enumerated type specifies a serial control operation. Specify one of these enumerated types for the op
parameter to the
SrmControl
call.
typedef enum SrmCtlEnum {
srmCtlFirstReserved = 0, // RESERVE 0
srmCtlSetBaudRate,
srmCtlGetBaudRate,
srmCtlSetFlags,
srmCtlGetFlags,
srmCtlSetCtsTimeout,
srmCtlGetCtsTimeout,
srmCtlStartBreak,
srmCtlStopBreak,
srmCtlStartLocalLoopback,
srmCtlStopLocalLoopback,
srmCtlIrDAEnable,
srmCtlIrDADisable,
srmCtlRxEnable,
srmCtlRxDisable,
srmCtlEmuSetBlockingHook,
srmCtlUserDef,
srmCtlGetOptimalTransmitSize,
srmCtlLAST
} SrmCtlEnum;
srmCtlSetBaudRate
| Sets the current baud rate for the serial hardware. |
srmCtlGetBaudRate
| Gets the current baud rate for the serial hardware. |
srmCtlSetFlags
| Sets the current flag settings for the serial hardware. Specify flags from the set described in Serial Settings Constants. |
srmCtlGetFlags
| Gets the current flag settings for the serial hardware. |
srmCtlSetCtsTimeout
| Sets the current CTS timeout value for hardware handshaking. |
srmCtlGetCtsTimeout
| Gets the current CTS timeout value for hardware handshaking. |
srmCtlStartBreak
| Turn RS232 break signal on. Caller is responsible for turning this signal on and off and insuring it is on long enough to generate a viable break. |
srmCtlStopBreak
| Turn RS232 break signal off. |
srmCtlStartLocalLoopback
| Start local loopback test. |
srmCtlStopLocalLoopback
| Stop local loopback test. |
srmCtlIrDAEnable
| Enable IrDA connection on this serial port. |
srmCtlIrDADisable
| Disable IrDA connection on this serial port. |
srmCtlRxEnable
| Enable receiver (for IrDA). |
srmCtlRxDisable
| Disable receiver (for IrDA). |
srmCtlEmuSetBlockingHook
| Set a blocking hook routine for emulation mode only. Not supported on the Palm device. |
srmCtlUserDef
|
This is a user-defined function that 3rd party hardware developers can use to set or retrieve hardware-specific information from the serial driver. This opCode invokes the SdrvControl (or VdrvControl ) function with its user-defined opCode and the parameters are passed directly through to the serial driver. A serial driver that does not handle this function returns a serErrBadParam error.
|
srmCtlGetOptimalTransmitSize
| Ask the port for the most efficient buffer size for transmitting data packets. This opCode returns an error (buffering not necessary), 0 (buffering requested, but application can choose buffer size), or a number > 0 (recommended buffer size). |
SrmCallbackEntryType
structure defines a callback function for the
SrmControl
function's srmCtlEmuSetBlockingHook
opCode.
typedef struct SrmCallbackEntryType {
BlockingHookProcPtr funcP;
UInt32 userRef; // ref value to pass to callback
} SrmCallbackEntryType;
funcP
|
Function pointer to the callback function. Pass NULL if you no longer want a callback function to be called.
|
userRef
| User-defined reference value passed to the callback function. |
SrmGetStatus
function.
Err SrmClearErr(UInt16 portId)
Err SrmClose(UInt16 portID)
SrmOpen
).
SrmOpen
,
SrmOpenBackground
Err SrmControl(UInt16 portId, UInt16 op, void *valueP, UInt16 *valueLenP)
  |
-> |
Port ID. |
  |
-> |
Control operation to perform. Specify one of the SrmCtlEnum enumerated types. |
  |
<-> |
Pointer to a value to use for the operation. See Comments for details. |
  |
<-> |
Pointer to the size of *valueP . See Comments for details. |
valueP
and valueLenP
parameters for each of the operation codes. Control codes not listed do not use these parameters.
Operation Code | Parameters |
---|---|
srmCtlSetBaudRate
|
-> valueP = Pointer to Int32 (baud rate)
-> valueLenP = Pointer to sizeof(Int32)
|
srmCtlGetBaud
|
<- valueP = Pointer to Int32 (baud rate)
<- valueLenP = Pointer to Int16
|
srmCtlSetFlags
|
-> valueP = Pointer to Uint32 (bitfield; see Serial Settings Constants)
-> valueLenP = Pointer to sizeof(UInt32)
|
srmCtlGetFlags
|
<- valueP = Pointer to UInt32 (bitfield)
<- valueLenP = Pointer to Int16
|
srmCtlSetCtsTimeout
|
-> valueP = Pointer to Int32 (timeout value)
-> valueLenP = Pointer to sizeof(Int32)
|
srmCtlGetCtsTimeout
|
<- valueP = Pointer to Int32 (timeout value)
<- valueLenP = Pointer to Int16
|
srmCtlEmuSetBlockingHook
|
<-> valueP = Pointer to SrmCallbackEntryType struct
<-> valueLenP = Pointer to sizeof(SrmCallbackEntryType)
Returns the old settings in the first parameter.
|
srmCtlUserDef
|
<-> valueP = Pointer passed to the serial or virtual driver
<-> valueLenP = Pointer to sizeof(Int32)
For a serial driver, these pointers are passed to the SdrvControl function's sdrvOpCodeUserDef opCode. For a virtual driver, these pointers are passed to the VdrvControl function's vdrvOpCodeUserDef opCode.
|
srmCtlGetOptimalTransmitSize
|
<- valueP = Pointer to Int32
<- valueLenP = Pointer to sizeof(Int32)
If an error is returned by SrmControl , no buffering should be done. If valueP points to zero, buffering is requested, but the transmitting application can determine the buffer size. If valueP points to a number > 0, then try to send data in blocks of this number of bytes, as this is the most efficient block size for this particular device.
|
Err SrmGetDeviceCount(UInt16* numOfDevicesP)
  |
<- |
Pointer to address where the number of serial devices is returned. |
SrmGetDeviceInfo
Err SrmGetDeviceInfo(UInt32 deviceID, DeviceInfoType* deviceInfoP)
  |
<- |
Pointer to a DeviceInfoType structure where information about the device is returned. |
SrmGetDeviceCount
Err SrmGetStatus(UInt16 portId, UInt32* statusFieldP), UInt16* lineErrsP)
  |
-> |
Port ID. |
  |
<- |
Pointer to address where hardware status information for the port is returned. This is a 32-bit field using the flags described in Status Constants. |
  |
<- |
Pointer to address where the number of line errors for the port is returned. |
SrmGetStatus
is called to retrieve the line errors for the port if some of the send and receive functions return a serErrLineErr
error code.
Err SrmOpen(UInt32 port, UInt32 baud, UInt16* newPortIdP)
  |
-> |
Port name or logical port number to be opened. For information about how to identify a port, see "Specifying the portID Parameter" in the Palm OS Programmer's Companion. |
  |
-> |
Initial baud rate of port. |
  |
<- |
Pointer to address where the port ID to be used with other new serial manager functions is returned. |
SrmOpenBackground
SrmOpen
call.
Err SrmOpenBackground(UInt32 port, UInt32 baud, UInt16* newPortIdP)
  |
-> |
Physical or logical port number to be opened. |
  |
-> |
Initial baud rate of port. |
  |
<- |
Pointer to address where the port ID to be used with other new serial manager functions is returned. |
SrmOpen
Err SrmPrimeWakeupHandler(UInt16 portId, UInt16 minBytes)
  |
-> |
Port ID. |
  |
-> |
Number of bytes that must be received before wakeup handler is called. Typically, this is set to 1. |
SrmSetWakeupHandler
.
SrmSetWakeupHandler
,
WakeupHandlerProc
UInt32 SrmReceive(UInt16 portId, void *rcvBufP, UInt32 count, Int32 timeout, Err* errP)
  |
-> |
Port ID. |
  |
<- |
Pointer to buffer where received data is to be returned. |
  |
-> |
Length of data buffer (in bytes). This specifies the number of bytes to receive. |
  |
-> |
The amount of time (in ticks) that the new serial manager waits to receive the requested block of data. At the end of the timeout, data received up to that time is returned. |
  |
<- |
Error code. |
Err SrmReceiveCheck(UInt16 portId, UInt32* numBytesP)
SrmReceive
,
SrmReceiveFlush
,
SrmReceiveWait
Err SrmReceiveFlush(UInt16 portId, Int32 timeout)
timeout
value forces this function to wait a period of ticks after flushing the port to see if more data shows up to be flushed. If more data arrives within the timeout period, the port is flushed again and the timeout counter is reset and waits again. The function only exits after no more bytes are received by the port for the full timeout period since the last flush of the port. To avoid this waiting behavior, specify 0 for the timeout period.
SrmReceive
,
SrmReceiveCheck
,
SrmReceiveWait
Err SrmReceiveWait(UInt16 portId, UInt32 bytes, Int32 timeout)
  |
-> |
Port ID. |
  |
-> |
Number of bytes to wait for. |
  |
-> |
Timeout value, in ticks. |
SrmReceiveCheck
) or it can just specify a buffer and receive the data by calling
SrmReceive
.
SrmReceive
,
SrmReceiveCheck
,
SrmReceiveFlush
Err SrmReceiveWindowClose(UInt16 portId, UInt32 bytesPulled)
  |
-> |
Port ID. |
  |
-> |
Number of bytes the application read from the receive queue. |
SrmReceiveWindowOpen
Err SrmReceiveWindowOpen(UInt16 portId, UInt8 **bufPP, UInt32* sizeP)
  |
-> |
Port ID. |
  |
<- |
Pointer to a pointer to the receive buffer. |
  |
<- |
Available bytes in buffer. |
SrmReceiveWindowClose
.
SrmReceiveWindowOpen
and SrmReceiveWindowClose
functions repeatedly until the buffer size returned is 0.
IMPORTANT: Once an application callsSrmReceiveWindowOpen
, it should not attempt to receive data via the normal method of callingSrmReceive
orSrmReceiveWait
, as these functions interfere with direct access to the receive queue.
SrmReceiveWindowClose
UInt32 SrmSend(UInt16 portId, void *bufP, UInt32 count, Err* errP)
  |
-> |
Port ID. |
  |
-> |
Pointer to data to send. |
  |
-> |
Length of data buffer, in bytes. |
  |
<- |
Error code. See Comments section for details. |
*errP
is NULL
, the result value should be the same as the count
parameter. If *errP
is not NULL
, then the result equals the number of bytes sent before the error occurred.
*errP
:
SrmSendCheck
,
SrmSendFlush
,
SrmSendWait
Err SrmSendCheck(UInt16 portId, UInt32* numBytesP)
SrmSend
,
SrmSendFlush
,
SrmSendWait
Err SrmSendFlush(UInt16 portId)
SrmSend
,
SrmSendCheck
,
SrmSendWait
Err SrmSendWait(UInt16 portId)
SrmSend
,
SrmSendCheck
,
SrmSendFlush
Err SrmSetReceiveBuffer(UInt16 portId, void *bufP, UInt16 bufSize)
  |
-> |
Port ID. |
  |
-> |
Pointer to new receive buffer. Ignored if bufSize is NULL . |
  |
-> |
Size of new receive buffer in bytes. To remove this buffer and allocate a new default buffer (512 bytes), specify NULL . |
IMPORTANT: Applications must install the default buffer before closing the port (or disposing of the new receive queue.)
Err SrmSetWakeupHandler(UInt16 portId, WakeupHandlerProcPtr procP, UInt32 refCon)
  |
-> |
Port ID. |
  |
-> |
Pointer to a WakeupHandlerProc function. Specify NULL to remove a handler. |
  |
-> |
User-defined data that is passed to the wakeup handler function. This can be a pointer or not. |
SrmPrimeWakeupHandler
function. Every time a wakeup handler is called, it must be reprimed (via SrmPrimeWakeupHandler
) in order to be called again.
SrmPrimeWakeupHandler
,
WakeupHandlerProc
void WakeupHandlerProcPtr(UInt32 refCon)
SrmSetWakeupHandler
. The number of bytes after which it is called is specified by
SrmPrimeWakeupHandler
.
SrmPrimeWakeupHandler
,
SrmSetWakeupHandler
  |   |