mi32/ports.h File Reference

#include <stdio.h>
#include <mi32/fixedstr.h>
#include <mi32/genericrw.h>
Include dependency graph for ports.h:

Go to the source code of this file.

Classes

struct  MPORT
struct  MPORTTYPE
 Forward declaration to prevent annoying warnings from compiler. More...
class  PORT
struct  PortChannel

Defines

#define MAXPORTCHANNEL   2
#define MSERIALBAUD_1200   1200
#define MSERIALBAUD_19_2K   19200
#define MSERIALBAUD_2400   2400
#define MSERIALBAUD_300   300
#define MSERIALBAUD_38_4K   28400
#define MSERIALBAUD_4800   4800
#define MSERIALBAUD_57_6K   57600
#define MSERIALBAUD_600   600
#define MSERIALBAUD_9600   9600
#define MSERIALDATABITS_7   7
#define MSERIALDATABITS_8   8
#define MSERIALFLOW_Hardware   0
#define MSERIALFLOW_NoCTSDSR   3
#define MSERIALFLOW_None   2
#define MSERIALFLOW_XonXoff   1
#define MSERIALPARITY_Even   2
#define MSERIALPARITY_None   0
#define MSERIALPARITY_Odd   1
#define MSERIALSTOPBITS_1   1
#define MSERIALSTOPBITS_1_5   3
#define MSERIALSTOPBITS_2   2
#define PORTMODE_NonBlocking   0x0200
#define PORTMODE_NOT   0x8000
#define PORTMODE_UnicodeName   0x0100
#define PORTSTAT_Abort   0x8000
#define PORTSTAT_DiskFull   0x0100
#define PORTSTAT_Error   0x0008
#define PORTSTAT_NotReady   0x0080
#define PORTSTAT_OffLine   0x0010
#define PORTSTAT_OutOfPaper   0x0020
#define PORTSTAT_TimeOut   0x0001
#define PORTTYPE_COM   0x0002
#define PORTTYPE_FILE   0x0008
#define PORTTYPE_LPT   0x0001
#define PORTTYPE_MACBACK   0x0800
#define PORTTYPE_PIPE   0x0080
#define PORTTYPE_SPOOLER   0x0100
#define PORTTYPE_WINPRINT   0x0400

Functions

 DEPRECATED_MSG ("There's a version that takes MISTRING for the name now") MPORT *MpOpen(const char *name
int MpClose (MPORT *port)
int MpComHasDataAvail (MPORT *port)
void MpComSetQueueSize (int InputSize, int OutputSize)
int MpFlush (MPORT *port)
int MpGetLastError (MPORT *port)
MPORTTYPEMpGetPortTypeByName (const char *name)
MPORTTYPEMpGetPortTypeByNumber (int num)
int MpInit (void)
int MpIsFile (const char *type, const char *name)
int MpIsFileUC (const char *type, const MIUNICODE *name)
int MpLastStatus (MPORT *port)
MPORTMpOpen (const MISTRING &name, const MPORTTYPE *type, const char *parms=0, UINT32 mode=0)
int MpRead (MPORT *port, void *buf, int maxlen, char *term=0)
int MpSetParms (MPORT *port, const char *parms)
int MpStatus (MPORT *port, char **status)
int MpWrite (MPORT *port, const void *buf, int len)
int MpWriteExt (MPORT *port, const void *buffer, int len, UINT32 flags=0)
int MxPortGetSettings (Widget pwidget, MPORTTYPE *porttype, char *portoptions)
int MxpWrite (MPORT *port, const void *buf, int numbytes, void *status, int line)

Variables

const MPORTTYPE const char UINT32 mode
MPORTTYPEMpPortTypeList []
const MPORTTYPE const char * parms = 0
const MPORTTYPEtype

Define Documentation

#define MAXPORTCHANNEL   2

Channels 0 - 2.

#define MSERIALBAUD_1200   1200
#define MSERIALBAUD_19_2K   19200
#define MSERIALBAUD_2400   2400
#define MSERIALBAUD_300   300
#define MSERIALBAUD_38_4K   28400
#define MSERIALBAUD_4800   4800
#define MSERIALBAUD_57_6K   57600
#define MSERIALBAUD_600   600
#define MSERIALBAUD_9600   9600
#define MSERIALDATABITS_7   7
#define MSERIALDATABITS_8   8
#define MSERIALFLOW_Hardware   0
#define MSERIALFLOW_NoCTSDSR   3
#define MSERIALFLOW_None   2
#define MSERIALFLOW_XonXoff   1
#define MSERIALPARITY_Even   2
#define MSERIALPARITY_None   0
#define MSERIALPARITY_Odd   1
#define MSERIALSTOPBITS_1   1
#define MSERIALSTOPBITS_1_5   3
#define MSERIALSTOPBITS_2   2
#define PORTMODE_NonBlocking   0x0200

Do not block on read.

#define PORTMODE_NOT   0x8000

Clear the given flags.

#define PORTMODE_UnicodeName   0x0100

Name is Unicode.

#define PORTSTAT_Abort   0x8000
#define PORTSTAT_DiskFull   0x0100

for files only

#define PORTSTAT_Error   0x0008
#define PORTSTAT_NotReady   0x0080
#define PORTSTAT_OffLine   0x0010
#define PORTSTAT_OutOfPaper   0x0020
#define PORTSTAT_TimeOut   0x0001
#define PORTTYPE_COM   0x0002
#define PORTTYPE_FILE   0x0008
#define PORTTYPE_LPT   0x0001
#define PORTTYPE_MACBACK   0x0800

Macintosh PrGeneral back door hack.

#define PORTTYPE_PIPE   0x0080

via popen()

#define PORTTYPE_SPOOLER   0x0100

lp or lpr using popen()

#define PORTTYPE_WINPRINT   0x0400

Windows printer driver.


Function Documentation

DEPRECATED_MSG ( "There's a version that takes MISTRING for the name now"   )  const

Open a port.

This routine will open a port. To get the MPORTTYPE structure needed in the second parameter, use MpGetPortTypeByName or MpGetPortTypeByNumber. The mode flags are listed in MpSetMode. The parms parameter is used to override the default parameters in tntproc.ini. Normally, just pass NULL for this paramter.

int MpClose ( MPORT port  ) 

Close a port.

This routine closes the port and frees the buffers. You MUST do an MpFlush before closing the port.

Parameters:
port Port to close
int MpComHasDataAvail ( MPORT port  ) 

Determine if data available for reading.

Returns:
TRUE if data available, FALSE if none, < 0 if error.
void MpComSetQueueSize ( int  InputSize,
int  OutputSize 
)

Set input/output queue sizes for COM ports.

int MpFlush ( MPORT port  ) 

Flush a buffered port.

Returns:
Port status.

This routine flushes the buffers for a buffered port. If the returned status is not 0, the port has not been flushed, and you should flush it again.

Parameters:
port Port to flush
int MpGetLastError ( MPORT port  ) 

Return last error that occurred for a port.

Parameters:
port Port, may be NULL
MPORTTYPE* MpGetPortTypeByName ( const char *  name  ) 

Get a MPORTTYPE given a port type name.

Returns:
Pointer to the MPORTTYPE structure needed in MpOpen() or NULL if no such port type exists.

This routine takes the name of a port type and returns the corresponding MPORTTYPE structure. This name may be stored in tntproc.ini. It is also returned by MpSelectPort.

Parameters:
name Name of port type
MPORTTYPE* MpGetPortTypeByNumber ( int  num  ) 

Get a MPORTTYPE given a port type number.

Returns:
Pointer to the MPORTTYPE structure needed in MpOpen() or NULL if no such port type exists.

PORTTYPE_LPT PORTTYPE_COM PORTTYPE_FILE

Parameters:
num Numeric port type
int MpInit ( void   ) 

Initialize the port library.

This function initializes the MicroImages Port routines.

int MpIsFile ( const char *  type,
const char *  name 
)

Is file really a "file" ?

Returns:
1 if a given file is really a "file", 0 if it's really a device (eg: LPT1: or /dev/tty0).
int MpIsFileUC ( const char *  type,
const MIUNICODE name 
)

Is file really a "file" -- Unicode version ?

Returns:
1 if a given file is really a "file", 0 if it's really a device (eg: LPT1: or /dev/tty0).
int MpLastStatus ( MPORT port  ) 

Return the last known status for a port.

Returns:
The last status value without querying the device.
MPORT* MpOpen ( const MISTRING name,
const MPORTTYPE type,
const char *  parms = 0,
UINT32  mode = 0 
)

Open a port.

This routine will open a port. To get the MPORTTYPE structure needed in the second parameter, use MpGetPortTypeByName or MpGetPortTypeByNumber. The mode flags are listed in MpSetMode. The parms parameter is used to override the default parameters in tntproc.ini. Normally, just pass NULL for this paramter.

Parameters:
name Name of port/file to open
type Type of port to use
parms Parameters
mode Mode flags
int MpRead ( MPORT port,
void *  buf,
int  maxlen,
char *  term = 0 
)

Read from a port.

Returns:
Bytes read >= 0; 0 if no data read.

WARNING: This function does NOT return error codes, 0 will be returned if no data is read.

This function will read data from a given port. If term is NULL, it acts like a normal read() function. If term is not NULL, it should contain a NULL-terminated string containing terminators. For example, if term contains "\n\t ", MpRead will read up to the next newline, tab, or space, but not more than maxlen chars. The terminator itself will also be read.

NOTE: The "term" argument hasn't been implemented, and is currently ignored. GENERATING_DOXYGEN_OUTPUT

Parameters:
port Port to read from
buf Buffer to read into
maxlen Max to read
term List of terminators
int MpSetParms ( MPORT port,
const char *  parms 
)

Set port specific parameters.

This routine allows you to set parameters for a given port. The values of the parms parameter is dependant on the port, but should always be in the following format:

:parm1:parm2:parm3:

This string may be stored in tntproc.ini. The last user selected parameters for each port are stored in tntproc.ini and automatically used when you call MpOpen. This function is only here to allow you to override them.

Example: :9600:8:none:1: for a "serial_port", this means 9600 baud, 8 data bits, no parity, and 1 stop bit.

Parameters:
port Port to perform operation on
parms Parameters to set
int MpStatus ( MPORT port,
char **  status 
)

Get the status of a port.

Returns:
Status code.

This function will query the port and return its status. Some types of ports return detailed status information. The status codes shown below are bits, so it's possible to get more than one at a time. If the status string is not wanted, pass NULL for status.

Possible status codes returned: 0 OK PORTSTAT_Error Some error has occured PORTSTAT_OffLine The printer is off-line PORTSTAT_OutOfPaper The printer is out of paper PORTSTAT_NotReady The printer is busy PORTSTAT_Abort

Parameters:
port Port to perform operation on
status Pointer to status RETURNED
int MpWrite ( MPORT port,
const void *  buf,
int  len 
)

Write to a port.

Returns:
Bytes written >= 0; 0 if no data written.

WARNING: This function does NOT return error codes, 0 will be returned if no data is written.

This function will write data to the given port. If the port is buffered, it might not actually send unless the buffer fills up or until you call MpFlush. If the status returned is not 0, the port is busy and the write has been buffered. In this case, you should call MpFlush() until it returns a status of 0 or until the user gets bored and goes home. If len is -1, buf is assumed to be a NULL-terminated string.

If the PORTMODE_SingleStream flag is set, the data is assumed to be wrapped as follows...

<CC> <HH> <LL> <Data....>

Where CC is the channel number (0 == CDB, 1 == DATA) to write to, HH and LL are the high and low-bytes of the length to write. In this mode, data is buffered until the full length is recieved and is then sent all at once. This is useful for where data has to be sent in fixed size chunks. A data block can span multiple calls to MpWrite(). MpWrite() will write at most one block per call. If a buffer contains multiple blocks, MpWrite() will write the first block then return a count indicating how many bytes were written. It is up to the caller to call MpWrite again with the rest of the buffer (possibly checking MpStatus() between calls). Also, to send just a CDB (eg reset command) using this method, you have to send the CDB in channel 0, followed by a 0-byte data block on channel 1.

Parameters:
port Port to write to
buf Buffer to send
len Length of buffer
int MpWriteExt ( MPORT port,
const void *  buffer,
int  len,
UINT32  flags = 0 
)

Same as MpWrite() but if the port becomes busy, will add a message to the current status handle (if any) and check the cancle button.

int MxPortGetSettings ( Widget  pwidget,
MPORTTYPE porttype,
char *  portoptions 
)

Create dialog for port settings.

INC_MI32_PORTS_H

int MxpWrite ( MPORT port,
const void *  buf,
int  numbytes,
void *  status,
int  line 
)

Write to a port with status and/or error dialogs.

Returns:
0 or EUserCancel.

This function is like MpWrite(), but it will keep trying if the port is busy. If there is an error on the port, the error is displayed in the status dialog in the specified line. If line is == -1, then "status" is used as the parent widget for a Retry/Cancel dialog instead of as a status dialog.

Parameters:
port Port to write to (see MpOpen)
buf Buffer of stuff to write
numbytes Number of bytes to write
status Status dialog
line Line in status dialog to put errors in

Variable Documentation

const MPORTTYPE const char UINT32 mode
Initial value:
 0
   )

Mode flags.

const MPORTTYPE const char* parms = 0

Parameters.

const MPORTTYPE* type

< Name of port/file to open

Type of port to use


Generated on Sun Oct 7 21:27:44 2012 for TNTsdk 2012 by  doxygen 1.6.1