Shop OBEX P1 Docs P2 Docs Learn Events
Activity Board <-> DNA-RTC board comms — Parallax Forums

Activity Board <-> DNA-RTC board comms

I am having a heck of a time trying to set up a C program to get an Activity Board to talk to a DNA-RTC , two conversation. I have the small programs which I have been messing around with, but I cannot get them to cooperate like I want. Basically, I am not getting the expected string on the Activity Board side. Not sure what is going on here, it should be a very straight forward exercise. Anybody see how I can get this thing to work correctly?

Thanks

Ray

Activity Board
/*
  rb5x_ab_test.c

*/
#include "simpletools.h"
#include "simpletext.h"
#include "fdserial.h"

serial *dna;

int main()
{
  // Add startup code here.
/*                  Rx Tx      BAUD  */
dna = fdserial_open(1, 0, 0, 115200);  // Connected to DNA-RTC board.

char inBuff[40];
char inDna[40];

 
  while(1)
  {
    // Add main loop code here.
    print("> ");   // Test on terminal window
    getStr(inBuff,10);
    if(!strcmp(inBuff,"hour"))
    {
      writeStr(dna,"Time");
      //pause(200);
      readStr(dna,inDna,10);
      //pause(150);
      print("%s",inDna);
    }
    else
    {
      print("Invalid Command\n");
    }           
  }  
}

DNA-RTC board
/*
  rb5x_test.c

*/
#include "simpletools.h"
#include "simpletext.h"
#include "fdserial.h"

serial *ab;

int main()
{
  // Add startup code here.
  ab = fdserial_open(4, 5, 0, 115200);  // Connected to Activity board
  
  //char inBuff[40];
  int inInt;
 
  while(1)
  {
    // Add main loop code here.
    readStr(ab,inBuff,40);
    if(!strcmp(inBuff,"Time"))
    {
      writeStr(ab,"Got it!\n");
    }
    //print("%s\n",inBuff);  // Test to see if comm is there.
    //writeStr(ab,"A\n");
    //pause(1000);      
  }  
}

Comments

  • Giving the programs another try this morning, nothing has changed, does not work as expected.

    The way it is supposed to work, type in 'hour' on the Activity Board side, and the DNA-RTC is supposed to send "Got it!". All that I am getting is, a blank line as the response, on the AB side. Both programs compile, so whatever the problem is, it is very subtle, or I am just not seeing a glaring mistake.

    Just to pick the program apart a bit, on the AB side, 'inDna' is supposed to have the string from the DNA-RTC side, now I cannot even figure out how to see what that value does contain. I tried printf(), with no success. I have verified that there is communication between the two boards, by having the DNA-RTC board send a char and the AB capturing and displaying it on the terminal window.

    What I am trying to do is setup the DNA-RTC board to run a clock program, and then have the AB get the datetime values when needed. I had a larger program that I was running that did just that, but I noticed that I was not getting anything from the DNA-RTC board clock program, just zero values, so basically this is a debug session. Still scratching my head as to what the next should be.

    Ray
  • The documentation doesn't say what happens if the stream ends prior to `max` characters being read in from `readStr()`. Do you know what makes readStr() stop waiting for new characters and write to the buffer? I can think of three end scenarios:

    1) fd_serial's buffer is empty (this would make it a non-blocking call, which would cause your program to fail in the way that it is failing)
    2) Some delimeter (like a newline) is reached. Since that delimeter can't be changed via a parameter to the function, one would have to assume it is a newline. Since your program doesn't send a newline, the failure you're experiencing would also be expected in this scenario.
    3) It waits for `max` chars to be sent. Since your program isn't sending 40 characters, I would once again expect to see the same failure you're experiencing.

    Soooo.... good luck :) It could be any one of the three. You'll have to dig through the source code to figure out what makes readStr() stop reading, or wait for someone else to respond.
  • Oh, and if you want to be REALLY nice, you'll submit a pull request to the Simple Libraries GitHub project when you're done with updated documentation for the readStr() function :)
  • As far as I can tell, readStr requires a CR to detect the string termination and you don't send it with writeStr(dna,"Time"), try with writeStr(dna,"Time\r");, also looks like readStr echoes back the received characters, so you may need to skip your command when receiving the response.

    In these cases, it would be good to test the individual programs with something known to work, for example, connect one board to the PC with a USB-Serial plug and test the interaction with a terminal program, once that works, connect to the other board and do the same. Now connecting the two boards toghether should work.

    Hope this helps.
  • I have tried a couple of different ways, I made the assumption that readStr() needed something like '\n', but that does not make a difference. In fact sometimes when I run the program, it seems to freeze up, meaning the readStr() is waiting for a delimiter. But most of the time it just continues, and shows a blank line. I have tried the qualify each board approach, but when I put them together, it does not work as expected. I also tried it with a QuickStart board, in the mix, that has the same problem.

    I am now considering a bunch of steps backward, work in project manager part of SimpleIDE, and develop my own libraries as needed. But, when I started to do a lookup of where everything is at, source wise, not even sure where the official PropGCC source code is to be found. I make a point on OFFICIAL source code. Probably the very important library, to look at, would be propeller.h.

    I have basically, I will call it wasted, a couple of days making some assumptions about the simpletools library, and finding out that it does not necessarily work the way you would think. Granted most of the simple functions work as assumed, but I am running into problems with other functions, very subtle problems. I fully realize that Parallax developed this for their Educational program, so I am not going negative on Parallax, just describing some problems that I am running into.

    Anybody have any suggestions as to a good way to proceed with this?

    Ray
  • The official repository for the Simple libraries is in my second post, and here's the official PropGCC repo. The hard part, of course, is going to be figuring out which commit was used for the version of PropGCC and Simple that are bundled with your installation of SimpleIDE... and that I can't help you with. I already checked the Simple Libraries repo, and there are no tags to help you figure it out.

    I am genuinely curious if you would run into the same (or none, or just different) problems with PropWare. PropWare's Printer and Scanner interfaces are pretty simple and I hope they work quite intuitively (they're certainly intuitive for me :P ). You can even continue using FdSerial as your driver as shown in the example below. The example wraps FdSerial with PropWare's own interfaces, which I think (I really hope) don't cause you quite such a headache. (full source with comments)
    #include <PropWare/hmi/output/printer.h>
    #include <PropWare/hmi/input/scanner.h>
    #include <PropWare/serial/uart/fullduplexserial.h>
    
    static void runScannerDemo (PropWare::Printer &queuePrinter, PropWare::Scanner &queueScanner);
    static bool isAnswerNo (char const userInput[]);
    
    int main () {
        PropWare::FullDuplexSerial serial;
        serial.start();
    
        PropWare::Printer printer(serial);
        PropWare::Scanner scanner(serial, &printer);
    
        runScannerDemo(printer, scanner);
        
        while (1);
    }
    
    void runScannerDemo (PropWare::Printer &queuePrinter, PropWare::Scanner &queueScanner) {
        char         userInput[64];
        char         name[64];
        unsigned int age;
    
        queuePrinter << "Hello! I'd like to teach you how to use PropWare to read from the terminal!\n";
    
        do {
            queuePrinter << "First, what's your name?\n>>> ";
            queueScanner >> name;
    
            queuePrinter << "And how old are you?\n>>> ";
            queueScanner >> age;
    
            queuePrinter << "Is your name " << name << " and are you " << age << " years old?\n>>> ";
            queueScanner.input_prompt("", "Please enter either 'yes' or 'no' (y/n)\n>>> ", userInput, sizeof(userInput),
                                      YES_NO_COMP);
        } while (isAnswerNo(userInput));
    
        queuePrinter << "Hello, " << name << "!\n";
    }
    bool isAnswerNo (char const userInput[]) {
        return 0 == strcmp("n", userInput) || 0 == strcmp("no", userInput);
    }
    

    (There's a problem with Doxygen at the moment that is making Printer's documentation fail to render. Reference the source directly for Printer docs in the meantime.
  • Thanks David for the official link to PropGCC repo, I know you have done this before, but I will keep bringing up, listing the link for me, over and over.

    So, I guess I can say that, for whoever is still using SimpleIDE, in Help, the PropGCC reference(online), is no longer valid, or is it? And David brings up an excellent point about what version of PropGCC is bundled with your version of SimpleIDE. This is maddening enough to just switch over to command prompt PropGCC usage, but I do not think that I am there, just yet.

    I will now investigate the PropGCC repo and see what is there, and maybe will have to bookmark it.

    I still like the general simplicity of SimpleIDE, but it did find it somewhat cumbersome when you are trying to work with two Propeller boards. Opening and closing the projects is getting to be very annoying, let alone making the mistake of not pulling the cord on one board and overwriting the original program with another program, things get a little bit messy. If you have two cords, then you have to think about which COM port, was it COM3 or is it COM11. I am sure glad I do not do this for a living, I probably would have starved a long time ago. Saved by retirement, so basically I am not starving, just wasting a lot of time.

    Ray
  • A small problem, for me anyway, while I was trying to find the source for readStr(), which I could not find, I came across code for getStr(). Now it looks like spin2cpp was maybe used to translate a Spin method. This really complicates trying to figure out where a, possibly, a subtle bug is causing some difficulty. Talk about a debugging nightmare.

    I have noticed that there are a lot of functions that were developed using spin2cpp, I like spin2cpp, but I am not sure if I like this added layer of complexity to trying to figure out why a function is not working the way it is supposed too. And if you notice, in the code below, there is use of readStr(), so what does that function tell you, or for that matter, what is it doing?

    The worms are starting to multiply.

    Ray
    /*
     * Super-simple text I/O for PropGCC, stripped of all stdio overhead.
     * Copyright (c) 2012, Ted Stefanik. Concept inspired by:
     *
     *     very simple printf, adapted from one written by me [Eric Smith]
     *     for the MiNT OS long ago
     *     placed in the public domain
     *       - Eric Smith
     *     Propeller specific adaptations
     *     Copyright (c) 2011 Parallax, Inc.
     *     Written by Eric R. Smith, Total Spectrum Software Inc.
     *
     * MIT licensed (see terms at end of file)
     */
    
    #include <limits.h>
    #include "simpletext.h"
    
    char* getStr(char* buf, int max)
    {
      extern text_t *dport_ptr;
      return (_safe_gets(dport_ptr, buf, max));
    }
    
    char* readStr(text_t *text, char* buf, int max)
    {
      return (_safe_gets(text, buf, max));
    }
    
    
    /* +--------------------------------------------------------------------
     * |  TERMS OF USE: MIT License
     * +--------------------------------------------------------------------
     * Permission is hereby granted, free of charge, to any person obtaining
     * a copy of this software and associated documentation files
     * (the "Software"), to deal in the Software without restriction,
     * including without limitation the rights to use, copy, modify, merge,
     * publish, distribute, sublicense, and/or sell copies of the Software,
     * and to permit persons to whom the Software is furnished to do so,
     * subject to the following conditions:
     *
     * The above copyright notice and this permission notice shall be
     * included in all copies or substantial portions of the Software.
     *
     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
     * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
     * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
     * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
     * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
     * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     * +--------------------------------------------------------------------
     */
    
  • Rsadeika wrote: »
    And if you notice, in the code below, there is use of readStr(), so what does that function tell you, or for that matter, what is it doing?

    getStr uses the global variable dport_ptr to read the characters from, while readStr uses the port you specify with the text argument. It is the same difference between gets and fgets where gets uses the standard input and fgets a file descriptor passed as argument. I guess the global variable is used to communicate with the standard serial pins 31 and 30.

  • I decided that I am done wasting time on this. Everywhere I look, it is not getting me any closer to a workable solution.

    On too plan B, I will be implementing a softRTC program on the AB, and then see how far I get before I run out of memory on the AB. At least this way I can feel like I am accomplishing something useful. Maybe at some point I will have to add my Raspberry Pi 3, at least I can get the AB to talk to that device. If that works out then I can remove the softRTC code and get the datetime from the RPi. We shall see what happens.

    Ray
  • I looked at the code used by readStr which is in the file safe_gets.c and it certainly requires either a \r or a \n to terminate input and it doesn't store that character in the buffer.
Sign In or Register to comment.