// CommWizardDlg.cpp : implementation file
//
#include "stdafx.h"
#include "lientSocket.h" //2011/09/29ywd 写得太困了
#include "CommWizard.h"
#include "CommWizardDlg.h"
#include "SettingDlg.h"
#include "access.h"//ywd add
//#include "lst.h"
#include "lientSocket.h" //2011/09/29ywd 写得太困了
#include "GargeManageDlg.h"//ywd add 2011/09/26
#include "ctype.h" //ywd add
#include "LishiDialog.h"//ywd
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
int gytime;
//int clientserver_flag;//2011/10/09
char jintaiyangflag=0;
float vol_dc,c_dc;
float vol_ac,c_ac;
char buffcli[30];//来自金太阳客户端数据
float gyfloatfuzhao;
float gyfloatrizhao;
unsigned char gyfengsu;
unsigned char gyfengxian;
char daqi;
float gy_float111;
float gy_float222;
float gy_float333;
float gy_float444;
int power11,power22,power33,power44,power55,power66,power77,power88;
float gy_float555;
float gy_float666;
float gy_float777;
float gy_float888;
unsigned int gydcvol1,gydcvol2,gydcvol3,gydcvol4,gydcvol5,gydcvol6,gydcvol7,gydcvol8;
unsigned int gydccur1,gydccur2,gydccur3,gydccur4,gydccur5,gydccur6,gydccur7,gydccur8;
unsigned int gyacvol1,gyacvol2,gyacvol3,gyacvol4,gyacvol5,gyacvol6,gyacvol7,gyacvol8;
unsigned int gyaccur1,gyaccur2,gyaccur3,gyaccur4,gyaccur5,gyaccur6,gyaccur7,gyaccur8;
unsigned int freq;
int shebeiwendu1,shebeiwendu2,shebeiwendu3,shebeiwendu4,shebeiwendu5,shebeiwendu6,shebeiwendu7,shebeiwendu8;
unsigned long gyfadian1,gyfadian2,gyfadian3,gyfadian4,gyfadian5,gyfadian6,gyfadian7,gyfadian8;
unsigned long gyzongfadian1,gyzongfadian2,gyzongfadian3,gyzongfadian4,gyzongfadian5,gyzongfadian6,gyzongfadian7,gyzongfadian8;
unsigned int dayrun1,dayrun2,dayrun3,dayrun4,dayrun5,dayrun6,dayrun7,dayrun8;
unsigned int zongrun1,zongrun2,zongrun3,zongrun4,zongrun5,zongrun6,zongrun7,zongrun8;
unsigned char modbus_tt[4]={0};//char modbus_tt[4]={0};20111212记得一定要改成此类型
int regflag=1;
int fywd=0x04;
extern void CServerSocket::OnSendServer(int nErrorCode);
int jihao=1;
int reg2flag=0;
int reg4flag=0;
int iii=0;
int shebeiwendu=0;
//这是一个将字符转换为相应的十六进制值的函数
//功能:若是在0-F之间的字符,则转换为相应的十六进制字符,否则返回-1
char CCommWizardDlg::ConvertHexChar(char ch)
{
if((ch>='0')&&(ch<='9'))
return ch-0x30;
else if((ch>='A')&&(ch<='F'))
return ch-'A'+10;
else if((ch>='a')&&(ch<='f'))
return ch-'a'+10;
else return (-1);
}
/////////////////////////////////
unsigned char hex_ascii(unsigned char d)
{
if (d<10)
d=d+0x30;
else
d=d+0x37;
return(d);
}
//将ASCII码转化为16进制数
BYTE ASCIIToHexChar(BYTE ch)
{
if((ch>='0')&&(ch<='9'))
{
return ch-0x30;
}
else if((ch>='A')&&(ch<='F'))
{
return ch-'A'+10;
}
else if((ch>='a')&&(ch<='f'))
{
return ch-'a'+10;
}
else
{
return -1;
}
}
//************************************
//函数名称:int StrToHex(const char *str, char *hex, UINT nLength)
//功 能:将字符串(不一定是以'/0'结尾的)转化为十六进制表示的字符串,
//如:"HELLO"-->"48 45 4C 4C 4F" nLength可以指定为字符串的实际长度
//参数说明:str--------需要转换的字符串
// hex -------转换后的字符串
// nLength----需要转换的字符串的长度(对不以'/0'结束的无符号数组,需要指明长度)
//返 回 值:零,成功
//************************************
int StringToHexing(const char *str, char *hex , UINT nLength)
{
int i;
for (i=0;i<(int)nLength;i++)
{
sprintf(hex+i*3,"%02X ",str[i]&0xFF); //将字符转化为相应的十六进制表示
}
return 0;
}
//************************************
//函数:ByteArrayToHex
//功能:字符数组的ASC转化位16进制
//参数:size为要转换的字节数组长度
//备注:调用如:
//char asc[]="123";
//static char buf[100];
//FormatToHex(buf,asc,sizeof(asc));
//输出字符串--"31 32 33 00 "
//************************************
//void ByteArrayToHex(char *pOut,BYTE *pIn,int size)
void ByteArrayToHex(char *pOut,char *pIn,int size)
{
char dl,dh;
for(int k=0;k<size;k++)
{
dl=pIn[k] & 0x0F;
pOut[3*k+1]=((dl<0xA)? dl+0x30 : dl+0x37);
dh=(pIn[k] >> 4) & 0x0F;
pOut[3*k]=((dh<0xA)? dh+0x30 : dh+0x37);
pOut[3*k+2]=0x20;
}
}
//这是一个将字符转换为相应的十六进制值的函数
//功能:若是在0-F之间的字符,则转换为相应的十六进制字符,否则返回-1
char ConvertHexChar(char ch)
{
if((ch>='0')&&(ch<='9'))
return ch-0x30;
else if((ch>='A')&&(ch<='F'))
return ch-'A'+10;
else if((ch>='a')&&(ch<='f'))
return ch-'a'+10;
else return (-1);
}
//字符串转换成16进制显示
int String2Hex(CString str, CByteArray &senddata)
{
int hexdata,lowhexdata;
int hexdatalen=0;
int len=str.GetLength();
senddata.SetSize(len/2);
for(int i=0;i<len;)
{
char lstr,hstr=str[i];
if(hstr==' ')
{
i++;
continue;
}
i++;
if(i>=len)
break;
lstr=str[i];
hexdata=ConvertHexChar(hstr);
lowhexdata=ConvertHexChar(lstr);
if((hexdata==16)||(lowhexdata==16))
break;
else
hexdata=hexdata*16+lowhexdata;
i++;
senddata[hexdatalen]=(char)hexdata;
hexdatalen++;
}
senddata.SetSize(hexdatalen);
return hexdatalen;
}
unsigned char Data_buf_ASCII[2];
//第一个字节11就转换成31 31两个字节,那么PC那边就显示成11啦。
void hctoa(unsigned char buf_char)
{
unsigned char count,c;
for(count=0;count<2;count++)
{
if(count==0)
c = buf_char>>4;
else
c = buf_char;
c &= 0x0f;
if( c>=0 && c<=9 )
Data_buf_ASCII[count] = '0' + c;
else
Data_buf_ASCII[count] = 'A' + c - 10;
}
}
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
UINT CCommWizardDlg:: ThreadFunc(LPVOID pParam) //辅助线程
{
//20111205((CCommWizardDlg*)pParam)->communcation(); //**在AUTOTEST平台中有问题YWD*//
// 20111205((CCommWizardDlg*)pParam)->addRecordset();//ywd 此函数只是初始化的//2011/08/23ywd
((CCommWizardDlg*)pParam)->OnButtonSendclient();
return 0;
}
/////////////////////////////////////////////////////////////////////////////
// CCommWizardDlg dialog
CCommWizardDlg::CCommWizardDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCommWizardDlg::IDD, pParent)
{
//2011/10/10为了防止打开主界面一直跳出串口未联就把它放在setting
bSend = FALSE;
bReceive = FALSE;
clientserver_flag=TRUE;//FALSE;
m_nPort =1;//1;//3;//2011/10/08 4;//2011/09/28YWD edit // 1;
m_strSettings = _T("9600,n,8,1");
m_strSendString = _T("");
m_nTime =1000;// 3000;//m_nTime = 1000;
m_nInputMode = 1;
//{{AFX_DATA_INIT(CCommWizardDlg)
m_strReceive = _T("");
m_CsEdit = _T("");
m_strIP =_T("xxxxxx");// _T("127.0.0.1"); //2011/09/30ywd
m_nIPPort =502;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CCommWizardDlg::DoD
评论7
最新资源