void vdg1105::OnOnCommMscomm1()
{
// TODO: Add your control notification handler code here
int cResult1 = 0;
int iReturn;
char szHex[10];
char buffer[1024];
int iIndex = 0;
BYTE cResult = 0;
int tmp="0";
int i="0" ;
VARIANT variant_inp;
COleSafeArray safearray_inp;
LONG k,len;
int recdata="0";
CString m_strRXData,strtemp;
BYTE rxdata[15]; //
char tmphv,tmphi;
if(m_vdg1105ctrl.GetCommEvent()==2)//事件值为2表示接收缓冲区内有字符
{
m_vdg1105ctrl.SetInputLen(0);
//读取控件中缓冲区中全部内容
variant_inp=m_vdg1105ctrl.GetInput(); //读缓冲区
safearray_inp=variant_inp; //VARIANT型变量转换为ColeSafeArray型变量
len = safearray_inp.GetOneDimSize();//得到有效数据长度
for (k = 0; k < len; k++)
{
safearray_inp.GetElement(&k, &rxdata[k]); //转换为BYTE型数组
}
for(k=0;k<len;k++) //将数组转换为Cstring型变量
{
BYTE bt=*(char*)(rxdata+k); //字符型
strtemp.Format("%c ",bt); //将字符送入临时变量strtemp存放
m_strRXData+=strtemp; //加入接收编辑框对应字符串
SetDlgItemText(IDC_EDIT8, m_strRXData);
if (FirSet)
{
if (rxdata[k]==0x07 )
{
goto end;
}
if (rxdata[k]==0xf1)
{
FirSet="false";
goto end;
}
}
else
{
RCda[comnum++]=rxdata[k];
}
for (i=0;i<comnum;i++)
{
if (RCda== 0xaa && RCda[i+1] == 0x07 && RCda[i+2] == 0xf1)
{
first3ok=true;
first3okpostion=i;
goto two;
}
goto end;
}
two:if (first3ok)
{
for (i=first3okpostion+1;i<comnum;i++)
{
if (RCda== 0xaa && RCda[i+1] == 0x07 && RCda[i+2] == 0xf1)
{
two3ok=true;
two3okpostion=i;
goto val;
}
}
}
val:if (two3ok)
{
for(i=0;i<comnum;i++)
{
RCdanew=RCda;
}
for (int i="first3okpostion"+1;i<two3okpostion;i++)
{
if (RCdanew== 0xaa && RCdanew[i+1]==0x00)
{
for(int j="i"+1;j<two3okpostion;j++)
RCdanew[j]=RCdanew[j+1];//去掉接受数据中0xaa后面的0x00
}
}
tmp = RCdanew[first3okpostion+3]<<8 ;
m_times = tmp+RCdanew[first3okpostion+4];
tmp = RCdanew[first3okpostion+5]<<8;
actwave_HV= (tmp+RCdanew[first3okpostion+6])/10.0;
tmp = RCdanew[first3okpostion+7]<<8;
actwave_HI= (tmp+RCdanew[first3okpostion+8])/100.0;
/* if (m_times>m_timesold+1)
{
actwave_HV=actwave_HVold;
actwave_HI=actwave_HIold;
m_times=m_timesold;
}*/
m_timesold=m_times;
actwave_HVold = actwave_HV;
actwave_HIold = actwave_HI;
if (m_times < m_Value_YDTimes)
{
ShowHVHI();//在波形图上显示电压,电流,时间等
}
else
{
}
comnum =3;
RCda[0]=0xaa;
RCda[1]=0x07;
RCda[2]=0xf1;
FirSet=true;
two3ok=false;
first3ok=false;
SetDlgItemInt(IDC_EDIT7, m_times);
UpdateData(false);
}
end:;
}
}
}
偶滴个神啊,偶调了整整两夜,终于搞定了,我容易嘛我,特发此日记,纪念一下我的思路.
文章评论(0条评论)
登录后参与讨论