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.
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.
void ByteSize(WORD wSize);
WORD ByteSize();
Remarks
See also: UpdateSerialConfig
DWORD BaudRate(); //actual baudrate
value
void BaudRate(DWORD dwBaudRate);
Remarks
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
BYTE ComPort();
void ComPort(BYTE byComPort);
Remarks
See also: UpdateSerialConfig
BYTE FlowControl();
void FlowControl(BYTE byFlowControl);
Remarks
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
BYTE Parity();
void Parity(BYTE byParity);
Remarks
Value | Meaning |
---|---|
EVENPARITY | Even |
MARKPARITY | Mark |
NOPARITY | No parity |
ODDPARITY | Odd |
SPACEPARITY | Space |
See also: UpdateSerialConfig
DWORD SilentInterval() const;
void SilentInterval(DWORD dwSilentInterval);
Remarks
Silent interval marking the begin and the end of a message in ms.
When using ASCII set silent interval 500 or 1000 ms.
See also: UpdateSerialConfig
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
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