声明:这里面的代码均为网上找的然后有小小的改动,并非原创。但文章为原创
一、.编译
1.1,、下载:进入http://embedthis.com/goahead/下载goahead3.6.3(2017年9月12日还是这版本)
1.2、解压
,
然后进入goahead-3.6.3-rc目录,进入后为这样
,
然后在进入goahead-3.6.3
然后在终端中进入goahead-3.6.3,然后输入make进行编译(该方式默认是生成x86架构的程序),如图:
二、简单使用
2.1、首先在生成的可执行文件的同级目录创建一个auth.txt(可以为空)和route.txt(内容为下图中行开始没有‘#’符号的行,#开始表示注释)文件 ,如果不创建的话在运行goahead时需要加参数指定文件,否则goahead无法运行
2.2.在编译生成的二进制文件的同一级目录中创建一个目录(名字随意,这里用web)用来存放html和js文件
2.3、在web目录中创建一个文件,名为aspTest.html或aspTest.asp(这里为aspTest.asp),内容为
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<h4>串口状态</h4>
<table id="viewTab" class="viewTab" cellspacing="0" cellpadding="0">
<tr>
<th width="">串口</th>
<th width="">线路协议</th>
<th width="">波特率(bps)</th>
<th width="">数据位</th>
<th width="">起始位</th>
<th width="">停止位</th>
<th width="">奇偶校验</th>
<th width="">流控</th>
</tr>
<% MakePortAttributeList("1", "Test", "Lanj"); %>
</table>
</html>
2.4. 在goahead.c文件中的main函数中websServiceEvents(&finished);之前添加websDefineJst("MakePortAttributeList", getPortAttrib);,然后在goahead.c文件的开头声明static void getPortA(Webs *wp, STPortAttributeList *PortAttributeList);和static int getPortAttrib(int eid, Webs *wp, int argc, char **argv); // 原型。然后实现这两个函数
typedef struct PortAttributeList{
char *port;
char *agreement;
char *bandrate;
char *figure;
char *outset;
char *termination;
char *parityCheck;
char *flowControl;
}STPortAttributeList;
static void getPortA(Webs *wp, STPortAttributeList *PortAttributeList)
{
PortAttributeList[0].port="1";
PortAttributeList[0].agreement="RS232";
PortAttributeList[0].bandrate="1200";
PortAttributeList[0].figure="8";
PortAttributeList[0].outset="1";
PortAttributeList[0].termination="1";
PortAttributeList[0].parityCheck="ODD";
PortAttributeList[0].flowControl="Hardware";
PortAttributeList[1].port="2";
PortAttributeList[1].agreement="RS485";
PortAttributeList[1].bandrate="9600";
PortAttributeList[1].figure="8";
PortAttributeList[1].outset="1";
PortAttributeList[1].termination="1";
PortAttributeList[1].parityCheck="EVEN";
PortAttributeList[1].flowControl="NO";
}
static int getPortAttrib(int eid, Webs *wp, int argc, char **argv)
{
int i=0;
int SerialNum = 2;
STPortAttributeList PortAttributeList[SerialNum];
printf("Parameter = %d
",argc);
while(i < argc)
{
printf("Parameter %d = %s
",i,*(argv+i));
i++;
}
i = 0;
getPortA(wp,PortAttributeList);
while(i<SerialNum)
{
websWrite(wp,"<tr>");
websWrite(wp,"<td>%s</td>",PortAttributeList[i].port);
websWrite(wp,"<td>%s</td>",PortAttributeList[i].agreement);
websWrite(wp,"<td>%s</td>",PortAttributeList[i].bandrate);
websWrite(wp,"<td>%s</td>",PortAttributeList[i].figure);
websWrite(wp,"<td>%s</td>",PortAttributeList[i].outset);
websWrite(wp,"<td>%s</td>",PortAttributeList[i].termination);
websWrite(wp,"<td>%s</td>",PortAttributeList[i].parityCheck);
websWrite(wp,"<td>%s</td>",PortAttributeList[i].flowControl);
websWrite(wp,"</tr>");
i++;
}
return 0;
}
2.5.重新编译goahead,然后在终端中进入goahead可运行文件的目录,然后执行sudo ./goahead -v ./web,最后在浏览器中访问127.0.0.1/aspTest.html