Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

readDec and dscan don't work correctly with serial.h #167

Open
AndyLindsay opened this issue Jan 23, 2018 · 0 comments
Open

readDec and dscan don't work correctly with serial.h #167

AndyLindsay opened this issue Jan 23, 2018 · 0 comments
Labels

Comments

@AndyLindsay
Copy link
Contributor

It looks like the culprit is in the simpletext library's _safe_gets function. The hardware echo feature that's useful for the terminal with half duplex serial ends up causing trouble for other device communication. Before removing or making hardware echo a configurable feature, existing serial and fdserial apps will need to be tested. This would also have to be coordinated with a blocklyprop terminal update.

Below is a block comment that I would recommend adding. Alternately, it could be something that only gets executed when rxPin == 31 and txPin == 30, and maybe some mode conditions.

#include <ctype.h>
#include "simpletext.h"

char* _safe_gets(text_t *text, char* origBuf, int count)
{
  char* buf = origBuf;
  while (count-- > 0)
  {
      int ch = text->rxChar(text);
      
      /*
      
      if (ch == 8 || ch == 127)
      {
          if (buf > origBuf)
          {
              text->txChar(text, '\010');
              text->txChar(text, ' ');
              text->txChar(text, '\010');
              count += 1;
              buf--;
          }
          count += 1;
          continue;
      }

      text->txChar(text, ch);
      
      if (ch == '\r')
          text->txChar(text, '\n');
          
      */   

      if (ch == '\r' || ch == '\n')
          break;

      *(buf++) = ch;
  }
  *buf = 0;

  return (origBuf);
}

Here is some test code that fails with the existing library, and executes correctly when the echo code is commented out.

#include "simpletools.h"
#include "serial.h"
#include "fdserial.h"

serial *msgOut;
serial *msgIn;

char s[10];

int val;

int c;

void sendVals();

int main()
{
  msgIn = serial_open(3, 4, 0, 9600);
  pause(100);
  cog_run(sendVals, 256);
  while(1)
  {
    //val = readDec(msgIn);
    dscan(msgIn, "%d", &val);
    print("val = %d\r", val);
  }
}

void sendVals()
{
  msgOut = serial_open(4, 3, 0, 9600);
  int t = CNT;
  int dt = CLKFREQ/10;
  int n = 0;
  while(1)
  {
    waitcnt(t += dt);
    writeDec(msgOut, n);
    writeChar(msgOut, '\r');
    n++;
    //writeChar(msgOut, '\n');
    //writeChar(msgOut, ' ');
  }
}      

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant