NetBurner 3.1
Serial Interfaces

Modules

 Parity Types
 
 Serial Port Error Codes
 

Macros

#define ADDR_ESCAPE_CHAR   (0xFF)
 Address escape character.
 
#define UART_ERR_BREAK   (0x08)
 
#define SimpleOpenSerial(p, b)   OpenSerial(p, b, 1, 8, eParityNone)
 Simple open a serial port. More...
 

Functions

int OpenSerial (int portnum, unsigned int baudrate, int stop_bits, int data_bits, parity_mode parity)
 Open a serial port. More...
 
int SerialClose (int portnum)
 Close a serial port. More...
 
void SerialEnableTxFlow (int port, int enab)
 Enable transmit software flow control on the specified UART. More...
 
void SerialEnableRxFlow (int port, int enab)
 
void SerialEnableHwTxFlow (int port, int enab)
 
void SerialEnableHwRxFlow (int port, int enab)
 
void Serial485HalfDupMode (int port, int enab)
 
void SendBreak (int port, uint32_t time)
 
int serwriteaddress (int fd, const char c)
 
int GetUartErrorReg (int fd)
 
BOOL SerialSendComplete (int fd)
 

Detailed Description

The NetBurner Serial Group

Macro Definition Documentation

◆ SimpleOpenSerial

#define SimpleOpenSerial (   p,
 
)    OpenSerial(p, b, 1, 8, eParityNone)

Simple open a serial port.

Select the UART number and baud rate, default paramters will be 1 stop bit, no parity, 8 data bits.

Parameters
portnumThe UART to open. First port is 0. The maximum number is platform dependent
baudrateThe speed of the serial port in bits per second
See also
OpenSerial()

◆ UART_ERR_BREAK

#define UART_ERR_BREAK   (0x08)

Definitions used to represent bits of the UART error register. These are associated with the GetUartErrorReg() function, which is only applicable to the MOD5270, SB70 and SB72.

Function Documentation

◆ GetUartErrorReg()

int GetUartErrorReg ( int  fd)

Gets the UART error register. This is only applicable on select platforms. Any errors are added to this register in a logical OR operation. Calling this function to read the error status will clear the register.

Bit Description


3 Received break 2 Framing error 1 Parity error 0 Overrun error

fd - The file descriptor associated with the UART serial port whose error register is to be retreived.

return - The value of the error register if successful (positive int - the bitwise values are represented by the UART_ERR_* definitions found near the top of this file); otherwise, one of the error codes is returned: SERIAL_ERR_NOSUCH_PORT (-1) SERIAL_ERR_PORT_NOTOPEN (-2)

◆ OpenSerial()

int OpenSerial ( int  portnum,
unsigned int  baudrate,
int  stop_bits,
int  data_bits,
parity_mode  parity 
)

Open a serial port.

This function opens a serial port. Note that funtions to open a serial port, such as OpenSerial() and SimpleOpenSerial(), must be called before any functions or pin assignments that configure the operation of the serial port. You must also configure all pins that have the same UART capability. For example, if UART 1 TX can be configured to come out on more than one pin (as a second or third alternate function), you must set those pins to some function other than UART 1 TX. This is because the functions that open a serial port will configure all serial port functions to default operation and default pins. For example, hardware flow control will be off, and the default pin assignments will be used on those platform that have multiple outputs.

Parameters
portnumThe UART to open. First port is 0. The maximum number is platform dependent
baudrateThe speed of the serial port in bits per second
stop_bitsThe number of stop bits, 1 or 2
data_bitsThe number of data bits sent per character or frame: 5, 6, 7 or 8
parityThe type of parity checking to use: eParityNone, eParityEven, eParityOdd or eParityMulti
Returns
The file descriptor of the serial port ( > 0), or Serial Port Error Codes
See also
SimpleOpenSerial()

◆ SendBreak()

void SendBreak ( int  port,
uint32_t  time 
)

Sets a break in the UART transmission for a given period of time. The break starts when character transmission completes. The break is delayed until any character in the transmitter shift register is sent. Any character in the transmitter holding register is sent after the break.

port - The UART whose transmitter will be forced low (start break). time - Specifies the amount of time in ticks that the break will hold; when time expires, the break will be stopped; 20 ticks equal 1 second by default.

return - Nothing to return.

◆ Serial485HalfDupMode()

void Serial485HalfDupMode ( int  port,
int  enab 
)

Enables or disables RS-485 half-duplex mode. Full-duplex mode is automatically enabled when half-duplex mode is disabled. This must be explicitly called before RS-485 functionality can be used. Jumpers may also be needed depending on the hardware device and/or development board used.

port - The UART port to use; the UART that can only be used for RS-485 depends on the platform (e.g., MOD52xx mounted on the MOD-DEV-100 develoment board use only UART 0 for RS-485, CB34-EX use only UART 1 for RS-485). enab - '0' disables half-duplex (enables full-duplex); '1' enables half- duplex (disables full-duplex)

return - Nothing to return.

◆ SerialClose()

int SerialClose ( int  portnum)

Close a serial port.

Parameters
portnumThe UART to close. First port is 0. The maximum number is platform dependent
Returns
0 if successful, otherwise Serial Port Error Codes
See also
OpenSerial()

◆ SerialEnableHwRxFlow()

void SerialEnableHwRxFlow ( int  port,
int  enab 
)

Enables or disables request-to-send hardware flow control on receive (RxRTS). When enabled, receive throttles the transmitter on the other end. Jumpers may also be needed to enable the RxRTS line depending on the device and/or development board used.

(NB Device) Rx <–<–< Tx (Other Device) (NB Device) RxRTS >–>–> TxCTS (Other Device)

port - The UART whose flow control will be toggled. enab - '0' disables flow control; '1' (or any non-zero number) will enable it.

return - Nothing to return.

◆ SerialEnableHwTxFlow()

void SerialEnableHwTxFlow ( int  port,
int  enab 
)

Enables or disables clear-to-send hardware flow control on transmit (TxCTS). When enabled, transmit is throttled by the receiver on the other end. Jumpers may also be needed to enable the TxCTS line depending on the device and/or development board used.

(NB Device) Tx >–>–> Rx (Other Device) (NB Device) TxCTS <–<–< RxRTS (Other Device)

Note: Calling this function to disable Tx hardware flow control after enabling RS-485 full-duplex mode configures for RS-422 mode (Tx stays actively driven).

port - The UART whose flow control will be toggled. enab - '0' disables flow control; '1' (or any non-zero number) will enable it.

return - Nothing to return.

◆ SerialEnableRxFlow()

void SerialEnableRxFlow ( int  port,
int  enab 
)

Enables or disables software flow control (XON/XOFF) on receive. When enabled, the NetBurner device will send special XON and XOFF characters to another device in order to control the flow of incoming data.

port - The UART whose flow control will be toggled. enab - '0' disables flow control; '1' (or any non-zero number) will enable it.

return - Nothing to return.

◆ SerialEnableTxFlow()

void SerialEnableTxFlow ( int  port,
int  enab 
)

Enable transmit software flow control on the specified UART.

Enables or disables software flow control (XON/XOFF) on transmit. When enabled, the NetBurner device will recognize the special XON and XOFF characters being sent from another device in order to throttle the output.

Parameters
portUART number
enab0 disables flow control, 1 enables flow control

◆ SerialSendComplete()

BOOL SerialSendComplete ( int  fd)

Determines if data waiting in transmitter holding/shift registers are already sent out.

return - True if finished, false if data still sending

◆ serwriteaddress()

int serwriteaddress ( int  fd,
const char  c 
)

Sends an address character via the UART port number associated with the given file descriptor. This function can only be utilized if the UART is initialized in multidrop mode.

fd - The file descriptor associated with the UART serial port that will be used. c - The address character to be sent.

return - '1' if successful; otherwise, one of the error codes is returned (note that SERIAL_ERR_PORT_NOTOPEN is also returned if UART is not initialized to be in multidrop mode): SERIAL_ERR_NOSUCH_PORT (-1) SERIAL_ERR_PORT_NOTOPEN (-2)