02-25-2008 10:25 PM
02-25-2008 11:55 PM
02-26-2008 09:35 AM
code for opening com port is as below
status = OpenComConfig (comport1, devicename, 9600, 0, 8, 1, 0, 0);
//配置失败,显示出错信息
if(status!=0)
{
MessagePopup ("Error", "TPG1串口配置错误Config failed!");
}
//openTPG2com:
status = OpenComConfig (comport2, devicename, 9600, 0, 8, 1, 0, 0);
//配置失败,显示出错信息
if(status!=0)
{
MessagePopup ("Error", "TPG2串口配置错误Config failed!");
}
02-26-2008 09:41 AM
My main code is as below: I have deleted some code without relation to communication with com port
int j;//cycle variable for data string copy
int i;//cycle variable for sample data from multi-channel
if(strcmp(TimeStr(),"00:00:00")==0)//08:49:44
{
CloseFile (filehandle);
for(i=0;i<10;i++)
{
datestr[i]=*(DateStr()+i);
}
datestr[10]='.'; datestr[11]='t'; datestr[12]='x'; datestr[13]='t'; datestr[14]='\0';
filehandle = OpenFile (datestr,VAL_READ_WRITE, VAL_APPEND, VAL_ASCII);
}
switch (event)
{
case EVENT_TIMER_TICK:
{
if(filehandle!=-1)
{
WriteFile (filehandle, TimeStr (), 8);
}
for(i=0;i<6;i++)
{
//step1
step1: ComWrt ((i/3+2),str1[(i%3)+3], 4);
//if(status!=4)
//{
//MessagePopup ("Error", "Send data step1 failed!");
//}
//step2
step2: status=ComRd((i/3+2),rdcom, 3);
rdcom[3]='\0';
if(status!=3)
{
//if a error happens during reading com port,then there will be message popup
MessagePopup ("Error", "Read data setp_2 failed!");
}
//step3
step3: if((((rdcom[0]-str2[0])||(rdcom[1]-str2[1])||(rdcom[2]-str2[2]))==0))//check the letters ( one by one) in the return string
{
ComWrt ((i/3+2),str3, 1);
//if(status!=1)
//{
//MessagePopup ("Error", "Send data step3 failed!");
//}
}
else
{
MessagePopup ("Error", "Read data setp_2 未返回正常数据!");
}
//step4
step4: status=ComRd((i/3+2),str4,12);
//for quick
if(status!=12)
{
//读取数据失败,显示出错信息并退出
MessagePopup ("Error", "Step_4 Read data failed!");
//SetCtrlVal (panelHandle4, PANEL4_LED4_2, 1);
}
/*else
{
SetCtrlVal (panelHandle4, PANEL4_LED4, 1);
}*/
02-26-2008 09:42 AM
add the below code to the end of last message
//choose the real data,delete the sensor status
//0,-0.001E+2
//0,0.001E+2
switch(str4[0])
{
case 48:
{
if(str4[2]!='-')
{
for(j=0;j<6;j++)
{
str5[j]=str4[j+2];//基数部完成1.234 str5[0~4]
}
if(str4[8]=='+')//str4 0,1.234E+5 str5=1.234E+4
{
str5[7]=str4[9]+2;//data of TPG is mbar,to be Pascal we have to multiplate 100
str5[6]=43;
}
else//以下都为负指数bar
{
if(str4[9]>'2')//如果为-2次bar以下
{
str5[6]='-';
str5[7]=str4[9]-2;
}
else//-2 and -1
{
if(str4[9]=='1')
{
str5[6]='+';
str5[7]='1';
}
else
{
str5[6]='+';
str5[7]='0';
}
}
}
str5[8]='\0';
}
else
{
ComRd((i/3+2),str0,1);
for(j=0;j<8;j++)
{
str5[j]=str4[j+3];
}
str5[8]='\0';
}
break;
}
case 49:
{
strcpy(str5,"UnderRan");
break;
}
case 50:
{
strcpy(str5,"OverRang");
break;
}
case 53:
{
strcpy(str5,"NoSensor");
break;
}
}
//display data in the table control SetTableCellVal (panelHandle, PANEL_TABLE, MakePoint(1,i+1), str5);
//output the data sampled from com port
str6[3]=(i%3)+49;//00i的i
if(filehandle!=-1)
{
WriteFile (filehandle,str6,5);
WriteFile (filehandle,strcat(str5,","),9);
}
//do the alarm check
if((str4[0]==48)&&(strtonum(str5)>uplim[i])&&(limflag[i]))
{
if(alarmsoundenable)
{
LaunchExecutable ("d:\\Program Files\\TTPlayer\\TTPlayer.exe");
}
SetTableCellAttribute (panel, PANEL_TABLE, MakePoint(1,i+1), ATTR_TEXT_BGCOLOR, VAL_RED);
SetTableCellAttribute (panel, PANEL_TABLE, MakePoint(3,i+1), ATTR_TEXT_BGCOLOR, VAL_RED);
}
Delay (0.01);
ProcessSystemEvents ();