Welcome! Log In Create A New Profile

Advanced

Sending gcode to a RepRap Printer?

Posted by arthurmani 
Sending gcode to a RepRap Printer?
September 28, 2012 06:57AM
Hi Guys,

I have been looking at the printerface.py code but I could not find the line that sends the gcode to the com port on which the printer is connected.

Hope you can help me to find it and how do you recommend sending a gcode to the printer once it is ready as an array of string (I am using c# and Windows 7)?

I have looked at the System.IO.Ports.SerialPort.Write(String) method in MSDN. I was told Pronterface was written "for UNIX", what type of method is it using and how can Windows understand this?

Many thanks,

Arthur

Edited 2 time(s). Last edit at 09/28/2012 07:44AM by arthurmani.


--
Arthur Mamou-Mani
Architect, AAdipl, RIBA III
Tutor DS10 Westminster University
Mamou-Mani.com ¦ WeWantToLearn.net
Re: Sending gcode to a RepRap Printer?
September 28, 2012 08:22AM
Console.ReadLine(File);
Console.WriteLine(ComPort);


Bob Morrison
Wörth am Rhein, Germany
"Luke, use the source!"
BLOG - PHOTOS - Thingiverse
Re: Sending gcode to a RepRap Printer?
September 28, 2012 09:55AM
Quote

how do you recommend sending a gcode to the printer once it is ready as an array of string

Communications between a host and a RepRap controller is plain text over a serial line. You can take sample code for talking to modems or remote hosts via SSH. In a Unix-like environment a simple "cat part.gcode >/dev/ttyUSBxxx" works.

... with one caveat: only few firmwares support flow control (Teacup supports XON/XOFF). Flow control is done by waiting for an "ok" coming back before sending the next line. Expect long waiting times for this ok when the printer is busy.


Generation 7 Electronics Teacup Firmware RepRap DIY
     
Re: Sending gcode to a RepRap Printer?
September 28, 2012 11:14AM
Quote

how do you recommend sending a gcode to the printer once it is ready as an array of string

foreach (line in GCode)
Console.WriteLine(ComPort, line);


Bob Morrison
Wörth am Rhein, Germany
"Luke, use the source!"
BLOG - PHOTOS - Thingiverse
Re: Sending gcode to a RepRap Printer?
September 28, 2012 05:09PM
I am just writing a simple Visual C# 2010 program to send my own g codes to my hexapod robot. You should be able to crib all you need on how to send codes from it, including setting up the com port etc.

There are a few pitfalls such as the firmware not recognising end of lines etc. My hexapod code is based on reprap firmware, so the program should be compatable. Just modify the buttons on the form to do what you want.

Sample Program
Re: Sending gcode to a RepRap Printer?
September 29, 2012 07:05PM
Hi Martin,
Thanks a lot for your reply! I opened the Helium Frog Hexapod project and ran the program. When opening the COM5@115200 i had an error saying `Access to the port 'COM5' is denied.` This happens on the port.Open(); line on the method buttonOpenPort_Click() below.
Do you know what is happening?
All the best,
Arthur

private void buttonOpenPort_Click(object sender, EventArgs e)
{
string selectedportname;
int selectedbaudrate;
selectedportname = combportnumber.SelectedItem.ToString();
selectedbaudrate = Convert.ToInt32 (cmbBaudRate.SelectedItem.ToString());
port = new SerialPort(selectedportname, selectedbaudrate, Parity.None, 8, StopBits.One);
port.DtrEnable = true;
port.Open();
port.DataReceived += serialPort1_DataReceived;

Edited 1 time(s). Last edit at 09/29/2012 07:07PM by arthurmani.


--
Arthur Mamou-Mani
Architect, AAdipl, RIBA III
Tutor DS10 Westminster University
Mamou-Mani.com ¦ WeWantToLearn.net
Re: Sending gcode to a RepRap Printer?
September 29, 2012 07:27PM
@arthurmani

The program doesn't do any fancy error checking, so it won't check if the port is valid etc. It will say the port does not exist, or is denied.

This could be because the port is bieng used by another program, you aren't running as administrator and dont have permission.

You can double check the com ports by using the hyperterminal program. Usually found in the start button / programs/ accessories / communications menu.
Re: Sending gcode to a RepRap Printer?
September 29, 2012 07:41PM
Thanks Martin,

I have checked the baud rate in the device manager port setting and specified the rate of 9600. Pressing the `open` button did not create an error. I then pressed some of the buttons like `G11 D 315 ` or `G0 X -120.711 Y 170.711 Z -120` but the machine does not move. Under the receive data I have `~?.#_?[5?Z??` what does this mean?

It could mean that I am still not connected. Unfortunately, the hyperterminal program is not present in Windows 7. Is there an alternative? Pronterface, the python software used with RepRap work on COM5@250000 I have tried to write this baud rate
but got a `System.NullRefrenceException` error.

Best,

A

Edited 4 time(s). Last edit at 09/30/2012 06:42AM by arthurmani.


--
Arthur Mamou-Mani
Architect, AAdipl, RIBA III
Tutor DS10 Westminster University
Mamou-Mani.com ¦ WeWantToLearn.net
Re: Sending gcode to a RepRap Printer?
September 30, 2012 08:35AM
Just to confirm

You are not expecting my code to completely control a reprap machine. The code is to give you examples so you can write your own. It is just so you can see how the com ports are programmed in a C# program.

If you just wan t plug and play solution, use pronterface. Its very good and works well.

You need to have the same baud rate set on your host software as in the firmware otherwise things dont work!

Access denied by the com port could be that a program using that port has crashed previously but is still connected to the port. In visual C# you just need to restart the software and this generally tidies things up. At worst a reboot of your machine will certainly clear this.

You are connected to something, otherwise you wouldn't recieve data back in the lower window. The text reported in the lower window is generated by what the connected device is sending back to the com port.

It may be you have a strange font selected for the text boxes and it prints strange code. My Visual C# version was set to a default text font that wasn't on my machine....another microsoft bug! Just modify the selected font in the text box properties.

Modify the values so you are sending a G1 Y10 X10 Z10 to the port, this should move the printer. This works on my prusa machine (Mine is connected to com4 but your machine may be different. It proves the communication works. It would just then be a case of writing your own software around these routines.
Re: Sending gcode to a RepRap Printer?
October 14, 2012 06:01PM
Hi Guys,

Martin, thank you so much for your help!

I wrote a new code which is now receiving data from the RepRap. The problem I am facing now is that the gcode that I send doesn't seem to be recognize by the device. Trying to send the gcode `g28` through the line port.Write("g28");.

My program connects to the right serial port however when I try sending the information as string the access to the com port gets denied when it was not before. Do you guys know how I could fix that?

Code below:

//Fields
    List myReceivedLines = new List();


    //subscriber method for the port.DataReceived Event
    private void DataReceivedHandler(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
    {
        SerialPort sp = (SerialPort)sender;
        while (sp.BytesToRead > 0)
        {
            try
            {
                myReceivedLines.Add(sp.ReadLine());
            }
            catch (TimeoutException)
            {
                break;
            }
        }
    }


    protected override void SolveInstance(IGH_DataAccess DA)
    {

        string selectedportname = default(string);
        DA.GetData(1, ref selectedportname);
        int selectedbaudrate = default(int);
        DA.GetData(2, ref selectedbaudrate);
        bool connecttodevice = default(bool);
        DA.GetData(3, ref connecttodevice);
        bool homeall = default(bool);
        DA.GetData(5, ref homeall);

        SerialPort port = new SerialPort(selectedportname, selectedbaudrate, Parity.None, 8, StopBits.One); 

        port.DtrEnable = true;   
        port.Open();             

        if (connecttodevice == true)
        {
            port.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
            DA.SetDataList(0, myReceivedLines);
        }

        if (homeall == true)
        {
            port.Write("g28");
        }

    }


--
Arthur Mamou-Mani
Architect, AAdipl, RIBA III
Tutor DS10 Westminster University
Mamou-Mani.com ¦ WeWantToLearn.net
Re: Sending gcode to a RepRap Printer?
October 15, 2012 11:57AM
Sorry I solved that by doirng:
SerialPort.Write("G28"+"\n")


--
Arthur Mamou-Mani
Architect, AAdipl, RIBA III
Tutor DS10 Westminster University
Mamou-Mani.com ¦ WeWantToLearn.net
Re: Sending gcode to a RepRap Printer?
October 17, 2014 04:02PM
Old thread but I was looking at this today and found good old dos still works with com ports.
Not the most robust or feature rich interface but...
Things like echo G29>com6 and type auto0.g>com6 or copy auto0.g com6 do work.
I guess I may try to create a batch file sends a file to the sd card at least.
Sorry, only registered users may post in this forum.

Click here to login