Welcome! Log In Create A New Profile

Advanced

Printer Response

Posted by Abinav_Shankar 
Printer Response
January 07, 2019 09:13PM
Hi,
I have an ANET A8 3D Printer running Marlin 1.1.x. I'm using a Raspberry Pi to use serial communication for the 3D Printer for my school project. I was able to send GCodes properly to the 3D Printer but I couldn't interpret the printer response correctly. It always gives me a character within quotes preceded by b (E.g. b's'). If I decode the message using decode() I get a single digit response which is the same without the letter b and the quotes ( E.g. b's' is decoded to s). I have attached my output response. I read somewhere that the Printer gives 'ok' as response but all I get is 's' during idle statements and when I pass some GCode and get a response, it is some random letter. Also, I receive the same response when I pass in M114 to get the extruder position. Is there something I'm missing.
Attachments:
open | download - {7846562C-3C10-4EDA-BCF5-08AE931068E5}.png.jpg (30.2 KB)
Re: Printer Response
January 07, 2019 09:42PM
This makes zero sense.

the printer does respond with 'ok'

so there is an issue

if you notice several lines down you get the k..


There is something wrong with your code...

How about sharing your code, instead of posting the same thing again?

Edited 1 time(s). Last edit at 01/07/2019 09:43PM by Dust.
Re: Printer Response
January 08, 2019 01:55AM
Could this be that the setting of your serial connection is wrong, so that the Pi interprets the parity bit of the arriving byte to be the 8th data bit?
(That could explain why the "k" is received correctly and the "o" not - the 2 characters have different parity.)
Re: Printer Response
January 08, 2019 03:34AM
Hi,

Quote
Dust
This makes zero sense.

the printer does respond with 'ok'

so there is an issue

if you notice several lines down you get the k..


There is something wrong with your code...

How about sharing your code, instead of posting the same thing again?

I have attached the source code of my program. Its for a college project. Its function is to read the coordinates and other parameters from a file and then to generate a GCode based on the file and send it to 3D Printer. It also saves a copy of the GCode communicated on the local disk. The program loops through every three seconds and if the data from the file is modified, the GCode will also be changed accordingly and the command will be sent to the printer.

I hope you understood.

Thanks.

Edited 1 time(s). Last edit at 01/08/2019 03:35AM by Abinav_Shankar.
Attachments:
open | download - 3D_Printer_Communication.py (3.6 KB)
Re: Printer Response
January 08, 2019 03:37AM
Quote
enif
Could this be that the setting of your serial connection is wrong, so that the Pi interprets the parity bit of the arriving byte to be the 8th data bit?
(That could explain why the "k" is received correctly and the "o" not - the 2 characters have different parity.)

I have set the baud rate equal to that of my 3D Printer. Is there anything else that needs to be set? Sorry, I'm new to 3D Printing.
Re: Printer Response
January 08, 2019 04:14AM
UTF8???

we work in ascii...

Sure some of it is the same... (values under 128) ... needs looking deeper.

EDIT: On further reflection I don't think this is it...

Edited 3 time(s). Last edit at 01/08/2019 04:48AM by Dust.
Re: Printer Response
January 08, 2019 04:34AM
or as enif said, perhaps more serial settings

eg try explicity telling it everything like this

device=serial.Serial()
device.baudrate=115200
device.port='/dev/ttyUSB0'
device.bytesize = serial.EIGHTBITS #number of bits per bytes
device.parity = serial.PARITY_NONE #set parity check: no parity
device.stopbits = serial.STOPBITS_ONE #number of stop bits
device.xonxoff = False #disable software flow control
device.rtscts = False #disable hardware (RTS/CTS) flow control
device.dsrdtr = False #disable hardware (DSR/DTR) flow control
device.open()
Re: Printer Response
January 08, 2019 07:23AM
Quote
Dust
UTF8???

we work in ascii...

Sure some of it is the same... (values under 128) ... needs looking deeper.

EDIT: On further reflection I don't think this is it...

I tried playing with other data types and utf-8 is the only type the printer seems to accept. For others it just throws an error.
Re: Printer Response
January 28, 2019 06:59AM
I tried declaring the serial settings explicitly but no effect. It still gives me single character response. Any other suggestions would be greatly helpful.

I was away for a while so couldn't test it out immediately.

Thanks.
Re: Printer Response
January 28, 2019 09:29AM
I knew that Octoprint and Printrun are written in Python.
I did quick dives into the source codes because I had always wanted too see how the code flowed, after seeing your post it got the best of me.

Looking through someones code to get an ideal is except-able. You are in school to learn by example and these are an excellent code examples.
Do not cave to plagiarism but strive for that "A" you will deserve it after tackling this mildly complex 3D Printer control program.
When you are finished would like to see what you can up with, it just may turn out to be better version of a 3D Printer control program.

A quick dive into Octoprint source
server/__init__.py
printer.connect(port=port, baudrate=baudrate, profile=printer_profile["id"] if "id" in printer_profile else "_default")

A quick dive in Printrun
printrun/printcore.py
self.printer = Serial(port = self.port,
                            baudrate = self.baud,
                            timeout = 0.25,
                            parity = PARITY_ODD)

Though it appears your source code more closely resembles Printrun style of programming
Looking further through the your code it appears you have a good connection, you need to retrieve information from the host 3D Printers,


Computer Programmer / Electronics Technician
Re: Printer Response
January 28, 2019 08:08PM
I tried but still the same. Couldn't figure out why it gives me these values. But it responds in a proper way to GCodes.

Thanks
Sorry, only registered users may post in this forum.

Click here to login