use of DoubleSerial

Hi,

during machine setup i want to do some manual control (for example x/y/z moves to find workpiece).
is there a possibility to use bluetooth input while serial input is connected to Repetier Host on computer ?
so repetier host is communicating, i think that´s the problem for me.
is there a possibility to switch over from serial  to bluetooth (serial1)  by a command and back again by another command?

thanks for any thoughts

RAyWB


Comments

  • You can configure to have both, but only one is allowed to be actively talking. If both talk the host gets content mixed and only throws communication errors. However it is ok to have both to listen.
  • ok, so what i want to do is use repetier host for sending gcode file and do some manual moves to set for example x/y/z by g92 before by another arduino via bluetooth only after receiving a "wait".
    seems to work so far when i use ascii protocol for both.(i still use firmware 92.9).
    when using repetier protocol for repetier host and sending ascii via bluetooth i get checksum error message.
    think that´s solved in actual firmware so i´ll switch over soon

  • With your wait trick it will work most of the time. Especially if one (bluetooth) does not use line numbers. With line numbers you get a conflict for sure.
  • is there a possibility to get line numbers from two senders in a row? at the moment i send without  line numbers and
    sometimes i get " resend" with a line number... it´s getting better when i switch the checking for extruder/bed temperatur
    off in repetier host.
    do you know a way to manage this? maybe i can check for others than the "wait" also.
    As i sometimes loose some bits on communication I´ll try to check for "OK" also. is there a "Dummy proof" way to catch all
    communication errors?


  • The problem with wait is that it does not say when host will send it's M105.

    You can not use line numbers from both as host has his internal counter and does not see if someone else changes data.

    But why do you need 2 programs connected to control printer? You could do this with the repetier-server if you use the api to send commands. Then the server takes care about line numbering for connection from host and your software.
  • edited June 2016
    the "need" for a second sender comes from a idea during using UI-Buttons to move X/Y/Z during searching
    workpiece coordinates for milling.
    from principal it´s ok to have buttons on the machine to move toolhead and do some other settings.
    but after milling some parts there are a lot of shavings around , so you have to clean the buttons etc.
    anyway you can spend a lot of money for good buttons or membrane switches which are not affected by
    that shavings.
    having Computer close to the machine resulted in a damaged  Laptop keyboard (by aluminum shavings)
    so for me there is a need to act .
    i have to keep computer away from machine for more than 3 meters(that´s the distance most of shavings reach)
    and that´s the problem when adjusting workpiece offset

    the idea goes to use low cost touch-display(which is easy to clean) instead of the switches.
    i use a 12€ 3.95inch Display on a Uno clone with HC05 Bluetooth Sender , so monetary effort is <25 € for that

    i can send any command with that, make any number of buttons on several pages

    for example:

    image

    image

    another possibility to avoid the communication problems would be to use that touch"terminal"  as I2C slave .
    so i can add a switch/case in UI and act commands in UI ...
    I´m also thinking about that so it´s not a must to have it wireless I just need a cleanable terminal.

    hope it helps you to understand my intension
  • Ok, I see what you want. One solution might be having a own input buffer for second connector. Now both parse into same buffer in gcode.cpp whcih is the source of your problem. Having a duplicate of the serial parsing with own buffer would solve the problems.If you do without checksum/line number it could be as simple as read during a event until \n and execute the gcode.
  • ok, if i´ll do it as a read during a event i have to initialize the serial connection on it´s own, that would make sense.
    something like
    in config.h:
    # define Terminal  Serial2
    # define TerminalBaud  38400

    in hal.cpp

    add to hwsetup()

    Terminal.begin(TerminalBaud);


    and for example read the terminal until\n during uidisplay slow action 
    and execute via GCode::executeFString

    think that´s the easiest to solve.will try that first
  • I was more thinking abount the event system so you have the code in a separate file and can update, but yes that is what I meant.
  • edited June 2016
    there is just one problem i stick with :

    i use this code:

    while (BT.available()&!stringComplete)
        {
        char inChar = (char)BT.read();
        inputString += inChar;
        if (inChar == '\n') {
        stringComplete = true;
        }
      }
      if (stringComplete)
    {
        GCode::executeFString(inputString);
        inputString = "";
        stringComplete = false;
      }

    #endif

    but   GCode::executeFString(inputString)   gives error message:

    no matching function for call to 'GCode::executeFString(String&)'

    can you please point me a way?
     

  • think problem is that string is is not in progmem so i have to decide what way to go...
    using fix commands and call them by number via switch/case in ui or a duplicate of parse commands as you wrote before

  • It is easy. You need GCode instance and parse the sting. Then send parsed gcode to execution function just like executeFString does (in fact you can copy that and use it just without progmem and ram instead).
  • edited June 2016
    seems not so easy for me.

    added following code:(whats a copy of executeFString)

    void GCode::executeString(String Kommando)
    {
        char buf[80];
        uint8_t buflen;
        char c;
        GCode code;
        do
        {
            // Wait for a free place in command buffer
            // Scan next command from string
            uint8_t comment = 0;
            buflen = 0;
            do
            {
                c = Kommando.charAt(buflen);
               
                 if(c == 0 || c == '\n') break;
             
                if(c == ';') comment = 1;
                if(comment) continue;
                buf[buflen++] = c;
            }
            while(buflen < 79);
            if(buflen == 0)   // empty line ignore
                continue;
            buf[buflen] = 0;
            // Send command into command buffer
            if(code.parseAscii((char *)buf,false));// && (code.params & 518))   // Success
            {
    #ifdef DEBUG_PRINT
                debugWaitLoop = 7;
    #endif

                Commands::executeGCode(&code);
                Printer::defaultLoopActions();
            }
        }
        while(c);
    }

    and even if i use it like for example GCode::executeString("G1 X100\n")   it most of the time fills up command buffer completely and also blocks executing commands from repetier host.
    can you please tell me where the trap is?


  • i use that function in ui.cpp  slow action

    #if(FEATURE_BTCONTROLLER== true)


     while(BT.available())
        {
        // get the new byte:
        char inChar =(char)BT.read(); //(char)BT.read();
        inputString += inChar;
        //BT.println(inputString); //for debug
        if (inChar=='\n')
        {fertig=true;
        break;
        }
        }
    #endif
     
        if(fertig)
         {
         BT.println(inputString); // for debug only to show string arrives correct, what it does
         GCode::executeString(inputString);
         // GCode::executeFString("M117 inputString");
         BT.println("x\n"+inputString+" 2"); // for debug only
         inputString="";
         fertig=false;
         BT.println(inputString); // for debug only
         BT.println("OK"); // for debug only
        
         }

    if i send M117 inputString and use the GCode::executeString  from above post green lines are not executed,seems it points to nirwana...
    when use the GCode::executeFstring("M117 inputString") green lines are executed.
    Both functions show "inputString" on display
  • If it is a single command per call you can simplify it neglecting your copy errors for multiple commands (don't use buflen as index to Kommando)

    void GCode::executeString(char* buf)
    {
        GCode code;
         // Send command into command buffer
          if(code.parseAscii((char *)buf,false));// && (code.params & 518))   // Success
            {
    #ifdef DEBUG_PRINT
                debugWaitLoop = 7;
    #endif

                Commands::executeGCode(&code);
                Printer::defaultLoopActions();
        }
    }

    Of course buf must be 0 terminated. Don't use string class for text, that only adds conversions etc.

  • edited June 2016
    you wrote : Of course buf must be 0 terminated

    do you mean the \n at end
    or
    replacing \n by \0(what i actually did)?

    what´s the difference?

    anyway ,it works fine now :-) thanks a lot!!


    maybe you should think about implementing that function  , that would enable
    some possibilities for users to work with variables in UI.

    but if you find the time, can you please explain why
    "(don't use buflen as index to Kommando)"


  • No, you should replace \n with 0 byte value as string termination. That is how C terminates all strings. All char *x = "jjhg"; strings are terminated by 0 byte value so everyone knows where it ends. The \n should not be part when send to parseAscii.
  • OK, thank you!

    as it seems seems i got some lousy bluetooth modules loosig data...(i use baudrate 38400)  i tested the stuff with
    direct connection via Serial1 up to 115200 baud and everything works well with no errors.

    As i also have some multi-line commands I switched over to a modified copy of GCode::readFromSerial now for my
    "terminal" what enables me to get acknowledge and request a resend also.




  • Can you please tell me if there is a command (G or Mcode) to get machine position in mm?


  • M114
    return position including G92 offset I think.
  • OK,thanks and yes it´s including offsets.

Sign In or Register to comment.