?? mm_rab.lib
字號:
NOTE: MM_RAB.LIB functions are generally not reentrant.
SYNTAX: int mmIn(unsigned wAddr, unsigned wInput, unsigned wCount,
void *pInputs)
DESCRIPTION: Modbus Master query 0x02, Read Input Status. Reads the
status (ON == 1, OFF == 0) of discrete inputs (1X references) in the
slave device. Places the present state of the selected discrete inputs
into the buffer pointed to by *pInputs, one input per bit with the
starting input number in the least significant bit of the buffer's
first byte. The buffer size should be no less than 'ceil(wCount / 8.0)'
bytes. If wCount is not evenly divisible by eight the unused bits of
the last required byte are cleared to zero.
PARAMETER1: slave address, broadcast (0x00) is not supported.
PARAMETER2: starting 1X input number (zero based).
PARAMETER3: inputs count (one based).
PARAMETER4: input information buffer pointer.
RETURN VALUE: 0 (MM_BUSY) if busy, -1 (MM_OK) if success, or exception
code (from master if < -1 or from slave if > 0). See the MM_* and MS_*
definitions near the start of MM_RAB.LIB for the complete list.
END DESCRIPTION ******************************************************/
nodebug
int mmIn(unsigned wAddr, unsigned wInput, unsigned wCount,
void *pInputs)
{
return mmCoilRd(wAddr, 0x02, wInput, wCount, pInputs);
}
/*=========================================================================*\
[0x03] Read Holding Registers
\*=========================================================================*/
/*** BeginHeader mmRead */
int mmRead(unsigned,unsigned,unsigned,void *);
/*** EndHeader */
/* START FUNCTION DESCRIPTION *****************************************
mmRead <MM_RAB.LIB>
NOTE: MM_RAB.LIB functions are generally not reentrant.
SYNTAX: int mmRead(unsigned wAddr, unsigned wReg, unsigned wCount,
void *pwRegs)
DESCRIPTION: Modbus Master query 0x03, Read Holding Registers. Reads
the contents of holding registers (4X references) in the slave device.
Places the present contents of the selected registers into the buffer
pointed to by *pRegs, 16-bits per register with the starting register
number at the beginning of the buffer. The buffer size should be no
less than 'wCount * 2' bytes.
PARAMETER1: slave address, broadcast (0x00) is not supported.
PARAMETER2: starting 4X register number (zero based).
PARAMETER3: registers count (one based).
PARAMETER4: registers information buffer pointer.
RETURN VALUE: 0 (MM_BUSY) if busy, -1 (MM_OK) if success, or exception
code (from master if < -1 or from slave if > 0). See the MM_* and MS_*
definitions near the start of MM_RAB.LIB for the complete list.
END DESCRIPTION ******************************************************/
nodebug
int mmRead(unsigned wAddr, unsigned wReg, unsigned wCount,
void *pwRegs)
{
return mmRegRd(wAddr, 0x03, wReg, wCount, pwRegs);
}
/*=========================================================================*\
[0x04] Read Input Registers
\*=========================================================================*/
/*** BeginHeader mmInput */
int mmInput(unsigned,unsigned,unsigned,void *);
/*** EndHeader */
/* START FUNCTION DESCRIPTION *****************************************
mmInput <MM_RAB.LIB>
NOTE: MM_RAB.LIB functions are generally not reentrant.
SYNTAX: int mmInput(unsigned wAddr, unsigned wReg, unsigned wCount,
void *pRegs)
DESCRIPTION: Modbus Master query 0x04, Read Input Registers. Reads the
contents of input registers (3X references) in the slave device. Places
the present contents of the selected registers into the buffer pointed
to by *pRegs, 16-bits per register with the starting register number at
the beginning of the buffer. The buffer size should be no less than
'wCount * 2' bytes.
PARAMETER1: slave address, broadcast (0x00) is not supported.
PARAMETER2: starting 3X register number (zero based).
PARAMETER3: registers count (one based).
PARAMETER4: registers information buffer pointer.
RETURN VALUE: 0 (MM_BUSY) if busy, -1 (MM_OK) if success, or exception
code (from master if < -1 or from slave if > 0). See the MM_* and MS_*
definitions near the start of MM_RAB.LIB for the complete list.
END DESCRIPTION ******************************************************/
nodebug
int mmInput(unsigned wAddr, unsigned wReg, unsigned wCount,
void *pRegs)
{
return mmRegRd(wAddr, 0x04, wReg, wCount, pRegs);
}
/*=========================================================================*\
[0x05] Force Single Coil
\*=========================================================================*/
/*** BeginHeader mmForceCoil */
int mmForceCoil(unsigned,unsigned,int);
/*** EndHeader */
/* START FUNCTION DESCRIPTION *****************************************
mmForceCoil <MM_RAB.LIB>
NOTE: MM_RAB.LIB functions are generally not reentrant.
SYNTAX: int mmForceCoil(unsigned wAddr, unsigned wCoil, int bState)
DESCRIPTION: Modbus Master query 0x05, Force Single Coil. Forces a
single coil (0X reference) to either ON (1) or OFF (0). When broadcast,
this function forces the same coil reference in all attached slave
devices.
PARAMETER1: slave address, broadcast (0x00) is supported.
PARAMETER2: 0X coil number (zero based).
PARAMETER3: binary state (OFF == zero, ON == non-zero).
RETURN VALUE: 0 (MM_BUSY) if busy, -1 (MM_OK) if success, or exception
code (from master if < -1 or from slave if > 0). See the MM_* and MS_*
definitions near the start of MM_RAB.LIB for the complete list.
END DESCRIPTION ******************************************************/
nodebug
int mmForceCoil(unsigned wAddr, unsigned wCoil, int bState)
{
auto int nErr;
nErr = MM_BUSY;
costate
{
mmCmdNew(wAddr, 0x05); // Start New Command
mmCmdWord(wCoil); // Coil Address
mmCmdWord(bState ? 0xFF00 : 0x0000); // Coil State
waitfor(nErr = mmExec()); // Finish & Execute Packet
}
return nErr;
}
/*=========================================================================*\
[0x06] Preset Single Register
\*=========================================================================*/
/*** BeginHeader mmPresetReg */
int mmPresetReg(unsigned,unsigned,unsigned);
/*** EndHeader */
/* START FUNCTION DESCRIPTION *****************************************
mmPresetReg <MM_RAB.LIB>
NOTE: MM_RAB.LIB functions are generally not reentrant.
SYNTAX: int mmPresetReg(unsigned wAddr, unsigned wReg, unsigned wVal)
DESCRIPTION: Modbus Master query 0x06, Preset Single Register. Presets
a value into a single holding register (4X reference). When broadcast,
this function presets the same register reference in all attached slave
devices.
PARAMETER1: slave address, broadcast (0x00) is supported.
PARAMETER2: 4X register number (zero based).
PARAMETER3: 16-bit preset value.
RETURN VALUE: 0 (MM_BUSY) if busy, -1 (MM_OK) if success, or exception
code (from master if < -1 or from slave if > 0). See the MM_* and MS_*
definitions near the start of MM_RAB.LIB for the complete list.
END DESCRIPTION ******************************************************/
nodebug
int mmPresetReg(unsigned wAddr, unsigned wReg, unsigned wVal)
{
auto int nErr;
nErr = MM_BUSY;
costate
{
mmCmdNew(wAddr, 0x06); // Start New Command
mmCmdWord(wReg); // Register Address
mmCmdWord(wVal); // Register Value
waitfor(nErr = mmExec()); // Finish & Execute Packet
}
return nErr;
}
/*=========================================================================*\
[0x07] Read Exception Status
\*=========================================================================*/
/*** BeginHeader mmRdExcStat */
/*** EndHeader */
/* START FUNCTION DESCRIPTION *****************************************
mmRdExcStat <MM_RAB.LIB>
NOTE: MM_RAB.LIB functions are generally not reentrant.
SYNTAX: int mmRdExcStat(unsigned wAddr, void *pbStatus)
DESCRIPTION: Modbus Master query 0x07, Read Exception Status. Reads the
contents of eight exception status coils within the slave device. The
assignment and meaning of each coil (one per bit) depends on the type
of slave device and may be either predefined or programmable. Places
the exception status into the byte pointed to by *pcStatus.
PARAMETER1: slave address, broadcast (0x00) is not supported.
PARAMETER2: exception status byte pointer.
RETURN VALUE: 0 (MM_BUSY) if busy, -1 (MM_OK) if success, or exception
code (from master if < -1 or from slave if > 0). See the MM_* and MS_*
definitions near the start of MM_RAB.LIB for the complete list.
END DESCRIPTION ******************************************************/
nodebug
int mmRdExcStat(unsigned wAddr, void *pbStatus)
{
auto int nErr;
if(!wAddr)
{
nErr = MM_NOBROAD; // Broadcast Not Supported
}
else
{
nErr = MM_BUSY;
costate
{
mmCmdNew(wAddr, 0x07); // Start New Command
waitfor(nErr = mmExec()); // Finish & Execute Packet
if(nErr == MM_OK)
{
* (unsigned char *) pbStatus = acMMRep[2];
}
}
}
return nErr;
}
/*=========================================================================*\
[0x0B] Fetch Comm Event Counter
\*=========================================================================*/
/*** BeginHeader mmFetchCommCnt */
int mmFetchCommCnt(unsigned,void *,void *);
/*** EndHeader */
/* START FUNCTION DESCRIPTION *****************************************
mmFetchCommCnt <MM_RAB.LIB>
NOTE: MM_RAB.LIB functions are generally not reentrant.
SYNTAX: int mmFetchCommCnt(unsigned wAddr, void *pwCount,
void *pwStatus)
DESCRIPTION: Modbus Master query 0x0B, Fetch Comm Event Counter. The
response is a status word and an event count from the slave device's
communications event counter. Places the communications event count
into the 16-bit word pointed to by *pwCount and the status word (0xFFFF
if busy, 0x0000 otherwise) into the 16-bit word pointed to by
*pwStatus.
PARAMETER1: slave address, broadcast (0x00) is not supported.
PARAMETER2: communications event count pointer.
PARAMETER3: status word pointer.
RETURN VALUE: 0 (MM_BUSY) if busy, -1 (MM_OK) if success, or exception
code (from master if < -1 or from slave if > 0). See the MM_* and MS_*
definitions near the start of MM_RAB.LIB for the complete list.
END DESCRIPTION ******************************************************/
nodebug
int mmFetchCommCnt(unsigned wAddr, void *pwCount,
void *pwStatus)
{
auto int nErr;
if(!wAddr)
{
nErr = MM_NOBROAD; // Broadcast Not Supported
}
else
{
nErr = MM_BUSY;
costate
{
mmCmdNew(wAddr, 0x0B); // Start New Command
waitfor(nErr = mmExec()); // Finish & Execute Packet
if(nErr == MM_OK)
{
* (unsigned *) pwCount = mmRepWord(4);
* (unsigned *) pwStatus = mmRepWord(2);
}
}
}
return nErr;
}
/*=========================================================================*\
[0x0F] Force Multiple Coils
\*=========================================================================*/
/*** BeginHeader mmForceCoils */
int mmForceCoils(unsigned,unsigned,unsigned,void *);
/*** EndHeader */
/* START FUNCTION DESCRIPTION *****************************************
mmForceCoils <MM_RAB.LIB>
NOTE: MM_RAB.LIB functions are generally not reentrant.
SYNTAX: int mmForceCoils(unsigned wAddr, unsigned wCoil,
unsigned wCount, void *pCoils)
DESCRIPTION: Modbus Master query 0x0F, Force Multiple Coils. Forces
each coil (0X reference) in a sequence of coils to either ON (1) or
OFF (0), one coil per bit with the starting coil number in the least
significant bit of the buffer's first byte. If wCount is not evenly
divisible by eight the unused bits in the last byte should be cleared
to zero. When broadcast, this function forces the same coil references
in all attached slave devices.
PARAMETER1: slave address, broadcast (0x00) is supported.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -