Make your own free website on Tripod.com

CLocalModbus Class Members

class CLocalModbus : public CModbus

UpdateSerialConfig - Opens a com port or or updates port parameters.

CloseCommPort - Closes a serial port.

TxRxMessage virtual CModbus implementation. Sends and receives a message from a slave.

ErrorMessage virtual CModbus implementation.Return string description of an error code.

 

ByteSize - Specifies the number of bits in the bytes transmitted and received.

BaudRate - Specifies the baud rate

ComPort - Comm serial port

FlowControl - Specifies flow control.

Parity - Specifies the parity scheme to be used.

SilentInterval - silent interval marking the begin and the end of message in ms.

StopBits - number of stop bits.

Timeout - message timeout in ms.

TransmissionMode - Specifies RTU or ASCII transmission mode.

CLocalModbus::UpdateSerialConfig

BOOL UpdateSerialConfig(BYTE byComPort=0, DWORD dwBaudRate=0, BYTE byParity=INVALID_PARITY);

Return Value

TRUE if function succeeds and FALSE if fails.

Parameters

byComPort - com port number 1 to 8.

dwBaudRate - actual baudrate , 1200, 9600 ...

byParity - Specifies the parity scheme to be used.

Value Meaning
EVENPARITY Even
MARKPARITY Mark
NOPARITY No parity
ODDPARITY Odd
SPACEPARITY Space

Remarks

Opens a com port or or updates port parameters. It's possible to set class properties instead of function parameters.

example:

CLocalModbus localModbus;

// open com 2

localModbus.StopBits(TWOSTOPBITS);
localModbus.ByteSize(8);
localModbus.FlowControl(CLocalModbus::FC_NONE);
localModbus.Timeout(300);
localModbus.SilentInterval(20);
localModbus.TransmissionMode(CLocalModbus::MODE_RTU);

if (!localModbus.UpdateSerialConfig(2,9600,NOPARITY)){

AfxMessageBox(_T("Error opening com port"));

}

See also: CloseCommPort , StopBits , ByteSize , FlowControl , Timeout , SilentInterval , TransmissionMode.

 

CLocalModbus::CloseCommPort

BOOL CLocalModbus::CloseCommPort();

Return Value

TRUE if function succeeds and FALSE if fails.

Remarks

Closes a com port. It's also called by destructor of CLocalModbus.

See also: UpdateSerialConfig.

 

CLocalModbus::ByteSize

void ByteSize(WORD wSize);
WORD ByteSize();

Remarks

Specifies the number of bits in the bytes transmitted and received. RTU uses 8 and ASCII 7.

See also: UpdateSerialConfig

CLocalModbus::BaudRate

DWORD BaudRate(); //actual baudrate value
void BaudRate(DWORD dwBaudRate);

Remarks

Specifies the baud rate , 300 , 1200 , 9600. You can use the following windows constants:
CBR_110 CBR_19200
CBR_300 CBR_38400
CBR_600 CBR_56000
CBR_1200 CBR_57600
CBR_2400 CBR_115200
CBR_4800 CBR_128000
CBR_9600 CBR_256000
CBR_14400

See also: UpdateSerialConfig

 

 

CLocalModbus::ComPort

BYTE ComPort();
void ComPort(BYTE byComPort);

Remarks

Specifies the Comm serial port 1 to 8.

See also: UpdateSerialConfig

CLocalModbus::FlowControl

BYTE FlowControl();
void FlowControl(BYTE byFlowControl);

Remarks

Specifies the flow control. This member can a combination of the following values:
CLocalModbus::FC_NONE No Flow control
CLocalModbus::FC_DTRDSR Hardware Flow Control DTR/CTS
CLocalModbus::FC_RTSCTS Hardware Flow Control DTR/CTS
CLocalModbus::FC_XONXOFF Software Flow Control XON/XOFF

If you use , for instance , software and hardware flow control set this member as CLocalModbus::FC_RTSCTS+CLocalModbus::FC_XONXOFF.

See also: UpdateSerialConfig

CLocalModbus::Parity

BYTE Parity();
void Parity(BYTE byParity);

Remarks

Specifies the parity scheme to be used.
Value Meaning
EVENPARITY Even
MARKPARITY Mark
NOPARITY No parity
ODDPARITY Odd
SPACEPARITY Space

See also: UpdateSerialConfig

CLocalModbus::SilentInterval

DWORD SilentInterval() const;
void SilentInterval(DWORD dwSilentInterval);

Remarks

Silent interval marking the begin and the end of a message in ms.

RTU messages start and end with a silent interval of at least 3.5 character times. For instance , for baud rate of 9600 bps silent interval is 4 ms , but when doing some practical tests this value was increased to 20 ms for correct communication with devices, try to increase this value if you get many communication errors.

When using ASCII set silent interval 500 or 1000 ms.

See also: UpdateSerialConfig

CLocalModbus::StopBits

BYTE StopBits();
void StopBits(BYTE byStopBits);

Remarks

Specifies the number of stop bits to be used.

Value Meaning
ONESTOPBIT 1 stop bit
ONE5STOPBITS 1.5 stop bits
TWOSTOPBITS 2 stop bits

Use 1(ONESTOPBIT) stop bit if parity is used and 2(TWOSTOPBITS) bits if no parity.

See also: UpdateSerialConfig

CLocalModbus::Timeout

DWORD Timeout() const;
void Timeout(DWORD dwTimeout);

Remarks

Time-out period for slave response in ms.

See also: UpdateSerialConfig

 

CLocalModbus::TransmissionMode

WORD TransmissionMode();
void TransmissionMode(WORD wMode);

Remarks

Modbus use either of two transmission modes: ASCII or RTU. This member can be one of the values below:

CLocalModbus::MODE_RTU RTU transmission mode
CLocalModbus::MODE_ASCII ASCII transmission mode

See also: UpdateSerialConfig