Shop OBEX P1 Docs P2 Docs Learn Events
Comm between two prop boards — Parallax Forums

Comm between two prop boards

RsadeikaRsadeika Posts: 3,837
edited 2014-03-29 12:27 in Propeller 1
I am running into some problems with comms between two prop boards and displaying too a terminal via XBee. Basically I have two boards connected with a common ground wire, using P14 and P15 on the GG board, P0 and P1 on the Activity board. The Activity board is accessed via an XBee connection(P11,P10), the problem is with having strings displayed to the xbee terminal screen. Sometimes I get parts of a string, and other times I get a partial string when I try to access the GG board . I have tried using fflush(xbee) with no success, it seems that in this configuration, the XBee is not behaving as expected.

I remember at one time I had a spin program that was acting in similar way, but a specific XBee command too flush the buffers seemed to work. In this case it seems like the C fflush is not doing the job or I am not using it correctly. Anybody see what the problem might be?

Thanks

Ray
/*
  testAB.c

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

serial *cGG;
serial *xbee;

int main()
{
  // Add startup code here.
/*                    Rx Tx  Mode  Baud*/
  cGG = fdserial_open(0,  1,   0, 9600);  // Connection to GG board
  xbee = fdserial_open(11,10,0,9600);

  char inBuff[40];
  char inSpec[40]; 
  while(1)
  {
    // Add main loop code here.
    writeStr(xbee,">");
    readStr(xbee,inBuff,40);
    if(!strcmp(inBuff,"test1"))
    {
      writeStr(cGG,"test1\n");
      //pause(50);      
      readStr(cGG,inSpec,40);
      pause(50);
      fprintf(xbee,"%s",inSpec);
      //fflush(xbee);
    }
    else
    {
      writeLine(xbee,"?cAB?");
    } 
    
  }  
}
/*
  testGG.c

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

serial *cAB;

int main()
{
  // Add startup code here.
/*                    Rx TX Mode Baud */
  cAB = fdserial_open(15,14, 0, 9600);  // Connect to AB 

  char inBuff[40]; 
  while(1)
  {
    // Add main loop code here.
    writeStr(cAB,">>\n");
    readStr(cAB,inBuff,40);
    if(!strcmp(inBuff,"test1"))
    {
      writeStr(cAB,"GG, sent it.\n");
    }
    else
    {
      writeStr(cAB,"?testGG?\n");
    }    
  }  
}

Comments

  • RsadeikaRsadeika Posts: 3,837
    edited 2014-03-28 07:21
    After doing some more testing I think I found the problem, but the problem is a can of worms. It seems that SimpleIDE is no longer simple to use, unless you stick to just using simpletools lib and whatever that entails.

    My specific headache is the serial stuff, simpleterm_open(xxx), serial_open(x,x,x,x), and fdserial_open(x,x,x,x). These have library specific commands which cannot be used interchangeably.
    simpleterm_open - here you can use commands like writeStr(xx,xx), readStr(xx,xx), ..., etc. This only works with the SimpleIDE terminal window. If you try to use it with a different assigned port, you get some very mixed results, some commands seem to work while others do not, but you get no warnings as to what is occuring.
    serial_open - here you only get to use only four commands, which makes this almost useless.
    fdserial_open - same thing here, you only get four commands, so why the duplication?

    And the biggest concern, in the example program below, the program does work as expected, yet you get no warnings about what is not occurring. The problem, the testGG.c program sends fdserial_txChar(xx,xx) byte value which the testAB.c program using serial_rxChar(xx) to read that byte value, is not responding. When I change the code in testAB.c too use fdserial_rxChar(xx) then everything works as expected. So, is serial_rxChar(xx) corrupted or is something else going on?

    It would really be nice if simpletools could use the attributes of serial_open, fdserial_open, or both. Short of that maybe we need a PropellerIDE C/C++ program.

    Ray


    /*
      testAB.c
    
    */
    #include "simpletools.h"
    #include "simpletext.h"
    #include "fdserial.h"
    
    serial *cGG;
    //serial *xbee;
    
    int main()
    {
      // Add startup code here.
    /*                    Rx Tx  Mode  Baud*/
    //  cGG = fdserial_open(0,  1,   0, 9600);  // Connection to GG board
      cGG = serial_open(0, 1, 0, 9600);
      //xbee = fdserial_open(11,10,0,9600);
    
      //char inBuff[40];
      //char inSpec[40];
      int inByte; 
      while(1)
      {
        // Add main loop code here.
        //writeStr(xbee,">");
        //readStr(xbee,inBuff,40);
       /* if(!strcmp(inBuff,"test1"))
        {
          writeStr(cGG,"test1\n");
          //pause(50);      
          readStr(cGG,inSpec,40);
          pause(50);
          fprintf(xbee,"%s",inSpec);
          //fflush(xbee);
        }
        else if(!strcmp(inBuff,"test2"))
        {
          writeStr(cGG,"test2\n");
          readStr(cGG,inSpec,40);
          if(!strcmp(inSpec,"ledon")) high(26);
        }
        else if(!strcmp(inBuff,"test3"))
        {
          writeStr(cGG,"test3\n");
          readStr(cGG,inSpec,40);
          if(!strcmp(inSpec,"ledoff")) low(26);
        } */
        //if(!strcmp(inBuff, "ledon")) high(26);
        //else if(!strcmp(inBuff,"ledoff")) low(26);
        //else
        //{
          //writeLine(xbee,"?cAB?");
        //} 
        inByte = serial_rxChar(cGG);
        //inByte = readChar(cGG);
        if(inByte == 100) high(26);
        if(inByte == 200) low(26);
      }  
    }
    
    /*
      testGG.c
    
    */
    #include "simpletools.h"
    #include "simpletext.h"
    #include "fdserial.h"
    
    serial *cAB;
    
    int main()
    {
      // Add startup code here.
    /*                    Rx TX Mode Baud */
      cAB = fdserial_open(15,14, 0, 9600);  // Connect to AB 
    
      //char inBuff[40]; 
      while(1)
      {
        // Add main loop code here.
      /*  writeStr(cAB,">>\n");
        readStr(cAB,inBuff,40);
        if(!strcmp(inBuff,"test1"))
        {
          writeStr(cAB,"GG, sent it.\n");
        }
        if(!strcmp(inBuff,"test2"))
        {
          writeStr(cAB,"ledon\n");
        }
        if(!strcmp(inBuff,"test3"))
        {
          writeStr(cAB,"ledoff\n");
        }
        else
        {
          writeStr(cAB,"?testGG?\n");
        }  */
        //writeStr(cAB,"ledon\n");
        fdserial_txChar(cAB,100);
        pause(2000);
        //writeStr(cAB,"ledoff\n");
        fdserial_txChar(cAB,200);
        pause(2000);  
      }  
    }
    
  • pmrobertpmrobert Posts: 675
    edited 2014-03-28 11:18
    Perhaps you are seeing a situation like I experienced - the silent conflict situation. See http://forums.parallax.com/showthread.php/154958-Invalid-variable-name-list-or for details. I did send a message to the forum admin re this as Dave Hein suggested.
  • jazzedjazzed Posts: 11,803
    edited 2014-03-28 11:31
    Rsadeika wrote: »
    serial_open - here you only get to use only four commands, which makes this almost useless.
    fdserial_open - same thing here, you only get four commands, so why the duplication?

    Do you know where to find any of the documentation on serial or fdserial?
  • RsadeikaRsadeika Posts: 3,837
    edited 2014-03-28 11:39
    Do you know where to find any of the documentation on serial or fdserial?
    Documentation serial Library
    Documentation simpletext Library
    Documentation fdserial Library
    This is what I have to go by in the Documents library folder that appears with the last SimpleIDE install.

    Ray
  • pmrobertpmrobert Posts: 675
    edited 2014-03-28 11:56
    I'm seeing this in my recent install at location file:///C:/Users/pmrobert/Documents/SimpleIDE/Learn/Simple%20Libraries/Text%20Devices/libfdserial/Documentation%20fdserial%20Library.html

    Function List:

    Functions
    fdserial * fdserial_open (int rxpin, int txpin, int mode, int baudrate)
    Initializes and starts native assembly driver in a cog. More...

    void fdserial_close (fdserial *term)
    Stop stops the cog running the native assembly driver.

    int fdserial_rxCheck (fdserial *term)
    Gets a byte from the receive queue if available function does not block. More...

    void fdserial_rxFlush (fdserial *term)
    Empties the receive queue.

    int fdserial_rxReady (fdserial *term)
    Find out if a byte is ready in the receive buffer. The function does not block. More...

    int fdserial_rxTime (fdserial *term, int ms)
    Gets a byte from the receive queue if available by timeout function blocks if no recieve for ms timeout. More...

    int fdserial_rxChar (fdserial *term)
    Waits for a byte from the receive queue. blocks until somehting is ready. More...

    int fdserial_txChar (fdserial *term, int txbyte)
    Sends a byte on the transmit queue. More...

    int fdserial_txEmpty (fdserial *term)
    Find out if the tx queue is empty. More...

    void fdserial_txFlush (fdserial *term)
    Flush the transmit queue.
  • jazzedjazzed Posts: 11,803
    edited 2014-03-28 15:29
    What about simpletext ?

    All of these functions are also available for fdserial, serial, and vgatext. These devices are all of type text_t. Andy chose to hide this fact to make it more "simple." There are certainly more than 4 functions available per device.
    int      readBin (text_t *device);
    int      readChar (text_t *device);
    int      readDec (text_t *device);
    float    readFloat (text_t *device);
    int      readHex (text_t *device);
    char    *readStr (text_t *device, char *buffer, int max);
    void     writeBin (text_t *device, int value);
    void     writeBinDigits (text_t *device, int value, int digits);
    void     writeChar (text_t *device, char c);
    void     writeDec (text_t *device, int value);
    void     writeDecDigits (text_t *device, int value, int width);
    void     writeFloat (text_t *device, float value);
    void     writeHex (text_t *device, int value);
    void     writeHexDigits (text_t *device, int value, int digits);
    void     writeFloatPrecision (text_t *device, float value, int width, int precision);
    int      writeLine (text_t *device, char *str);
    int      writeStr (text_t *device, char *str);
    int      writeStrDigits (text_t *device, char *str, int width);
    int      dprint (text_t *device, const char *format,...);
    int      dscan (text_t *device, const char *fmt,...);
    int      printNumber (text_t *p, unsigned long u, int base, int width, int fill_char);
    
    As for code with problems in it, I can't look at any of it until sundown because of a big project I'm doing for my wife.
  • jazzedjazzed Posts: 11,803
    edited 2014-03-28 20:24
    Ray,

    Either use all Simple Library functions or use stdio.h functions. Do not mix them.

    Functions fprintf and fflush are designed to work with stdio.h devices, not simpletext devices.

    Is there a code example somewhere that mixes fprintf and a simpletext.h device?
  • RsadeikaRsadeika Posts: 3,837
    edited 2014-03-29 06:33
    For clarification, what is the difference between fdserial_txChar(xx,xx) and serial_txChar(xx,xx)? These two are to be used with Simple tools Library, correct? I would ask the same question about fdserial_rxChar() and serial_rxChar() and others, just trying to figure out if there are some really subtle differences that I am not picking up. And of course I could also throw in writeChar() into the mix.

    Ray
  • jazzedjazzed Posts: 11,803
    edited 2014-03-29 07:49
    Rsadeika wrote: »
    For clarification, what is the difference between fdserial_txChar(xx,xx) and serial_txChar(xx,xx)?
    The difference is that fdserial uses a COG while serial does not. It means that fdserial can be used to capture input while other functions are running in the main COG.

    Rsadeika wrote: »
    These two are to be used with Simple tools Library, correct?
    Well, not really. They are designed to be used by simpletext.h functions. You can add any IO device that can be used by writeChar (or even putChar). For example, vgatext has been added to the libraries recently.

    Rsadeika wrote: »
    I would ask the same question about fdserial_rxChar() and serial_rxChar() and others, just trying to figure out if there are some really subtle differences that I am not picking up. And of course I could also throw in writeChar() into the mix.
    Functions *_txChar() and *_rxChar() are low level drivers called by the simpletext functions. The only reason to use them over putChar/getChar or writeChar/readChar is to save a few bytes of code space.

    The reason to use writeChar/readChar is to have more maintainable code without resorting to using the huge stdio.h methods.

    The device used with all writeChar or other simpletext.h functions in a single program can be changed just by changing the device open method and variable assignment. The same can be done with putChar and friends with just a few more lines of code.

    If you decide to use vgatext instead of fdserial for output, that's relatively painless if you use putChar/writeChar. If you have multiple files with fdserial_txChar() in them, you would have to change every file to use another device.
  • RsadeikaRsadeika Posts: 3,837
    edited 2014-03-29 08:58
    Thanks jazzed. For further clarification, we have fdserial_open(),simpleterm_open(),and serial_open(), so fdserial_open() uses a cog, simpleterm_open(),and
    serial_open() do not use a COG. The functions that you would use with fdserial_open() would generally be the fdserial*() functions, and with serial_open() you would use the functions like putChar(), writeChar(), ..., etc. So, what is the intended use for simpleterm_open() and what are the functions? And you also mentioned that you cannot mix the different functions with a specific *_open(). Also, can fdserial_open() be used with XMMC mode, or will there be some serious problems? Since it has been a long time ago that I had used fdserial with stdio.h, what is the proper way of opening up a port with that? I am very sure that I have not seen that in the Learn site.

    One problem that I was seeing is when I tried to use fdserial_txChar() or writeDec() or serial_txChar() when I had used fdserial_open(), I was getting different results with each function. I guess now I have been warned, and mix and match at your own risk.

    I noticed on the Learn site, there is no detailed explanation for how to use serial in the correct manner, hopefully Andy will accidentally browse here and maybe consider adding a chapter as to how to use serial, and all of the variations, in a correct and beneficial manner.

    Ray
  • jazzedjazzed Posts: 11,803
    edited 2014-03-29 12:27
    Rsadeika wrote: »
    The functions that you would use with fdserial_open() would generally be the fdserial*() functions
    Or any simpletext.h function like writeChar/readChar (or even put/get functions for the terminal if you really need it).
    Rsadeika wrote: »
    , and with serial_open() you would use the functions like putChar(), writeChar(), ..., etc. So, what is the intended use for simpleterm_open() and what are the functions?
    The simpleterm_open() function is just another name for serial_open(31,30,0,115200) and is the default serial port for the simpletext.h put/get functions.
    Rsadeika wrote: »
    And you also mentioned that you cannot mix the different functions with a specific *_open().
    I said don't mix stdio.h functions and simpletext.h functions. That is don't use fprintf/fflush with simpletext.h functions such as writeChar. The files stdin, stdout, stderr are the only files you can use with fprintf and fflush ... for console IO. FILE * pointers can be used with fprintf, but not simpletext devices. You can still use SDCard files with functions like fread and fwrite. The functions printf and scanf are also part of stdio.h.
    Rsadeika wrote: »
    Also, can fdserial_open() be used with XMMC mode, or will there be some serious problems?
    There should be no problem.
    Rsadeika wrote: »
    Since it has been a long time ago that I had used fdserial with stdio.h, what is the proper way of opening up a port with that? I am very sure that I have not seen that in the Learn site.
    Functions sprint and sscan can be used to format text passed to and from fwrite and fread.
    Rsadeika wrote: »
    I noticed on the Learn site, there is no detailed explanation for how to use serial in the correct manner, hopefully Andy will accidentally browse here and maybe consider adding a chapter as to how to use serial, and all of the variations, in a correct and beneficial manner.
    I think that the intent of the Learn curriculum is mainly that you will use what he teaches. However, there should be some explanation about what the limits are with respect to the stdio.h formatted input/output.
Sign In or Register to comment.