Mysterious Serial communication in custom software

Home Forums TinyG TinyG Support Mysterious Serial communication in custom software

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #4566
    psyko
    Member

    Hello,

    I’m working on my own software to send GCode files to TinyG.
    I have the serial In/Out running, but I have some weirds issues.
    First of all :
    TinyG Firmware version : 0.95
    TinyG Firmware build : 380.02
    Software developped in Java.

    I made a test protocol.
    I watch both what my application sends and what TinyG boards sends in 2 separates Arduino Serial monitor. (This helps making sure what’s sent is what I’m expecting). I’m using Virtual Serial Port Emulator to split the COM ports, and send them on 2 separate devices.

    When sending a file, here is what my application sends (copied from the outgoing Arduino monitor) :

    {"gc":"n1g17"}
    {"gc":"n2m3s1000"}
    {"gc":"n3g0x-84.0y19.0"}
    {"gc":"n4g1f300.0z-0.5"}
    {"gc":"n5g1f800.0x-38.0"}
    {"gc":"n6g1y53.0"}
    {"gc":"n7g1x-84.0"}
    {"gc":"n8g1y19.0"}
    {"gc":"n9g0z3.0"}
    {"gc":"n10g0y0.0"}
    {"gc":"n11g1f300.0z-0.5"}
    {"gc":"n12g1f800.0x0.0"}
    {"gc":"n13g1y70.0"}
    {"gc":"n14g1x-106.0"}
    {"gc":"n15g1y0.0"}
    {"gc":"n16g1x-84.0"}
    {"gc":"n17g0z3.0"}
    {"gc":"n18g0y19.0"}
    ... (And more, not displayed)

    And below is what TinyG answers (also copied from the Arduino monitor plugged on the TinyG COM port):

    {"r":{"fb":380.02,"fv":0.950,"hv":7,"id":"9H3583-PXN","msg":"SYSTEM READY","f":[1,0,2,3394]}}
    {"r":{"gc":"N1G17","n":1,"f":[1,0,15,1162]}}
    {"r":{"gc":"N2M3S1000","n":2,"f":[1,0,19,5972]}}
    {"r":{"gc":"N3G0X-84.0Y19.0","n":3,"f":[1,0,25,3712]}}
    {"sr":{"line":3,"posx":-0.000,"posy":101.470,"vel":0.31,"momo":0,"stat":5}}
    {"sr":{"posx":-0.000,"posy":101.470,"vel":1.23}}
    {"r":{"gc":"N4G1F300.0Z-0.5","n":4,"f":[1,0,25,7547]}}
    {"sr":{"posx":-0.000,"posy":101.470,"vel":2.76}}
    {"r":{"gc":"N5G1F800.0X-38.0","n":5,"f":[1,0,26,4801]}}
    {"sr":{"posx":-0.001,"posy":101.470,"vel":4.91}}
    {"r":{"gc":"N6G1Y53.0","n":6,"f":[1,0,19,7909]}}
    {"sr":{"posx":-0.002,"posy":101.468,"vel":9.29}}
    {"r":{"gc":"N7G1X-84.0","n":7,"f":[1,0,20,4319]}}
    {"sr":{"posx":-0.004,"posy":101.467,"vel":12.97}}
    {"r":{"gc":"N8G1Y19.0","n":8,"f":[1,0,19,7522]}}
    {"sr":{"posx":-0.007,"posy":101.464,"vel":19.65}}
    {"r":{"gc":"N9G0Z3.0","n":9,"f":[1,0,18,5076]}}
    {"sr":{"posx":-0.011,"posy":101.460,"vel":27.72}}
    {"r":{"gc":"N10G0Y0.0","n":10,"f":[1,0,19,8305]}}
    {"sr":{"posx":-0.015,"posy":101.456,"vel":33.86}}
    {"r":{"gc":"N11G1F300.0Z-0.5","n":11,"f":[1,0,26,2080]}}
    {"sr":{"posx":-0.022,"posy":101.449,"vel":44.22}}
    {"r":{"gc":"N12G1F800.0X0.0","n":12,"f":[1,0,25,6781]}}
    {"sr":{"posx":-0.031,"posy":101.440,"vel":55.97}}
    {"r":{"gc":"N13G1Y70.0","n":13,"f":[1,0,20,8967]}}
    {"sr":{"posx":-0.039,"posy":101.433,"vel":64.57}}
    {"r":{"gc":"N14G1X-106.0","n":14,"f":[1,0,22,8984]}}
    {"sr":{"posx":-0.052,"posy":101.420,"vel":78.62}}
    {"sr":{"posx":-0.056,"posy":101.415,"vel":83.61}}
    {"r":{"gc":"N15G1Y0.0","n":15,"f":[1,0,19,410]}}   // <--- error starts here
    {"sr":{"posx":-0.073,"posy":101.399,"vel":99.50}}
    {"r":{"gc":"N17G0Z3.0","n":17,"f":[1,0,19,2954]}}
    {"sr":{"posx":-0.086,"posy":101.386,"vel":110.86}}
    {"r":{"f":[1,48,19,3280]}}
    {"sr":{"posx":-0.100,"posy":101.372,"vel":122.84}}
    {"r":{"gc":"NF800.0X0.0","f":[1,42,21,8955]}}
    {"sr":{"posx":-0.115,"posy":101.357,"vel":135.43}}
    {"sr":{"posx":-0.124,"posy":101.349,"vel":141.96}}
    {"r":{"gc":1,"f":[1,0,21,1154]}}

    As you can see, the line N16 is not acknowledged, although it was sent.
    Any idea why ?
    After that we can see that TinyG completely lost the track of sent GCode. The response enveloppe shows incoherent GCode.
    I can’t understand what the error {“r”:{“f”:[1,48,19,3280]}} is for. I know 49 means “Bad json format”, but I can’t see any wrong command.

    If it helps, my application is handling Xon/Xoff, but I’m pretty sure this is not the case, because until line N16, there is not much data.

    Can you pelase help me see through this ?

    Thanks

    #4567
    cmcgrath5035
    Moderator

    I can’t help directly, but you mention application handling XON/XOFF.
    User Makerboost made this comment relative to a post I had made
    Also, I understand that tgFX doesn’t use XON/XOFF like a normal terminal client, but controls TinyG differently. This has caused my TinyG’s $ex value to revert to 0 every time I start up tgFX.

    #4569
    psyko
    Member

    I tried again, and it doesn’t seem to be linked to the Xon/Xoff. Even when sending one command every second, I have the issue…

    Even worst, it jumped from line 49 to line 74….

    {"r":{"gc":"N49G1F300.0Z-2.0","n":49,"f":[1,0,103,5670]}}
    {"sr":{"line":25,"posy":18.998,"posz":3.000,"vel":21.88}}
    {"sr":{"posy":18.996,"vel":22.12}}
    {"sr":{"posy":18.974,"vel":33.36}}
    {"sr":{"posy":18.935,"vel":60.67}}
    {"sr":{"posy":18.865,"vel":104.03}}
    {"sr":{"posy":18.752,"vel":163.46}}
    {"sr":{"posy":18.603,"vel":230.67}}
    {"sr":{"posy":18.370,"vel":320.46}}
    {"sr":{"posy":18.062,"vel":407.19}}
    {"sr":{"posy":17.690,"vel":477.86}}
    {"sr":{"posy":17.265,"vel":532.46}}
    {"sr":{"posy":16.803,"vel":571.01}}
    {"sr":{"posy":16.365,"vel":591.97}}
    {"sr":{"posy":15.867,"vel":600.00}}
    {"sr":{"posy":15.368,"vel":600.00}}
    {"sr":{"posy":14.868}}
    {"sr":{"posy":14.369}}
    {"sr":{"posy":13.870}}
    {"sr":{"posy":13.420}}
    {"sr":{"posy":12.921}}
    {"sr":{"posy":12.422}}
    {"sr":{"posy":11.923}}
    {"sr":{"posy":11.423}}
    {"sr":{"posy":10.924}}
    {"sr":{"posy":10.475}}
    {"sr":{"posy":9.975}}
    {"sr":{"posy":9.476}}
    {"sr":{"posy":8.977}}
    {"sr":{"posy":8.477}}
    {"sr":{"posy":7.978}}
    {"sr":{"posy":7.529}}
    {"sr":{"posy":7.029}}
    {"sr":{"posy":6.530}}
    {"sr":{"posy":6.031}}
    {"sr":{"posy":5.531}}
    {"sr":{"posy":5.032}}
    {"sr":{"posy":4.583}}
    {"sr":{"posy":4.083}}
    {"sr":{"posy":3.584}}
    {"sr":{"posy":3.085}}
    {"sr":{"posy":2.587,"vel":591.97}}
    {"sr":{"posy":2.104,"vel":567.88}}
    {"sr":{"posy":1.692,"vel":532.46}}
    {"sr":{"posy":1.272,"vel":477.86}}
    {"sr":{"posy":0.905,"vel":407.19}}
    {"sr":{"posy":0.605,"vel":320.46}}
    {"sr":{"posy":0.380,"vel":230.67}}
    {"sr":{"posy":0.223,"vel":156.79}}
    {"sr":{"posy":0.128,"vel":104.03}}
    {"sr":{"posy":0.062,"vel":60.67}}
    {"sr":{"posy":0.025,"vel":33.36}}
    {"sr":{"posy":0.004,"vel":22.12}}
    {"r":{"gc":"N74G1Y0.0","n":74,"f":[1,0,19,2165]}}
    • This reply was modified 11 years ago by psyko.
    #4571
    psyko
    Member

    Ok, problem solved !
    This was definitely me handling the Xon/Xoff flag incorrectly…
    It seems to be solved now 🙂

    #4579
    alden
    Member

    Cool stuff. A couple of things to note:

    – It is possible that a status report can be skipped. This is normal and by design. The system will not report more frequently than the status interval: {“si”:250} for example. This is to manage the load on the serial line in heavy traffic. You will not miss any events as all changes are reported, but things like line numbers, velocity, position might “skip ahead”.

    – You might want to consider setting your footer depth variable (fd) to 0. This makes the JSON footer a peer of the response, and sets up for future developments where things other than ‘r’s will return with footers. We left the fd=1 setting in so as not to break legacy parsers, but if you are doing this new I’d recommend using fd=0

    #4599
    psyko
    Member

    Thanks for the answer.

    A missing status report is not a problem.
    I was simply expecting the GCode commande confirmation {“r”:{“gc”:…}}.

    I’ll have to look for the fd parameter, but I can’t find it in the Wiki… Any link ?

    thanks

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.