C++ UART Infite loop with the TI-Nspire
C++ UART Infite loop with the TI-Nspire
这是由于表中的编译错误的延续C++
所以这是我的程序:
#include <os.h>
#include <nspireio/uart.hpp>
#include <nspireio/console.hpp>
int key_already_pressed = 0;
char oldinput[100] = {0};
char voidlist[100] = {0};
/*
void messagel(void) {
if(messagemode){
if(isKeyPressed(KEY_NSPIRE_A) && !key_already_pressed) {
nio_printf("A");
uart_printf("A");
//strcat(message,"A");
key_already_pressed = 1;
}
if(isKeyPressed(KEY_NSPIRE_B) && !key_already_pressed) {
nio_printf("B");
uart_printf("B");
//strcat(message,"B");
key_already_pressed = 1;
}
if(isKeyPressed(KEY_NSPIRE_ENTER) && messagemode && !key_already_pressed) {
messagemode = 0;
key_already_pressed = 1;
}
if(!any_key_pressed())
key_already_pressed = 0;
}
}*/
int main(void)
{
assert_ndless_rev(874);
//clrscr();
nio_console csl;
nio_init(&csl,NIO_MAX_COLS,NIO_MAX_ROWS,0,0,NIO_COLOR_WHITE,NIO_COLOR_BLACK,TRUE);
nio_set_default(&csl);
nio_color(&csl,NIO_COLOR_BLACK,NIO_COLOR_WHITE);
nio_printf("Nspire UART Chat by Samy. Compiled the %s At %sn",__DATE__,__TIME__);
nio_color(&csl,NIO_COLOR_WHITE,NIO_COLOR_BLACK);
nio_puts("Press any ESC to exit and CTRL to send msg...n");
while(!isKeyPressed(KEY_NSPIRE_ESC)){
if(isKeyPressed(KEY_NSPIRE_CTRL) && !key_already_pressed){
nio_printf(">");
char input[100] = {0};
nio_getsn(input,100);
uart_printf(input);
key_already_pressed = 1;
}
if(!any_key_pressed())
key_already_pressed = 0;
if(uart_ready()) {
char input[100] = {0};
getline(input,100);
if(oldinput != input) {
if(input != voidlist) {
nio_puts(input);
strcpy(oldinput,input);
strcpy(input,voidlist);
}
}
}
}
nio_puts("Closing the programm.");
nio_free(&csl);
return 0;
}
程序在 TI 屏幕和串行输出上持续发送一个字母。例如,如果我在串行监视器中写 lol,它将无限发送 l,如果我发送一个新字符串,字母不会改变。
我真的希望这个程序在周末结束时完全工作,所以告诉我我做错了什么?
PS:我是法国人
让我们看看你的代码的这一部分
if(uart_ready()) {
char input[100] = {0};
getline(input,100);
if(oldinput != input) {
if(input != voidlist) {
nio_puts(input);
strcpy(oldinput,input);
strcpy(input,voidlist);
}
}
}
您正在检查 UART 是否已准备就绪,如果是这样,您正在声明一个包含 100 个元素的字符 arry。到这里还好。但是你在做什么比:
if(oldinput != input) {
您将数组 'oldinput' 的地址与之前声明的 'input' 数组的地址进行比较。 我假设您真正想要的是比较这两个字符数组的内容,因为"oldinput"和"input"将始终不相等。
你真正想要的是这个:
if(strcmp(oldinput,input) != 0){
这将比较这些字段的实际内容。但请注意,此函数假定字符串末尾有一个 null 终止符!!下一个"如果"也是如此。
尝试解决此问题,它可能会帮助您解决问题。
C 语言中的字符串
PS:我是德国人,但谁在乎XP
在 github 上放置问题后,我使一切正常 链接: GitHub 问题
相关文章:
- 这对"With a stackless coroutine, only the top-level routine may be suspended."意味着什么
- Doees the 'this' 指针参与虚函数的多态行为
- 为什么我会收到"Run-Time Check Failure #2 - Stack around the variable 'pr' was corrupted"错误?
- 您将如何连接"on the fly"文本+整数并将其传递给函数?
- 如何理解"Temporary objs are destroyed as the last step in evaluating the full-expression"?谁能用一些简单的例子来说明这
- 如何解决C++中声纳库贝静态代码分析错误"Explicitly define the missing copy constructor, move constructor .."
- Configuring the MPEG4MediaSink
- 这在C++ "It does not own the underlying data, and so is cheap to copy or assign"中意味着什么
- What is the std::chrono::time_point equivalent of std::numer
- 如何在数据库程序中添加"reduce the quantity of an item"功能?
- 使用自定义 nodejs 插件时的"The specified module could not be found"
- Boost.Python 和导入 dll,"The specified module could not be found"
- "Build succeeded"但"The breakpoint will not currently be hit"
- 尝试应用肖恩父母谈话"inheritance is the base class of evil"中的模式
- 为什么'allocate in one library and free in the other'是错误的
- 如何修复此错误"the value of 'x1' is not usable in a constant expression"?static_assert
- Count the digits
- 加载安全区图像"A device attached to the system is not functioning"
- 调用 dll 函数时"Run-Time Check Failure #0 - The value of ESP"
- C++ UART Infite loop with the TI-Nspire