A bed levelling plugin automatization: some issues with the Serial communication

What is the problem?

Please see my attached code: test_1.zip (794 Bytes)

Hey everyone !
I'm a beginner in the developping world, so my knowledges are very limited...
I'm trying to develop a plugin called "ZConfig" and this is a plugin that'll automatize the bed levelling of an ender 3 using a probe (I know, the jneilliii plugin already exists, but mine is very specific. And I prefere to learn things and code :slight_smile:). My problem is that at some moments of the bed levelling calibration, some X, Y, and Z coordinates needs to be read using a M114.
Jneilliii helped me at some points in this task and a BIG thanks to him, but I don't want to ask him for everything...
So, my problem is that with my code, when I send the custom GCODE with the parameter next to it example: @ZCONFIG 1 the printer head is really moving and not far from doing what I want, but the M114 value storage is a bit odd... You'll see in my logs that I have to send the command 3 times to finally get the coordinates in the settings to then print them. This is really annoying because I don't want to move the head 3 times always.

What did you already try to solve it?

I already tried several thing. At first, I used a the hook gcode.received so I could get the output line, but then jneilliii told me to use the event "if position changed.." and it's working better, because before I had the coordinates before the command was received, so it wasn't working. And now I have them after, but still need to send the command 3 times.... Not so good... I tried to send the GCODE head movements 3 times in the code using a "for i in range..." but not working too. In my opinion, it looks like a weird communication issue..

Complete Logs

2020-07-19 01:45:15,842 - octoprint.plugins.test_1 - INFO - Hey, I'm in the flagCollection 2
2020-07-19 01:45:15,845 - octoprint.plugins.test_1 - INFO - 0.0
2020-07-19 01:45:15,845 - octoprint.plugins.test_1 - INFO - 0.0
2020-07-19 01:45:15,845 - octoprint.plugins.test_1 - INFO - 0.0
2020-07-19 01:45:15,865 - octoprint.plugins.test_1 - INFO - {'reason': None, u'e': 0.0, u't': 0, u'f': None, u'y': 0.0, u'x': 0.0, u'z': 0.0}
2020-07-19 01:45:15,867 - octoprint.plugins.test_1 - INFO - ['0.0', '0.0', '0.0', '0.0']

2020-07-19 01:45:18,624 - octoprint.plugins.test_1 - INFO - Hey, I'm in the flagCollection 2
2020-07-19 01:45:18,625 - octoprint.plugins.test_1 - INFO - 0.0
2020-07-19 01:45:18,625 - octoprint.plugins.test_1 - INFO - 0.0
2020-07-19 01:45:18,627 - octoprint.plugins.test_1 - INFO - 0.0
2020-07-19 01:45:18,668 - octoprint.plugins.test_1 - INFO - {'reason': None, u'e': 0.0, u't': 0, u'f': None, u'y': 100.0, u'x': 100.0, u'z': 0.0}
2020-07-19 01:45:18,668 - octoprint.plugins.test_1 - INFO - ['0.0', '100.0', '100.0', '0.0']

2020-07-19 01:45:21,176 - octoprint.plugins.test_1 - INFO - Hey, I'm in the flagCollection 2
2020-07-19 01:45:21,177 - octoprint.plugins.test_1 - INFO - 100.0
2020-07-19 01:45:21,177 - octoprint.plugins.test_1 - INFO - 100.0
2020-07-19 01:45:21,177 - octoprint.plugins.test_1 - INFO - 0.0
2020-07-19 01:45:21,193 - octoprint.plugins.test_1 - INFO - {'reason': None, u'e': 0.0, u't': 0, u'f': None, u'y': 100.0, u'x': 100.0, u'z': 0.0}`
2020-07-19 01:45:21,194 - octoprint.plugins.test_1 - INFO - ['0.0', '100.0', '100.0', '0.0']

As you can see in my logs, (I distinguished the 3 blocks) I need to send the @ZCONFIG 2 three times before having the:

2020-07-19 01:45:21,177 - octoprint.plugins.test_1 - INFO - 100.0
2020-07-19 01:45:21,177 - octoprint.plugins.test_1 - INFO - 100.0
2020-07-19 01:45:21,177 - octoprint.plugins.test_1 - INFO - 0.0` 

that corresponds to the xyz coordinates from the settings.
Of course, it's the same thing for the @ZCONFIG 1

Additional information about your setup

I'm currently using the last windows version of Octoprint and a virtual printer for faster changes.

Thank you in advance for answer :wink:
Take care of yourself

problem solved :slight_smile:

What was the solution?

1 Like

I had to keep sending M114 while the coordinates didn't changed in the settings, but it was a little tricky...
Not perfect but working enough for my application