This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] CCS/TM4C1294NCPDT:TM4C1294NCPDT 网站服务器 javascript 问题

Guru**** 2482155 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/716629/ccs-tm4c1294ncpdt-tm4c1294ncpdt-website-server-javascript-problem

器件型号:TM4C1294NCPDT

工具/软件:Code Composer Studio

您好!

我正在尝试更新网站上的一些测量结果。 过去我使用了 http 的 SSI 和 CGI 功能、它运行正常、但我必须刷新整个页面才能更新字段。 我现在尝试使用 JavaScript 和 XML 功能来实现它。 我的变量显示在网页上时出现问题。 在使用 ADC 测量对其进行高级测试时,我将其转换为2个整数(一个表示整数和小数),并使用 TI usnprintf()函数。 使用此函数、我将其转换为字符串、并将其返回到 psFile 结构中。 在网页上、我会看到如下所示。 是否有来自经验丰富的用户的线索?  

 usnprintf()不支持 float,因此我使用两个变量在字符串中表示浮点。 我使用了原始 sprintf 函数将 float 转换为 str. 这将占用更多的堆栈空间、我在屏幕上看到类似的不可读标志。

负责将句柄返回到更新数据的代码: 

fs_open (const char * pcName)
{
.
。
。
。
//
//电压
//
否则 if (ustncmp (pcName、"/voltage、8)=0)
{
uint32_t pui32ADC0Value2[1]、pui32ADC0Value_i2、pui32ADC0Value_f2;
float pui32ADC0Valuef2;


char pcBuf[5];
ADCSequenceDataGet (ADC0_BASE、3、pu32ADC0Value2);
pui32ADC0Valuef2=(float) pui32ADC0Value2[0]/4096.0*3.3;
pui32ADC0Value_int2=(int) pui32ADC0Valuef2;
pui32ADC0Value_frar2=(int)((pui32ADC0Valuef2-pui32ADC0Value_int2)*1000);


usnprintf (pcBuf、5、"%d.%d"、pui32ADC0Value_int2、pui32ADC0Value_分数2);

psFile->data = pcBuf;
psFile->len = strlen (pcBuf);
psFile->index = psFile->len;
psFile->pextension = NULL;
return (psFile);
}
。

.} 



JavaScript 中负责此部分的部分:

函数电压()
{
var req = false;

函数 VoltageComplete()
{
if (req.readyState == 4)
{
if (req.status =200)
{
document.getElementById ("电压").innerHTML =" 
"+ REQ.responseText +"
"; } } if (window.XMLHttpRequest) { REQ =新的 XMLHttpRequest(); } 否则 if (window.ActiveXObject) { REQ =新的 ActiveXObject ("Microsoft.XMLHTTP"); } if (req) { REQ.open ("get"、"/voltage?id"+ Math.random ()、true); REQ.onreadystatechange = VoltageComplete; req.send(null); } }

与 JavaScript voltage ()函数相关的 http 代码:

电压: 

-

提前感谢您。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    您是否已验证您是否在 pcBuf 中获得了正确的字符串并且它是 NULL 终止的?
  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    尊敬的 Bob:

    帮助我跟踪问题。


    谢谢。