用向导建立一个单文档的程序,加入上面的类
在“关于”对话框类中,加入私有成员my类型为ty 代码如下:能向串口发出数据
void CAboutDlg::OnOK() 
{
int i,state;
state=my.CommOpen(2,57600,8,1,0);
unsigned char send[20];
CTime time;
time=CTime::GetCurrentTime();
send[0]=0x04;
send[1]=0x0B;
send[2]=time.GetSecond();//second
send[3]=time.GetMinute();//minute
         send[4]=time.GetHour();//hour
send[5]=time.GetDay();//day
send[6]=time.GetMonth();//month
send[7]=yea=time.GetYear();//year
send[8]=time.GetDayOfWeek();//week
for(i=0;i<9;i++)
{
state=my.WriteCommByte(send[i]);
}
my.CommClose();

/// CDialog::OnOK();
}
在视图类中,加入私有成员my类型为ty 代码如下:不能向串口发出数据void CTIView::OnPtime() 
{
int i,state;
state=my.CommOpen(2,57600,8,1,0);
unsigned char send[20];
CTime time;
time=CTime::GetCurrentTime();
send[0]=0x04;
send[1]=0x0B;
send[2]=time.GetSecond();//second
send[3]=time.GetMinute();//minute
         send[4]=time.GetHour();//hour
send[5]=time.GetDay();//day
send[6]=time.GetMonth();//month
send[7]=yea=time.GetYear();//year
send[8]=time.GetDayOfWeek();//week
for(i=0;i<9;i++)
{
state=my.WriteCommByte(send[i]);
}
my.CommClose();
}
其中my是我自已写的一个类的实例,这个类的详细代码在
http://expert.csdn.net/Expert/topic/2301/2301483.xml?temp=.7145044