#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.
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.
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.
- Enumerator:
SOH |
Page 2-6 of Ref Manual.
|
STX |
|
ETX |
|
EOT |
|
ENQ |
|
ACK |
|
DLE |
|
NAC |
|
Definition at line 167 of file rldf1.h.
- Enumerator:
FLAG_TIMEOUT |
|
FLAG_DATA |
|
FLAG_CONTROL |
|
Definition at line 177 of file rldf1.h.
- Enumerator:
retERROR_TNS |
|
retERROR_STS |
|
retERROR_CRC |
|
retERROR_NAC |
|
retERROR |
|
retNORESPONSE |
|
retSUCCESS |
|
Definition at line 51 of file rldf1.h.
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.
{
tns = (
unsigned short) time((time_t *)0);
}
void rlDF1::clearStats |
( |
| ) |
|
|
inline |
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.
{
unsigned char cdat[256];
cdat[0]=0x03;
int ret =
sendCommand( destination, 0x06, 0x00, cdat, 1);
unsigned char dest,cmd,sts,len;
for (int i=0;i<len;i++) buffer[i]=cdat[i];
ret = len;
}
}
return ret;
}
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.
{
unsigned char cdat[256];
cdat[0]=0xA2;
cdat[1]=nsize;
cdat[2]=filenum;
cdat[3]=filetype;
cdat[4]=adr;
cdat[5]=sadr;
int ret =
sendCommand( destination , 0x0F, 0x00, cdat, 6);
unsigned char dest,cmd,sts,len;
for (int i=0;i<len;i++) buffer[i]=cdat[i];
ret = len;
}
}
return ret;
}
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.
{
unsigned char cdat[256];
cdat[0]=0xAA;
cdat[1]=nsize;
cdat[2]=filenum;
cdat[3]=filetype;
cdat[4]=adr;
cdat[5]=sadr;
for (int i=0;i<nsize;i++) cdat[6+i] = buffer[i];
int ret =
sendCommand( destination, 0x0F, 0x00, cdat, 6+nsize);
unsigned char dest,cmd,sts,len;
for ( int i=0;i<len;i++) buffer[i] = cdat[i];
ret = len;
}
}
return ret;
}
int rlDF1::cmdSetCPUMode |
( |
unsigned char |
destination, |
|
|
unsigned char |
mode |
|
) |
| |
Definition at line 240 of file rldf1.cpp.
{
unsigned char cdat[256];
cdat[0]=0x3A;
cdat[1]=mode;
int ret =
sendCommand( destination, 0x0F, 0x00, cdat, 2);
unsigned char dest,cmd,sts,len;
if (sts!=0) {
printf("\nSet CPU Mode Execution Error! STS:%02X",sts);
}
}
return ret;
}
int rlDF1::get |
( |
unsigned char * |
c | ) |
|
|
private |
int rlDF1::getSymbol |
( |
unsigned char * |
c | ) |
|
|
private |
Definition at line 184 of file rldf1.cpp.
{
} else {
} else {
}
}
}
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.
{
int ret;
static unsigned char response=
NAC;
int flag;
unsigned char rxc;
while(1) {
break;
msg.reset();
}
continue;
}
flag = get(&rxc);
continue;
}
unsigned short crc = (unsigned short)rxc;
flag = get(&rxc);
continue;
}
crc += ( (unsigned short)rxc )<<8;
continue;
}
unsigned short tns_ = (
unsigned short)msg[
POS_TNSL];
tns_ += ( (
unsigned short)msg[
POS_TNSH] )<<8;
break;
}
for (
int i=0; i<len; i++) cdata[i] = msg[i +
POS_DATA];
break;
break;
} else {
}
}
return ret;
}
void rlDF1::registerSerial |
( |
rlSerial * |
serial | ) |
|
Some statistics...
Definition at line 204 of file rldf1.h.
Definition at line 220 of file rldf1.cpp.
{
static unsigned char buf[2];
}
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.
{
unsigned short crc;
for (
int i=0; i<len; i++) {
DBGPRINTF(
"[%02X] ",cdata[i]); }
msg.
write( destination );
msg.
write( (
unsigned char)(
tns&0x00FF) );
for(
int i=0; i<len; i++) msg.
write( cdata[i] );
fullmsg.
write( (
unsigned char)(crc&0x00FF) );
fullmsg.
write( (
unsigned char)(crc>>8) );
int naks=0;
int enq=0;
int flag;
unsigned char rxc;
int ret;
while(1) {
break;
naks++;
if (naks>=3) {
break;
}
enq++;
if (enq>=3) {
break;
}
}
}
return ret;
}
Definition at line 211 of file rldf1.cpp.
{
static unsigned char buf[2];
}
Definition at line 229 of file rldf1.cpp.
{
static unsigned char buf[2];
}
int rlDF1::writeBuffer |
( |
unsigned char * |
buffer, |
|
|
int |
len |
|
) |
| |
|
private |
Definition at line 165 of file rldf1.cpp.
{
int ret=-1;
}
return ret;
}
Definition at line 174 of file rldf1.cpp.
{
int ret=-1;
}
return ret;
}
unsigned char rlDF1::source |
|
private |
unsigned short rlDF1::tns |
|
private |
The documentation for this class was generated from the following files: