#pragma once
|
/************************************************************************************
|
FPX PLC ͨѶͷÎļþ
|
Version: V1.02
|
Date: 2015-06-30
|
Description;
|
2015-08-30 Ôö¼ÓÁËÄ£Ä⹦ÄÜ
|
1.03 2016-05-23
|
Ôö¼ÓÁÙ½çÇø
|
|
************************************************************************************/
|
#include "omp.h"
|
#include "../SerialCom/SerialCom.hpp"
|
const unsigned short HexMask[16]=
|
{
|
0x1,0x2,0x4,0x8,0x10,0x20,0x40,0x80,
|
0x100,0x200,0x400,0x800,0x1000,0x2000,0x4000,0x8000
|
};
|
static inline int xtoi(const char * hexstr, int len=0)
|
{
|
int i,j,k;
|
unsigned char ch;
|
k=0;j=0;
|
int len1=(int)strlen(hexstr);
|
if (len>0) len1=len;
|
for (i=0;i<len1;i++)
|
{
|
ch=hexstr[i];
|
if (ch>='0'&&ch<='9')
|
{
|
k=ch-'0';
|
j=j*16+k;
|
continue;
|
}
|
if (ch>='A'&&ch<='F')
|
{
|
k=ch-'A'+10;
|
j=j*16+k;
|
continue;
|
}
|
if (ch>='a'&&ch<='f')
|
{
|
k=ch-'a'+10;
|
j=j*16+k;
|
continue;
|
}
|
if (ch==' '||ch==' ')
|
{
|
continue;
|
}
|
break;
|
}
|
return j;
|
}
|
#pragma pack(push)
|
#pragma pack(2)
|
struct bitfield16
|
{
|
short int b0:1;
|
short int b1:1;
|
short int b2:1;
|
short int b3:1;
|
short int b4:1;
|
short int b5:1;
|
short int b6:1;
|
short int b7:1;
|
short int b8:1;
|
short int b9:1;
|
short int ba:1;
|
short int bb:1;
|
short int bc:1;
|
short int bd:1;
|
short int be:1;
|
short int bf:1;
|
};
|
#pragma pack()
|
#pragma pack(pop)
|
class FPXPLC
|
{
|
public:
|
int Connected;
|
CSerialCom SerialPlc1;
|
int Station;
|
char buffer1[4000];
|
char buffer2[4000];
|
int SimFunc; //Ä£Ä⹦ÄÜ
|
int simresult1; //Ä£Ä⹦ÄÜÊýÖµ
|
CStringA LastRecvString;
|
|
double SendTimeMin; //·¢ËÍʱ¼ä×îС
|
double SendTimeMax; //·¢ËÍʱ¼ä×î´ó
|
double SendTimeCur; //·¢ËÍʱ¼äµ±Ç°
|
double SendTimeAvg; //·¢ËÍʱ¼äƽ¾ù
|
|
double RecvTimeMin; //½ÓÊÕʱ¼ä×îС
|
double RecvTimeMax; //½ÓÊÕʱ¼ä×î´ó
|
double RecvTimeCur; //½ÓÊÕʱ¼äµ±Ç°
|
double RecvTimeAvg; //½ÓÊÕʱ¼äƽ¾ù
|
|
double TransTimeMin; //´«Êäʱ¼ä£¬×îС
|
double TransTimeMax; //´«Êäʱ¼ä×î´ó
|
double TransTimeCur; //´«Êäʱ¼äµ±Ç°
|
double TranstimeAvg; //´«Êäʱ¼äƽ¾ù
|
|
#pragma pack(push)
|
#pragma pack(2)
|
union uPLCINFO
|
{
|
struct //stPLCINFO
|
{
|
char PlcType[2];
|
char Version[2];
|
char PrgSize[2];
|
char RunMode[2];
|
char LinkInfo[2];
|
char ErrMark[2];
|
char SelfTestInfo[4];
|
};
|
unsigned char bytes[16];
|
}InfoBytes;
|
#pragma pack()
|
#pragma pack(1)
|
struct stPLCINFO
|
{
|
unsigned char PlcType;
|
unsigned char Version;
|
unsigned char PrgSize;
|
union{
|
unsigned char RunMode;
|
struct
|
{
|
unsigned char Running:1;
|
unsigned char Test:1;
|
unsigned char BRK:1;
|
unsigned char BRKALW:1;
|
unsigned char ReFresh:1;
|
unsigned char SigleStep:1;
|
unsigned char MSG:1;
|
unsigned char REM:1;
|
}stRunMode;
|
};
|
unsigned char LinkInfo;
|
union{
|
unsigned char Errs;
|
struct{
|
unsigned char SelfTestErr:1;
|
unsigned char PowerDown:1;
|
unsigned char Fuse:1;
|
unsigned char UnitErr:1;
|
unsigned char IOChkErr:1;
|
unsigned char BetteryErr:1;
|
unsigned char BetteryErrKeep:1;
|
unsigned char RunErr:1;
|
}stErrs;
|
};
|
unsigned short SelfTestInfo;
|
}PlcInfo;
|
#pragma pack()
|
#pragma pack(pop)
|
volatile bitfield16 * R; //λ·ÃÎÊ
|
volatile short WX[110]; //WX0-WX109;
|
volatile short WY[110]; //WY0-WY109;
|
volatile short WL[128]; //WL0-WL127;
|
volatile short WR[256]; //WR0-WR255;
|
volatile short SWR[15]; //WR900-WR915;
|
volatile short DT[32768]; //DT0-DT32767;
|
volatile short SDT[512]; //DT90000-DT90499;
|
volatile short LD[256]; //LD0-LD255;
|
|
CCriticalSection myCriticalSection1; //ÁÙ½çÇø
|
|
FPXPLC()
|
{
|
SimFunc=0;
|
R=(bitfield16 *)WR;
|
RecvTimeAvg=RecvTimeCur=RecvTimeMin=RecvTimeMax=0;
|
SendTimeAvg=SendTimeCur=SendTimeMin=SendTimeMax=0;
|
TranstimeAvg=TransTimeCur=TransTimeMin=TransTimeMax=0;
|
|
};
|
~FPXPLC(){};
|
|
int BCC(const char * value)
|
{
|
int i,j;
|
char k;
|
k=0;
|
j=(int)strlen(value);
|
for (i=0;i<j;i++)
|
{
|
k^=value[i];
|
}
|
return k;
|
}
|
|
int SendPLCData(const char * buffer, int n)
|
{
|
double time1=GetTimeMs();
|
SerialPlc1.Purge();
|
int j=SerialPlc1.Send(buffer,n);
|
double time2=GetTimeMs();
|
double dif=time2-time1;
|
if (SendTimeCur==0)
|
{
|
SendTimeCur=SendTimeMin=SendTimeMax=SendTimeAvg=dif;
|
}else
|
{
|
SendTimeCur=dif;
|
if (dif>SendTimeMax) {SendTimeMax=dif;}
|
if (dif<SendTimeMin) {SendTimeMin=dif;}
|
SendTimeAvg=SendTimeAvg*0.9+dif*0.1;
|
}
|
return j;
|
}
|
|
int ReadPLCCom(char * buffer, int n)
|
{
|
double time1=GetTimeMs();
|
int j=SerialPlc1.Read(buffer,n);
|
double time2=GetTimeMs();
|
double dif=time2-time1;
|
if (j>0)
|
{
|
buffer[j]=0;
|
LastRecvString=buffer;
|
}
|
if (RecvTimeCur==0)
|
{
|
RecvTimeCur=RecvTimeAvg=RecvTimeMax=RecvTimeMin=dif;
|
}else
|
{
|
RecvTimeCur=dif;
|
if (dif>RecvTimeMax) {RecvTimeMax=dif;}
|
if (dif<RecvTimeMin) {RecvTimeMin=dif;}
|
RecvTimeAvg=RecvTimeAvg*0.9+dif*0.1;
|
}
|
return j;
|
}
|
int Connect(int Station2=0)
|
{
|
int j;
|
j=SerialPlc1.Open();
|
if (j==1)
|
{// RT(Station2);
|
Connected=1;
|
RecvTimeAvg=RecvTimeCur=RecvTimeMin=RecvTimeMax=0;
|
SendTimeAvg=SendTimeCur=SendTimeMin=SendTimeMax=0;
|
TranstimeAvg=TransTimeCur=TransTimeMin=TransTimeMax=0;
|
}
|
return j;
|
}
|
int DisConnect()
|
{
|
if (Connected)
|
{
|
SerialPlc1.Close();
|
Connected=0;
|
}
|
return 0;
|
}
|
|
// /*
|
// Ö¸Áî ¹¦ÄÜÃèÊö
|
//* RCS Read single point of contact information ¶ÁÈ¡µ¥¸ö´¥µãµÄ״̬ÐÅÏ¢ X Y R L T C
|
//* WCS Write single point of contact information дÈëµ¥¸ö´¥µãµÄ״̬ÐÅÏ¢ Y R L
|
// RCP Read plural point of contact information ¶ÁÈ¡¶à¸ö´¥µãµÄ״̬ÐÅÏ¢
|
// WCP Write plural point of contact information дÈë¶à¸ö´¥µãµÄ״̬ÐÅÏ¢
|
//* RCC Read word unit of contact information ¶ÁÈ¡×Öµ¥Î»µÄ´¥µãµÄ״̬ÐÅÏ¢ X Y R L T C
|
//* WCC Write word unit of contact information дÈë×Öµ¥Î»µÄ´¥µãµÄ״̬ÐÅÏ¢ Y R L
|
// SC Preset word unit in contact area Ô¤ÖÃ×Öµ¥Î»µÄ´¥µã
|
//
|
//* RD Read data area ¶ÁÈ¡Êý¾Ý¼Ä´æÆ÷Öµ D L F
|
//* WD Write data area дÈëÊý¾Ý¼Ä´æÆ÷Öµ D L F
|
// SD Preset of data area Ô¤ÖÃÊý¾Ý¼Ä´æÆ÷Öµ
|
//
|
// RS Read timer and counter set value area ¶ÁÈ¡¶¨Ê±Æ÷/¼ÆÊýÆ÷Ä¿±êÖµ
|
// WS Write timer and counter set value area дÈ붨ʱÆ÷/¼ÆÊýÆ÷Ä¿±êÖµ
|
// RK Read timer and counter elapsed value area ¶ÁÈ¡¶¨Ê±Æ÷/¼ÆÊýÆ÷¾¹ýÖµ
|
// WK Write timer and counter elapsed value area дÈ붨ʱÆ÷/¼ÆÊýÆ÷¾¹ýÖµ
|
//
|
// MC Registration and reset of monitor contact µÇ¼¼°¸´Î»¼à¿Ø´¥µã
|
// MD Registration and reset of monitor data µÇ¼¼°¸´Î»¼à¿ØÊý¾Ý
|
// MG Monitor execution Ö´Ðмà¿Ø
|
//
|
// RR Read system register ¶Áȡϵͳ¼Ä´æÆ÷
|
// WR Write system register дÈëϵͳ¼Ä´æÆ÷
|
//
|
//* RT Read Programmable Controller (PC) status ¶ÁÈ¡PLC µ±Ç°×´Ì¬
|
// RP Read program ¶ÁÈ¡³ÌÐò
|
// WP Write program дÈë³ÌÐò
|
// RM Remote control (RUN/PROGRAM mode switching) Ò£¿Ø(ÔËÐÐ/±à³ÌģʽÇл»)
|
// AB Transmission abort command ´«ÊäÖÕÖ¹Ö¸Áî
|
// */
|
int RT(int Station2=0)
|
{
|
if (SimFunc)
|
{
|
|
}
|
if (!SerialPlc1.IsOpened) return 0;
|
int len;
|
CStringA s1;
|
int station3;
|
if (Station2==0) station3=Station;
|
else station3=Station2;
|
s1.Format("%%%02X#RT",station3);
|
s1.AppendFormat("%02X\r",(unsigned char)(BCC(s1)));
|
len=s1.GetLength();
|
myCriticalSection1.Lock(INFINITE);
|
SendPLCData(s1,len);
|
int j;
|
j=ReadPLCCom(buffer2,9+16);
|
myCriticalSection1.Unlock();
|
if (j>=9)
|
{
|
buffer2[j]=0;
|
s1=buffer2;
|
for (int i=0;i<16;i++)
|
{
|
InfoBytes.bytes[i]=buffer2[6+i];
|
}
|
PlcInfo.PlcType=xtoi(InfoBytes.PlcType,2);
|
PlcInfo.Version=xtoi(InfoBytes.Version,2);
|
PlcInfo.PrgSize=xtoi(InfoBytes.PrgSize,2);
|
PlcInfo.RunMode=xtoi(InfoBytes.RunMode,2);
|
PlcInfo.LinkInfo=xtoi(InfoBytes.LinkInfo,2);
|
PlcInfo.Errs=xtoi(InfoBytes.ErrMark,2);
|
PlcInfo.SelfTestInfo=xtoi(InfoBytes.SelfTestInfo,4);
|
|
return 1;
|
}
|
else
|
{
|
return 0;
|
}
|
}
|
int RCS(const char * typeaddr,int &value, int Station2=0) //RCS Read single point of contact information ¶ÁÈ¡µ¥¸ö´¥µãµÄ״̬ÐÅÏ¢ X Y R L T C
|
|
{
|
if (SimFunc)
|
{
|
myCriticalSection1.Lock(INFINITE);
|
CStringA stypeaddr;
|
stypeaddr=typeaddr;
|
CStringA type;
|
CStringA addr,Laddr,Raddr;
|
type=typeaddr[0];
|
addr="0000"+stypeaddr.Mid(1);
|
addr=addr.Right(4);
|
Laddr=addr.Left(3);
|
Raddr=addr.Right(1);
|
int Laddrv=atoi(Laddr);
|
int Raddrv=xtoi(Raddr);
|
if (type.MakeUpper()=="R")
|
{
|
value=(WR[Laddrv]&HexMask[Raddrv]);
|
simresult1=1;
|
}else {simresult1=0;}
|
myCriticalSection1.Unlock();
|
return simresult1;
|
}
|
if (!Connected) {return 0;}
|
|
CStringA stypeaddr;
|
stypeaddr=typeaddr;
|
CStringA type;
|
CStringA addr;
|
type=typeaddr[0];
|
addr="0000"+stypeaddr.Mid(1);
|
addr=addr.Right(4);
|
int len;
|
CStringA s1;
|
int station3;
|
if (Station2==0) station3=Station;
|
else station3=Station2;
|
s1.Format("%%%02X#RCS%c%s",station3,type[0],addr);
|
s1.AppendFormat("%02X\r",(unsigned char)(BCC(s1)));
|
len=s1.GetLength();
|
myCriticalSection1.Lock(INFINITE);
|
SendPLCData(s1,len);
|
int j;
|
j=ReadPLCCom(buffer2,9+2);
|
myCriticalSection1.Unlock();
|
if (j>=9)
|
{
|
value=buffer2[6]-48;
|
return 1;
|
}
|
else
|
{
|
return 0;
|
}
|
}
|
|
int WCS(const char * typeaddr, int value)
|
{
|
if (SimFunc)
|
{
|
myCriticalSection1.Lock(INFINITE);
|
CStringA stypeaddr;
|
stypeaddr=typeaddr;
|
CStringA type;
|
CStringA addr,Laddr,Raddr;
|
type=typeaddr[0];
|
addr="0000"+stypeaddr.Mid(1);
|
addr=addr.Right(4);
|
Laddr=addr.Left(3);
|
Raddr=addr.Right(1);
|
int Laddrv=atoi(Laddr);
|
int Raddrv=xtoi(Raddr);
|
if (type.MakeUpper()=="R")
|
{
|
if (value)
|
{
|
WR[Laddrv]|=HexMask[Raddrv];
|
|
}
|
else
|
{
|
WR[Laddrv]&=~HexMask[Raddrv];
|
}
|
simresult1=1;
|
}else simresult1=0;
|
myCriticalSection1.Unlock();
|
return simresult1;
|
}
|
|
if (!Connected) {return 0;}
|
CStringA s1;
|
CStringA type;
|
CStringA addr;
|
CStringA stypeaddr;
|
stypeaddr=typeaddr;
|
type=typeaddr[0];
|
addr="0000"+stypeaddr.Mid(1);
|
addr=addr.Right(4);
|
s1.Format("%%%02X#WCS%C%s%1X",Station,type[0],addr,value);
|
s1.AppendFormat("%02X\r",(unsigned char)(BCC(s1)));
|
int len;
|
len=s1.GetLength();
|
myCriticalSection1.Lock(INFINITE);
|
SendPLCData(s1,len);
|
len=ReadPLCCom(buffer2,9+2);
|
myCriticalSection1.Unlock();
|
CString s1T;
|
if (len<9)
|
{
|
s1T.Format(_T("WCS faild\r\n"),type);
|
return 0;
|
}
|
return 1;
|
}
|
|
|
int RCC(const char * typeaddr,int count,short int value[]) //count ×î´ó32
|
{
|
if (SimFunc)
|
{
|
myCriticalSection1.Lock(INFINITE);
|
CStringA stypeaddr,type,addr;
|
stypeaddr=typeaddr;
|
type=typeaddr[0];
|
addr=stypeaddr.Mid(1);
|
int addrv=atoi(addr);
|
if (type.MakeUpper()=="R")
|
{
|
for (int i=0;i<count;i++) { value[i]=WR[i+addrv]; }
|
}else if (type.MakeUpper()=="X")
|
{
|
for (int i=0;i<count;i++) { value[i]=WX[i+addrv]; }
|
}else if (type.MakeUpper()=="Y")
|
{
|
for (int i=0;i<count;i++) { value[i]=WY[i+addrv]; }
|
}else if (type.MakeUpper()=="L")
|
{
|
for (int i=0;i<count;i++) { value[i]=WL[i+addrv]; }
|
}
|
myCriticalSection1.Unlock();
|
return 1;
|
}
|
if (!Connected) {return 0;}
|
CStringA type;
|
int addr;
|
CStringA s1,s2;
|
type=typeaddr[0];
|
s1=typeaddr;
|
s1=s1.Mid(1);
|
CString s1T;
|
addr=atoi(s1);
|
if (count>32) {count=32;}
|
|
s1.Format("%%%02X#RCC%c%04d%04d",Station,type[0],addr,addr+count-1);
|
s1.AppendFormat("%02X\r",(unsigned char)(BCC(s1)));
|
int len=s1.GetLength();
|
myCriticalSection1.Lock(INFINITE);
|
SendPLCData(s1,len);
|
len=ReadPLCCom(s1.GetBuffer(512),9+count*4+1);
|
myCriticalSection1.Unlock();
|
s1.ReleaseBuffer(len);
|
int i;
|
if (len>9)
|
{
|
for (i=0;i<count;i++)
|
{
|
value[i]=xtoi(s1.Mid(6+i*4,2))+xtoi(s1.Mid(8+i*4,2))*256;
|
}
|
s1T.Format(_T("RCC %c%d %d OK %dB \r\n"),type[0],addr,count,len);
|
}else
|
{
|
for (i=0;i<count;i++)
|
{
|
value[i]=0;
|
}
|
return 0;
|
}
|
return 1;
|
}
|
int WCC(const char * typeaddr,int count,short int value[])
|
{
|
if (SimFunc)
|
{
|
myCriticalSection1.Lock(INFINITE);
|
CStringA stypeaddr,type,addr;
|
stypeaddr=typeaddr;
|
type=typeaddr[0];
|
addr=stypeaddr.Mid(1);
|
int addrv=atoi(addr);
|
if (type.MakeUpper()=="R")
|
{
|
for (int i=0;i<count;i++) { WR[i+addrv]=value[i]; }
|
}else if (type.MakeUpper()=="X")
|
{
|
for (int i=0;i<count;i++) { WX[i+addrv]=value[i]; }
|
}else if (type.MakeUpper()=="Y")
|
{
|
for (int i=0;i<count;i++) { WY[i+addrv]=value[i]; }
|
}else if (type.MakeUpper()=="L")
|
{
|
for (int i=0;i<count;i++) {WL[i+addrv]=value[i]; }
|
}
|
myCriticalSection1.Unlock();
|
return 1;
|
}
|
if (!Connected) {return 0;}
|
CStringA type;
|
int addr;
|
CStringA s1,s2;
|
type=typeaddr[0];
|
s1=typeaddr;
|
s1=s1.Mid(1);
|
addr=atoi(s1);
|
int i;
|
s1.Empty();
|
unsigned char low,high;
|
CString s1T;
|
for (i=0;i<count;i++)
|
{
|
low=value[i]%256;high=((unsigned)value[i])/256;
|
s1.AppendFormat("%02X%02X",low,high);
|
}
|
|
s2.Format("%%%02X#WCC%c%04d%04d%s",Station,type[0],addr,addr+count-1,s1);
|
s2.AppendFormat("%02X\r",((unsigned char) (BCC(s2))));
|
|
int len=s2.GetLength();
|
myCriticalSection1.Lock(INFINITE);
|
SendPLCData(s2,len);
|
len=ReadPLCCom(s1.GetBuffer(512),9+2);
|
myCriticalSection1.Unlock();
|
s1.ReleaseBuffer(len);
|
if (len>0)
|
{
|
}else
|
{
|
s1T.Format(_T("WCC %c%d %d failed \r\n"),type[0],addr,count);
|
}
|
return 1;
|
}
|
int RD(const char * typeaddr,int count,short int value[])
|
{
|
if (SimFunc)
|
{
|
myCriticalSection1.Lock(INFINITE);
|
CStringA stypeaddr,type,addr;
|
stypeaddr=typeaddr;
|
type=typeaddr[0];
|
addr=stypeaddr.Mid(1);
|
int addrv=atoi(addr);
|
if (type.MakeUpper()=="D")
|
{
|
if (addrv+count<32768)
|
{
|
for (int i=0;i<count;i++) { value[i]=DT[i+addrv]; }
|
}
|
else if (addrv>=90000)
|
{
|
for (int i=0;i<count;i++) {value[i]=SDT[i+addrv-90000];}
|
}
|
else { }
|
}else if (type.MakeUpper()=="L")
|
{
|
for (int i=0;i<count;i++){ value[i]=LD[i+addrv];}
|
}
|
myCriticalSection1.Unlock();
|
return 1;
|
}
|
if (!Connected) {return 0;}
|
CStringA type;
|
int addr;
|
CStringA s1,s2;
|
CString s1T;
|
type=typeaddr[0];
|
s1=typeaddr;
|
s1=s1.Mid(1);
|
|
addr=atoi(s1);
|
if (count>32) {count=32;}
|
|
s1.Format("%%%02X#RD%c%05d%05d",Station,type[0],addr,addr+count-1);
|
s1.AppendFormat("%02X\r",(unsigned char)BCC(s1));
|
int len=s1.GetLength();
|
myCriticalSection1.Lock(INFINITE);
|
SendPLCData(s1,len);
|
len=ReadPLCCom(s1.GetBuffer(512),9+count*4+1);
|
myCriticalSection1.Unlock();
|
s1.ReleaseBuffer(len);
|
if (len>9)
|
{
|
int i;
|
for (i=0;i<count&&i*4+9<=len;i++)
|
{
|
value[i]=xtoi(s1.Mid(6+i*4,2))+xtoi(s1.Mid(8+i*4,2))*256;
|
}
|
for (;i<count;i++) //Ê£ÓàµÄ¡£
|
{ value[i]=0; }
|
}
|
else
|
{
|
for (int i=0;i<count;i++) { value[i]=0; }
|
s1T.Format(_T("RD %c%d %d failed \r\n"),type[0],addr,count);
|
return 0;
|
}
|
return 1;
|
}
|
int WD(const char * typeaddr,int count,short int value[])
|
{
|
if (SimFunc)
|
{
|
myCriticalSection1.Lock(INFINITE);
|
CStringA stypeaddr,type,addr;
|
stypeaddr=typeaddr;
|
type=typeaddr[0];
|
addr=stypeaddr.Mid(1);
|
int addrv=atoi(addr);
|
if (type.MakeUpper()=="D")
|
{
|
if (addrv+count<32768)
|
{
|
for (int i=0;i<count;i++){DT[i+addrv]=value[i]; }
|
}else if (addrv>=90000)
|
{
|
for (int i=0;i<count;i++){ SDT[i+addrv-90000]=value[i];}
|
}else{ }
|
} else if (type.MakeUpper()=="L")
|
{
|
for (int i=0;i<count;i++){LD[i+addrv]=value[i]; }
|
}
|
myCriticalSection1.Unlock();
|
return 1;
|
}
|
if (!Connected) {return 0;}
|
CStringA type;
|
int addr;
|
CStringA s1,s2;
|
CString s1T;
|
type=typeaddr[0];
|
s1=typeaddr;
|
s1=s1.Mid(1);
|
addr=atoi(s1);
|
int i;
|
s1.Empty();
|
unsigned char low,high;
|
|
for (i=0;i<count;i++)
|
{
|
low=value[i]%256;high=((unsigned)value[i])/256;
|
s1.AppendFormat("%02X%02X",low,high);
|
}
|
|
s2.Format("%%%02X#WD%c%05d%05d%s",Station,type[0],addr,addr+count-1,s1);
|
s2.AppendFormat("%02X\r",((unsigned char) (BCC(s2))));
|
|
int len=s2.GetLength();
|
myCriticalSection1.Lock(INFINITE);
|
SendPLCData(s2,len);
|
len=ReadPLCCom(s1.GetBuffer(512),9+2);
|
myCriticalSection1.Unlock();
|
s1.ReleaseBuffer(len);
|
if (len>0) { return 1; }
|
else{
|
s1T.Format(_T("WD %c%d %d failed \r\n"),type[0],addr,count);
|
return 0;
|
}
|
return 1;
|
}
|
};
|
|
|