#include <rldf1.h>
|
| rlDF1 (unsigned char src=0, int timeout=1000) |
|
virtual | ~rlDF1 () |
|
void | registerSerial (rlSerial *serial) |
|
int | cmdSetCPUMode (unsigned char destination, unsigned char mode) |
|
int | cmdDiagnosticStatus (unsigned char destination, unsigned char *data) |
|
int | cmdLogicalRead (unsigned char destination, unsigned char nsize, unsigned char filetype, unsigned char filenum, unsigned char adr, unsigned char sadr, unsigned char *buffer) |
|
int | cmdLogicalWrite (unsigned char destination, unsigned char nsize, unsigned char filetype, unsigned char filenum, unsigned char adr, unsigned char sadr, unsigned char *buffer) |
|
int | requests () |
|
int | responses () |
|
void | clearStats () |
|
|
enum | DF1BytePos {
POS_DST =0,
POS_SRC =1,
POS_CMD =2,
POS_STS =3,
POS_TNSL =4,
POS_TNSH =5,
POS_DATA =6
} |
|
enum | DF1ControlChars {
SOH = 0x01,
STX = 0x02,
ETX = 0x03,
EOT = 0x04,
ENQ = 0x05,
ACK = 0x06,
DLE = 0x10,
NAC = 0x15
} |
|
enum | DF1Flags { FLAG_TIMEOUT =-1,
FLAG_DATA =0,
FLAG_CONTROL =1
} |
|
|
int | sendCommand (unsigned char destination, unsigned char cmd, unsigned char sts, unsigned char *cdata, unsigned char len) |
|
int | receiveAnswer (unsigned char &destination, unsigned char &cmd, unsigned char &sts, unsigned char *cdata, unsigned char &len) |
|
int | writeBuffer (unsigned char *buffer, int len) |
|
int | writeBuffer (df1Buffer &buffer) |
|
int | getSymbol (unsigned char *c) |
|
int | get (unsigned char *c) |
|
int | sendENQ () |
|
int | sendACK () |
|
int | sendNAC () |
|
Definition at line 38 of file rldf1.h.
◆ CPUMODE
Command: Set CPU mode ( See page 7-26 )
destination = destination ID
mode = CPUMODE value
Enumerator |
---|
PROGRAM | |
TEST | |
RUN | |
NOCHANGE | |
Definition at line 67 of file rldf1.h.
◆ DF1BytePos
Functions for Data Link Layer.
Internal Use ONLY.
Enumerator |
---|
POS_DST | |
POS_SRC | |
POS_CMD | |
POS_STS | |
POS_TNSL | |
POS_TNSH | |
POS_DATA | |
Definition at line 158 of file rldf1.h.
◆ DF1ControlChars
Enumerator |
---|
SOH | Page 2-6 of Ref Manual.
|
STX | |
ETX | |
EOT | |
ENQ | |
ACK | |
DLE | |
NAC | |
Definition at line 167 of file rldf1.h.
◆ DF1Flags
Enumerator |
---|
FLAG_TIMEOUT | |
FLAG_DATA | |
FLAG_CONTROL | |
Definition at line 177 of file rldf1.h.
◆ DF1ret
Enumerator |
---|
retERROR_TNS | |
retERROR_STS | |
retERROR_CRC | |
retERROR_NAC | |
retERROR | |
retNORESPONSE | |
retSUCCESS | |
Definition at line 51 of file rldf1.h.
◆ rlDF1()
rlDF1::rlDF1 |
( |
unsigned char |
src = 0 , |
|
|
int |
timeout = 1000 |
|
) |
| |
Initialize class
src = id of local device
timeout = receive timeout in ms
Get a random TNS
Definition at line 145 of file rldf1.cpp.
153 tns = (
unsigned short) time((time_t *)0);
◆ ~rlDF1()
◆ clearStats()
void rlDF1::clearStats |
( |
| ) |
|
|
inline |
◆ cmdDiagnosticStatus()
int rlDF1::cmdDiagnosticStatus |
( |
unsigned char |
destination, |
|
|
unsigned char * |
data |
|
) |
| |
Command: Diagnostic Status
Reads a block of status information from an interface module.
The function returns the status information in data.
(see Chapter 10, “Diagnostic Status Information.”)
destination = destination ID
data = buffer for data return
returns the number of valid bytes in data or Error Code
Definition at line 257 of file rldf1.cpp.
259 unsigned char cdat[256];
261 int ret =
sendCommand( destination, 0x06, 0x00, cdat, 1);
263 unsigned char dest,cmd,sts,len;
266 for (
int i=0;i<len;i++) buffer[i]=cdat[i];
int sendCommand(unsigned char destination, unsigned char cmd, unsigned char sts, unsigned char *cdata, unsigned char len)
int receiveAnswer(unsigned char &destination, unsigned char &cmd, unsigned char &sts, unsigned char *cdata, unsigned char &len)
◆ cmdLogicalRead()
int rlDF1::cmdLogicalRead |
( |
unsigned char |
destination, |
|
|
unsigned char |
nsize, |
|
|
unsigned char |
filetype, |
|
|
unsigned char |
filenum, |
|
|
unsigned char |
adr, |
|
|
unsigned char |
sadr, |
|
|
unsigned char * |
buffer |
|
) |
| |
Command: protected typed logical read with three address fields
*Most Important command*. Reads data from a logical address.
Parameters:
destination = destination ID
nsize = size of data to be read
filetype = Type of file with number filenum
84 hex: status
85 hex: bit
86 hex: timer
87 hex: counter
88 hex: control
89 hex: integer
8A hex: floating point
8B hex: output logical by slot
8C hex: input logical by slot
8D hex: string
8E hex: ASCII
8F hex: BCD
filenum = filenumber in PLC memory
adr = Elements Address (see Manual)
sadr = Subelements Address (see Manual)
data = buffer for data return
returns the number of valid bytes in data or Error Code
Definition at line 273 of file rldf1.cpp.
275 unsigned char cdat[256];
282 int ret =
sendCommand( destination , 0x0F, 0x00, cdat, 6);
284 unsigned char dest,cmd,sts,len;
287 for (
int i=0;i<len;i++) buffer[i]=cdat[i];
int sendCommand(unsigned char destination, unsigned char cmd, unsigned char sts, unsigned char *cdata, unsigned char len)
int receiveAnswer(unsigned char &destination, unsigned char &cmd, unsigned char &sts, unsigned char *cdata, unsigned char &len)
◆ cmdLogicalWrite()
int rlDF1::cmdLogicalWrite |
( |
unsigned char |
destination, |
|
|
unsigned char |
nsize, |
|
|
unsigned char |
filetype, |
|
|
unsigned char |
filenum, |
|
|
unsigned char |
adr, |
|
|
unsigned char |
sadr, |
|
|
unsigned char * |
buffer |
|
) |
| |
Command: protected typed logical write with three address fields
*Most Important command*. Writes data to a logical address.
Parameters:
destination = destination ID
nsize = size of data to write
filetype = Type of file with number filenum
84 hex: status
85 hex: bit
86 hex: timer
87 hex: counter
88 hex: control
89 hex: integer
8A hex: floating point
8B hex: output logical by slot
8C hex: input logical by slot
8D hex: string
8E hex: ASCII
8F hex: BCD
filenum = filenumber in PLC memory
adr = Elements Address (see Manual)
sadr = Subelements Address (see Manual)
data = buffer of data to write
returns Error Code
Definition at line 294 of file rldf1.cpp.
296 unsigned char cdat[256];
303 for (
int i=0;i<nsize;i++) cdat[6+i] = buffer[i];
304 int ret =
sendCommand( destination, 0x0F, 0x00, cdat, 6+nsize);
306 unsigned char dest,cmd,sts,len;
309 for (
int i=0;i<len;i++) buffer[i] = cdat[i];
int sendCommand(unsigned char destination, unsigned char cmd, unsigned char sts, unsigned char *cdata, unsigned char len)
int receiveAnswer(unsigned char &destination, unsigned char &cmd, unsigned char &sts, unsigned char *cdata, unsigned char &len)
◆ cmdSetCPUMode()
int rlDF1::cmdSetCPUMode |
( |
unsigned char |
destination, |
|
|
unsigned char |
mode |
|
) |
| |
Definition at line 240 of file rldf1.cpp.
243 unsigned char cdat[256];
246 int ret =
sendCommand( destination, 0x0F, 0x00, cdat, 2);
248 unsigned char dest,cmd,sts,len;
251 printf(
"\nSet CPU Mode Execution Error! STS:%02X",sts);
int sendCommand(unsigned char destination, unsigned char cmd, unsigned char sts, unsigned char *cdata, unsigned char len)
int receiveAnswer(unsigned char &destination, unsigned char &cmd, unsigned char &sts, unsigned char *cdata, unsigned char &len)
◆ get()
int rlDF1::get |
( |
unsigned char * |
c | ) |
|
|
private |
Definition at line 203 of file rldf1.cpp.
int readBlock(unsigned char *buf, int len, int timeout=-1)
◆ getSymbol()
int rlDF1::getSymbol |
( |
unsigned char * |
c | ) |
|
|
private |
Definition at line 184 of file rldf1.cpp.
int readBlock(unsigned char *buf, int len, int timeout=-1)
◆ receiveAnswer()
int rlDF1::receiveAnswer |
( |
unsigned char & |
destination, |
|
|
unsigned char & |
cmd, |
|
|
unsigned char & |
sts, |
|
|
unsigned char * |
cdata, |
|
|
unsigned char & |
len |
|
) |
| |
|
private |
CRC LOW
CRC HI
Definition at line 386 of file rldf1.cpp.
389 static unsigned char response=
NAC;
398 DBGPRINTF(
"\nreceiveAnswer() Timeout....");
424 unsigned short crc = (
unsigned short)rxc;
432 crc += ( (
unsigned short)rxc )<<8;
439 unsigned short tns_ = (
unsigned short)msg[
POS_TNSL];
440 tns_ += ( (
unsigned short)msg[
POS_TNSH] )<<8;
462 for (
int i=0; i<len; i++) cdata[i] = msg[i +
POS_DATA];
unsigned int write(unsigned char c)
int getSymbol(unsigned char *c)
static unsigned short computeCRC(const unsigned char *buffer, int len)
◆ registerSerial()
void rlDF1::registerSerial |
( |
rlSerial * |
serial | ) |
|
◆ requests()
Some statistics...
Definition at line 204 of file rldf1.h.
◆ responses()
◆ sendACK()
Definition at line 220 of file rldf1.cpp.
222 static unsigned char buf[2];
int writeBuffer(unsigned char *buffer, int len)
◆ sendCommand()
int rlDF1::sendCommand |
( |
unsigned char |
destination, |
|
|
unsigned char |
cmd, |
|
|
unsigned char |
sts, |
|
|
unsigned char * |
cdata, |
|
|
unsigned char |
len |
|
) |
| |
|
private |
Functions for Application Layer.
Normally private. If you want to add new Commands do it with new public functions.
sendCommand implements sending with retries and handling
destination = id of remote device
cmd = Command Code (see page 6-3)
sts = Status Code (see page 6-6 )
cdata = Pointer to Command Specific data packet ( Chapter 7 )
len = Length of cdata
receiveAnswer gets answer frame from remote.
SOURCE
Definition at line 319 of file rldf1.cpp.
333 for (
int i=0; i<len; i++) {
DBGPRINTF(
"[%02X] ",cdata[i]); }
334 msg.
write( destination );
338 msg.
write( (
unsigned char)(
tns&0x00FF) );
339 msg.
write( (
unsigned char)(
tns>>8) );
340 for(
int i=0; i<len; i++) msg.
write( cdata[i] );
349 fullmsg.
write( (
unsigned char)(crc&0x00FF) );
350 fullmsg.
write( (
unsigned char)(crc>>8) );
unsigned int writeDLE(unsigned char c)
int writeBuffer(unsigned char *buffer, int len)
unsigned int write(unsigned char c)
int getSymbol(unsigned char *c)
static unsigned short computeCRC(const unsigned char *buffer, int len)
◆ sendENQ()
Definition at line 211 of file rldf1.cpp.
213 static unsigned char buf[2];
int writeBuffer(unsigned char *buffer, int len)
◆ sendNAC()
Definition at line 229 of file rldf1.cpp.
231 static unsigned char buf[2];
int writeBuffer(unsigned char *buffer, int len)
◆ writeBuffer() [1/2]
int rlDF1::writeBuffer |
( |
unsigned char * |
buffer, |
|
|
int |
len |
|
) |
| |
|
private |
Definition at line 165 of file rldf1.cpp.
int writeBlock(const unsigned char *buf, int len)
◆ writeBuffer() [2/2]
Definition at line 174 of file rldf1.cpp.
int writeBlock(const unsigned char *buf, int len)
◆ active
◆ nRequests
◆ nResponses
◆ source
unsigned char rlDF1::source |
|
private |
◆ timeout
◆ tns
unsigned short rlDF1::tns |
|
private |
◆ tty
The documentation for this class was generated from the following files: