ports.h File Reference

#include <stdio.h>
#include <mi32/stddefns.h>
#include <mi32/fixedstr.h>

Include dependency graph for ports.h:

Include dependency graph

Go to the source code of this file.

Classes

struct  MPORT
struct  MPORTTYPE
struct  PortChannel

Defines

#define LIBEXPORT   MI_DLLIMPORT
#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_Buffered   0x0003
#define PORTMODE_Command   PORTMODE_Secondary
#define PORTMODE_Compressed   0x0010
#define PORTMODE_Data   (PORTMODE_Secondary|PORTMODE_NOT)
#define PORTMODE_DoubleBuf   0x0001
#define PORTMODE_HighSpeed   0x0004
#define PORTMODE_NonBlocking   0x0200
#define PORTMODE_NOT   0x8000
#define PORTMODE_Secondary   0x0080
#define PORTMODE_SingleBuf   0x0002
#define PORTMODE_SingleStream   0x0020
#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_GPIB   0x0004
#define PORTTYPE_IKON   0x0040
#define PORTTYPE_LPT   0x0001
#define PORTTYPE_MACBACK   0x0800
#define PORTTYPE_PAP   0x0200
#define PORTTYPE_PIPE   0x0080
#define PORTTYPE_SCSI   0x0010
#define PORTTYPE_SPOOLER   0x0100
#define PORTTYPE_VPI110   0x0020
#define PORTTYPE_WINPRINT   0x0400

Functions

LIBEXPORT MPORTTYPE_MserialGetClassDef (void)
int MpAbort (MPORT *port)
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 MpInterfaceCommand (MPORT *port, const char *cmd, int len)
int MpIsFile (const char *type, const char *name)
int MpIsFileUC (const char *type, const UNICODE *name)
int MpLastStatus (MPORT *port)
MPORTMpOpen (const char *name, MPORTTYPE *type, const char *parms, UINT32 mode)
int MpRead (MPORT *port, void *buf, int maxlen, char *term)
int MpReset (MPORT *port)
int MpSetMode (MPORT *port, int mode)
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)
LIBEXPORT int MserialClose (MPORT *port)
LIBEXPORT int MserialFlush (MPORT *port)
LIBEXPORT int MserialGetLastError (MPORT *port)
LIBEXPORT int MserialGetStatus (MPORT *port)
LIBEXPORT int MserialHasDataAvail (MPORT *port)
LIBEXPORT int MserialLastStatus (MPORT *port)
LIBEXPORT int MserialOpen (MPORT **port, const char *name, const char *parms, UINT32 mode)
LIBEXPORT int MserialRead (MPORT *port, void *buf, int maxlen)
LIBEXPORT int MserialReset (MPORT *port)
LIBEXPORT int MserialSetParms (MPORT *port, int baud, int data, int parity, int stop, int flow)
LIBEXPORT int MserialSetParmsString (MPORT *port, const char *parmstr)
LIBEXPORT void MserialSetQueueSize (int insize, int outsize)
LIBEXPORT int MserialWrite (MPORT *port, const void *buf, int len)
int MxPortGetSettings (Widget pwidget, MPORTTYPE *porttype, char *portoptions)
int MxpWrite (MPORT *port, const void *buf, int numbytes, void *status, int line)

Variables

MPORTTYPEMpPortTypeList []


Define Documentation

#define LIBEXPORT   MI_DLLIMPORT
 

Definition at line 335 of file ports.h.

#define MAXPORTCHANNEL   2
 

Channels 0 - 2.

Definition at line 208 of file ports.h.

#define MSERIALBAUD_1200   1200
 

Definition at line 309 of file ports.h.

#define MSERIALBAUD_19_2K   19200
 

Definition at line 313 of file ports.h.

#define MSERIALBAUD_2400   2400
 

Definition at line 310 of file ports.h.

#define MSERIALBAUD_300   300
 

Definition at line 307 of file ports.h.

#define MSERIALBAUD_38_4K   28400
 

Definition at line 314 of file ports.h.

#define MSERIALBAUD_4800   4800
 

Definition at line 311 of file ports.h.

#define MSERIALBAUD_57_6K   57600
 

Definition at line 315 of file ports.h.

#define MSERIALBAUD_600   600
 

Definition at line 308 of file ports.h.

#define MSERIALBAUD_9600   9600
 

Definition at line 312 of file ports.h.

#define MSERIALDATABITS_7   7
 

Definition at line 317 of file ports.h.

#define MSERIALDATABITS_8   8
 

Definition at line 318 of file ports.h.

#define MSERIALFLOW_Hardware   0
 

Definition at line 298 of file ports.h.

#define MSERIALFLOW_NoCTSDSR   3
 

Definition at line 301 of file ports.h.

#define MSERIALFLOW_None   2
 

Definition at line 300 of file ports.h.

#define MSERIALFLOW_XonXoff   1
 

Definition at line 299 of file ports.h.

#define MSERIALPARITY_Even   2
 

Definition at line 305 of file ports.h.

#define MSERIALPARITY_None   0
 

Definition at line 303 of file ports.h.

#define MSERIALPARITY_Odd   1
 

Definition at line 304 of file ports.h.

#define MSERIALSTOPBITS_1   1
 

Definition at line 320 of file ports.h.

#define MSERIALSTOPBITS_1_5   3
 

Definition at line 322 of file ports.h.

#define MSERIALSTOPBITS_2   2
 

Definition at line 321 of file ports.h.

#define PORTMODE_Buffered   0x0003
 

Single or double.

Definition at line 285 of file ports.h.

#define PORTMODE_Command   PORTMODE_Secondary
 

Definition at line 295 of file ports.h.

#define PORTMODE_Compressed   0x0010
 

Do LZW compression.

Definition at line 287 of file ports.h.

#define PORTMODE_Data   (PORTMODE_Secondary|PORTMODE_NOT)
 

Definition at line 296 of file ports.h.

#define PORTMODE_DoubleBuf   0x0001
 

Definition at line 283 of file ports.h.

#define PORTMODE_HighSpeed   0x0004
 

else via DOS

Definition at line 286 of file ports.h.

#define PORTMODE_NonBlocking   0x0200
 

Do not block on read.

Definition at line 291 of file ports.h.

#define PORTMODE_NOT   0x8000
 

Clear the given flags.

Definition at line 292 of file ports.h.

#define PORTMODE_Secondary   0x0080
 

Use secondary port (command/print).

Definition at line 289 of file ports.h.

#define PORTMODE_SingleBuf   0x0002
 

Definition at line 284 of file ports.h.

#define PORTMODE_SingleStream   0x0020
 

Single stream has command/data.

Definition at line 288 of file ports.h.

#define PORTMODE_UnicodeName   0x0100
 

Name is Unicode.

Definition at line 290 of file ports.h.

#define PORTSTAT_Abort   0x8000
 

Definition at line 279 of file ports.h.

#define PORTSTAT_DiskFull   0x0100
 

for files only

Definition at line 280 of file ports.h.

#define PORTSTAT_Error   0x0008
 

Definition at line 274 of file ports.h.

#define PORTSTAT_NotReady   0x0080
 

Definition at line 277 of file ports.h.

#define PORTSTAT_OffLine   0x0010
 

Definition at line 275 of file ports.h.

#define PORTSTAT_OutOfPaper   0x0020
 

Definition at line 276 of file ports.h.

#define PORTSTAT_TimeOut   0x0001
 

Definition at line 278 of file ports.h.

#define PORTTYPE_COM   0x0002
 

Definition at line 261 of file ports.h.

#define PORTTYPE_FILE   0x0008
 

Definition at line 263 of file ports.h.

#define PORTTYPE_GPIB   0x0004
 

Definition at line 262 of file ports.h.

#define PORTTYPE_IKON   0x0040
 

Definition at line 266 of file ports.h.

#define PORTTYPE_LPT   0x0001
 

Definition at line 260 of file ports.h.

#define PORTTYPE_MACBACK   0x0800
 

Macintosh PrGeneral back door hack.

Definition at line 271 of file ports.h.

#define PORTTYPE_PAP   0x0200
 

Macintosh Printer Access Protocol.

Definition at line 269 of file ports.h.

#define PORTTYPE_PIPE   0x0080
 

via popen()

Definition at line 267 of file ports.h.

#define PORTTYPE_SCSI   0x0010
 

Definition at line 264 of file ports.h.

#define PORTTYPE_SPOOLER   0x0100
 

lp or lpr using popen()

Definition at line 268 of file ports.h.

#define PORTTYPE_VPI110   0x0020
 

Definition at line 265 of file ports.h.

#define PORTTYPE_WINPRINT   0x0400
 

Windows printer driver.

Definition at line 270 of file ports.h.


Function Documentation

LIBEXPORT MPORTTYPE* _MserialGetClassDef void   ) 
 

For ports.c only!

int MpAbort MPORT port  ) 
 

Abort current operation and close port.

Parameters:
port  Port to perform operation on

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 MIPS.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_GPIB PORTTYPE_FILE PORTTYPE_SCSI PORTTYPE_VPI110 PORTTYPE_UNIXPORT (as in "/dev/lp0")
Parameters:
num  Numeric port type

int MpInit void   ) 
 

Initialize the port library.

This function initializes the MicroImages Port routines.

int MpInterfaceCommand MPORT port,
const char *  cmd,
int  len
 

Send a command to the interface (for SCSI).

This function will send a command to the interface. So far, it's only used for SCSI and ignored for all other port types. For SCSI, this function is used to send a CDB before an MpRead or MpWrite. Note, this function won't actually write the CDB until you call MpRead() or MpWrite(). To send a command that is nothing but a CDB, call this function followed by MpWrite() with a length of 0.

Parameters:
port  Port to perform operation on
cmd  Command to send
len  Length of command

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 UNICODE 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 char *  name,
MPORTTYPE type,
const char *  parms,
UINT32  mode
 

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 MIPS.INI. Normally, just pass NULL for this paramter.

SCSI: Port names are platform specific. For Windows, they're "SCSIn" where "n" is a digit from 0 to 7. For Unix, you have to pass the name of a character mode special device in the /dev directory (eg: /dev/scsi/sc0d1l0 is SCSI device 1 on the SGI).

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
 

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.

SCSI: Note that for SCSI read commands, you must send a CDB by calling MpInterfaceCommand() before calling MpRead().

Parameters:
port  Port to read from
buf  Buffer to read into
maxlen  Max to read
term  List of terminators

int MpReset MPORT port  ) 
 

GENERATING_DOXYGEN_OUTPUT.

Returns:
Port status.
Parameters:
port  Port to reset

int MpSetMode MPORT port,
int  mode
 

Set the mode of a port.

Returns:
The new mode (may not be same as you set).
This function will allow you to set the mode of the port. The new mode will be OR'd with the current mode, so you don't have to set all the flags every time you call MpSetMode. Some flags are mutual exclusive (eg DoubleBuf and SingleBuf), and setting one will automatically cancel the other. Any of the modes can be turned off by setting that mode OR'd with PORTMODE_NOT. (eg, PORTMODE_Buffered|PORTMODE_NOT)

PORTMODE_Buffered Single or double PORTMODE_Secondary Use secondary port (command/print) PORTMODE_SingleStream See MpWrite() for details PORTMODE_NOT Clear the given flags

Some of these modes may be set by using MpSetParms when it's rewritten.

Parameters:
port  Port to perform operation on
mode  Mode to set

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 MIPS.INI. The last user selected parameters for each port are stored in MIPS.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 (SCSI) 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

SCSI: A pointer to a SCSI Sense Block is returned in the "status" parameter. DO NOT FREE IT! Also be aware that the data in this Sense Block may change after calling other functions on the port. This Sense Block is obtained by sending a REQUEST SENSE (CDB command 0).

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.

Notes for SCSI implementation: This command is used to send DATA only. To send a CDB, use MpInterfaceCommand(), followed by MpWrite(). An alternative method is to open the port with PORTMODE_SingleStream (or set it using MpSetMode).

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 SCSI and GPIB 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
 

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.

LIBEXPORT int MserialClose MPORT port  ) 
 

Close a serial port.

This function is equivalent to the Mp function but assumes the port is a serial port. This function is also in misystem.

Parameters:
port  Serial port to close

LIBEXPORT int MserialFlush MPORT port  ) 
 

Flush a serial port.

Returns:
Serial port status.
This function is equivalent to the Mp function but assumes the port is a serial port. This function is in misystem.
Parameters:
port  Serial port to flush

LIBEXPORT int MserialGetLastError MPORT port  ) 
 

Return last error code for a port.

This function is equivalent to the Mp function but assumes the port is a serial port. This function is in misystem.

Parameters:
port  Serial port, may be NULL

LIBEXPORT int MserialGetStatus MPORT port  ) 
 

Get status of a serial port (asks the OS).

Returns:
Status code (See MpStatus()).
This function is equivalent to the MpStatus function but assumes the port is a serial port and doesn't have a 2nd parameter. This function is in misystem.
Parameters:
port  Serial port to get the status of

LIBEXPORT int MserialHasDataAvail MPORT port  ) 
 

See if a port has data available for reading.

Returns:
1 if any data available, 0 if not, < 0 for error.
Check to see if a port has any incoming data. This function is in misystem.
Parameters:
port  Serial port to check

LIBEXPORT int MserialLastStatus MPORT port  ) 
 

Return last known status for a serial port.

Returns:
Status code (See MpStatus()).
This function is equivalent to the Mp function but assumes the port is a serial port. This function is in misystem.

LIBEXPORT int MserialOpen MPORT **  port,
const char *  name,
const char *  parms,
UINT32  mode
 

Open a serial port.

The only valid mode is PORTMODE_UnicodeName if the name passed is really Unicode. This function is almost equivalent to the Mp function but assumes the port is a serial port. This function is in misystem.

Parameters:
port  Serial port returned
name  Serial port name (eg: "com1:")
parms  Default parms (eg: ":9600:8:none:1:hardware:")

LIBEXPORT int MserialRead MPORT port,
void *  buf,
int  maxlen
 

Read from a serial port.

Returns:
Bytes read >= 0; 0 if no data read.
This function is equivalent to the Mp function but assumes the port is a serial port. This function is in misystem.
Parameters:
port  Serial port to read from
buf  Buffer to read into
maxlen  Max to read

LIBEXPORT int MserialReset MPORT port  ) 
 

Reset a serial port.

This function is equivalent to the Mp function but assumes the port is a serial port. This function is in misystem.

Parameters:
port  Serial port to reset

LIBEXPORT int MserialSetParms MPORT port,
int  baud,
int  data,
int  parity,
int  stop,
int  flow
 

Set serial port parameters given numeric values.

This function is in misystem. It's designed to replace MserialSetParmsString for cases where you don't really want to form a string just to pass it. The #defined constants are mostly logical, so you don't have to use them. For example, the following are equivalent: MserialSetParms(port, MSERIALBAUD_57_6K, MSERIALDATABITS_8, MSERIALPARITY_None, MSERIALSTOPBITS_1, MSERIALFLOW_Hardware) MserialSetParms(port, 57600, 8, 0, 1, MSERIALFLOW_Hardware); The constants are #defined in ports.h

Parameters:
port  Serial port to set parameters on
baud  MSERIALBAUD_Xxxx
data  MSERIALDATABITS_Xxxx
parity  MSERIALPARITY_Xxxx
stop  MSERIALSTOPBITS_Xxxx
flow  MSERIALFLOW_Xxxx

LIBEXPORT int MserialSetParmsString MPORT port,
const char *  parmstr
 

Set port parameters from a string (like MpSetParms).

This function is equivalent to the MpSetParms function but assumes the port is a serial port. This function is in misystem.

Parameters:
port  Serial port to perform operation on
parmstr  Parameters to set

LIBEXPORT void MserialSetQueueSize int  insize,
int  outsize
 

Set the size of the input and output queues.

Sets the size of the input/output buffers in bytes. These values will be used for subsiquent MserialOpen()s.

This function is equivalent to the Mp function but assumes the port is a serial port. This function is in misystem.

Parameters:
insize  Input buffer size
outsize  Output buffer size

LIBEXPORT int MserialWrite MPORT port,
const void *  buf,
int  len
 

Write data to a serial port.

Returns:
Bytes written >= 0; 0 if no data written.
This function is equivalent to the Mp function but assumes the port is a serial port. This function is in misystem.
Parameters:
port  Serial port to write to
buf  Buffer to send
len  Length of buffer

int MxPortGetSettings Widget  pwidget,
MPORTTYPE porttype,
char *  portoptions
 

Create dialog for port settings.

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

MPORTTYPE* MpPortTypeList[]
 


Generated on Tue Dec 14 13:19:11 2004 for TNTsdk by  doxygen 1.3.8-20040913