We use cookies to personalize content, interact with our analytics companies, advertising networks and cooperatives, and demographic companies, provide social media features, and to analyze our traffic. Our social media, advertising and analytics partners may combine it with other information that you’ve provided to them or that they’ve collected from your use of their services. Learn more.
I’ve been doing a bit of researching an it looks like you just need to write to the serial port the arduino is on. I found this on microsoft’s site:
Sub SendSerialData(ByVal data As String)
' Send strings to a serial port.
Using com1 As IO.Ports.SerialPort =
My.Computer.Ports.OpenSerialPort("COM1")
com1.WriteLine(data)
End Using
End Sub
There is also a nice little example program on the grbl wiki showing how to communicate written in python.
import serial
import time
# Open grbl serial port
s = serial.Serial('/dev/tty.usbmodem1811',115200)
# Open g-code file
f = open('grbl.gcode','r');
# Wake up grbl
s.write("\r\n\r\n")
time.sleep(2) # Wait for grbl to initialize
s.flushInput() # Flush startup text in serial input
# Stream g-code to grbl
for line in f:
l = line.strip() # Strip all EOL characters for consistency
print 'Sending: ' + l,
s.write(l + '\n') # Send g-code block to grbl
grbl_out = s.readline() # Wait for grbl response with carriage return
print ' : ' + grbl_out.strip()
# Wait here until grbl is finished to close serial port and file.
raw_input(" Press <Enter> to exit and disable grbl.")
# Close file and serial port
f.close()
s.close()
What I’m failing to wrap my head around is how to implement an NC file. I think I’m going to move this to a new thread!
It is actually a lot easier than that. Just drag this guy onto the form.
You will need to deal with threading issues, but a simple google search will show you how to deal with that. The serial data will come from a separate thread than the form controls.
Here is a way to text text from another thread.
Delegate Sub SetTextDelagate(ByVal ctrl As Control, ByVal Text As String)
Public Sub SetText(ByVal ctrl As Control, ByVal Text As String)
If ctrl.InvokeRequired Then
Dim del = New SetTextDelagate(AddressOf SetText)
ctrl.Invoke(del, ctrl, Text)
Else
ctrl.Text = Text
End If
End Sub
Perfect, thanks! This is what I was thinking would be the case, but I’m not entirely familiar with this process.
Yup, in my head I was thinking that it would be exactly that, the user would choose the file they wanted to load.
I’ve had some experience programming in Visual Basic, just some simple applications to aid in my day to day work at the company I work for. Basically I know just enough to be dangerous. Thanks for your help!
This is great! Exactly what I was looking for, a simple program just so I could wrap my head around the basic concepts! Thank you!
You guys are going pretty “old school” on everything. There are some pretty powerful objects to deal with most of this stuff. Here is how I read the file. (sorry about how Discuss is trying to color the lines.
Dim reader As New System.IO.StreamReader(mFilename)
Do While Not reader.EndOfStream
readline = reader.ReadLine().Trim() 'trim of the white space (especially the line end stuff)
If readline <> "" Then 'is there anythin left after the trim?
' do something with readline.
End If
Loop
This is perfect! Thanks. So during the if statement is that where you would print the line out to the arduino?
I find as I’m writing code, I’m usually learning. More times than not I’ll find out the huge block of code I just spent hours on can be summed up with some super simple built in function/method! A bit frustrating sometimes, but there always seems to be a better, simpler way out there!
No, that is just reading a file. Read the grbl wiki. Grbl can only handle a few lines at a time. Overly simplified…you send it a line, wait for an “OK”, then send the next.
My program rolls all this into one high level object called “GrblInterface”. It handles everything.
Serial port
Protocol (the "OK"s)
Timers
Parsing of responses
Real time Status (including where grbl is in 3D space)
All you need to do is design a local interface. My object generates events when status changes so you can update the interface. I’ll try to clean that up and publish it in the week or two.
Awesome, thanks for all the info. Like I said I know just enough to be dangerous. Once I dive into it I’m sure I’ll get the hang of it. Seeing your code would greatly expand my understanding of this! I’m not too bad at following along code, as I generally am searching online for little snippets here and there when I’m coding!
I uploaded a demo of the GrblInterface Class I use to GitHub. I put a super simple GUI with it. The GUI is not meant for actual use. It just demos the use of the class.
It is not the Tablet Based GUI. I am still testing that. The GrblInterface Class might be updated due to needs of the Table GUI
There is no compiled version or setup program. The repo is targeted at VB.Net programmers.
Thank you for posting the demo code! It is really well commented and easy to follow. I never thought I would be writing VB code again, but this opens up a whole new world of possibilities of things we can make the X-Carve do.