本文整理汇总了C#中RepetierHost.model.GCode类的典型用法代码示例。如果您正苦于以下问题:C# GCode类的具体用法?C# GCode怎么用?C# GCode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GCode类属于RepetierHost.model命名空间,在下文中一共展示了GCode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: receiveLine
public void receiveLine(GCode code)
{
bytesin += code.orig.Length;
ana.Analyze(code);
lock (output)
{
if (code.hasM) switch (code.M)
{
case 115: // Firmware
output.AddLast("FIRMWARE_NAME:RepetierVirtualPrinter FIRMWARE_URL:https://github.com/repetier/Repetier-Firmware/ PROTOCOL_VERSION:1.0 MACHINE_TYPE:Mendel EXTRUDER_COUNT:1 REPETIER_PROTOCOL:1");
//output.AddLast("FIRMWARE_NAME:Marlin FIRMWARE_URL:https://github.com/repetier/Repetier-Firmware/ PROTOCOL_VERSION:1.0 MACHINE_TYPE:Mendel EXTRUDER_COUNT:1 REPETIER_PROTOCOL:1");
break;
case 105: // Print Temperatures
output.AddLast("T:" + extruderTemp.ToString("0") + " B:" + bedTemp.ToString("0"));
break;
case 205: // EEPROM Settings
output.AddLast("EPR:2 75 76800 Baudrate");
output.AddLast("EPR:2 79 0 Max. inactive time [ms,0=off]");
output.AddLast("EPR:2 83 60000 Stop stepper afer inactivity [ms,0=off]");
output.AddLast("EPR:3 3 40.00 X-axis steps per mm");
output.AddLast("EPR:3 7 40.00 Y-axis steps per mm");
output.AddLast("EPR:3 11 3333.59 Z-axis steps per mm");
output.AddLast("EPR:3 15 20000.00 X-axis max. feedrate [mm/min]");
output.AddLast("EPR:3 19 20000.00 Y-axis max. feedrate [mm/min]");
output.AddLast("EPR:3 23 2.00 Z-axis max. feedrate [mm/min]");
output.AddLast("EPR:3 27 1500.00 X-axis homing feedrate [mm/min]");
output.AddLast("EPR:3 31 1500.00 Y-axis homing feedrate [mm/min]");
output.AddLast("EPR:3 35 100.00 Z-axis homing feedrate [mm/min]");
output.AddLast("EPR:3 39 20.00 X-axis start speed [mm/s]");
output.AddLast("EPR:3 43 20.00 Y-axis start speed [mm/s]");
output.AddLast("EPR:3 47 1.00 Z-axis start speed [mm/s]");
output.AddLast("EPR:3 51 750.00 X-axis acceleration [mm/s^2]");
output.AddLast("EPR:3 55 750.00 Y-axis acceleration [mm/s^2]");
output.AddLast("EPR:3 59 50.00 Z-axis acceleration [mm/s^2]");
output.AddLast("EPR:3 63 750.00 X-axis travel acceleration [mm/s^2]");
output.AddLast("EPR:3 67 750.00 Y-axis travel acceleration [mm/s^2]");
output.AddLast("EPR:3 71 50.00 Z-axis travel acceleration [mm/s^2]");
output.AddLast("EPR:3 150 373.00 Extr. steps per mm");
output.AddLast("EPR:3 154 1200.00 Extr. max. feedrate [mm/min]");
output.AddLast("EPR:3 158 10.00 Extr. start feedrate [mm/s]");
output.AddLast("EPR:3 162 10000.00 Extr. acceleration [mm/s^2]");
output.AddLast("EPR:0 166 1 Heat manager [0-1]");
output.AddLast("EPR:0 167 130 PID drive max");
output.AddLast("EPR:2 168 300 PID P-gain [*0.01]");
output.AddLast("EPR:2 172 2 PID I-gain [*0.01]");
output.AddLast("EPR:2 176 2000 PID D-gain [*0.01]");
output.AddLast("EPR:0 180 200 PID max value [0-255]");
output.AddLast("EPR:2 181 0 X-offset [steps]");
output.AddLast("EPR:2 185 0 Y-offset [steps]");
output.AddLast("EPR:2 189 40 Temp. stabilize time [s]");
break;
}
output.AddLast("ok");
}
}
示例2: writeArray
private void writeArray(BinaryWriter file, List<GCodeShort> list, bool binary)
{
foreach (GCodeShort code in list)
{
GCode gc = new GCode();
gc.Parse(code.text);
if (gc.hostCommand) continue;
if (binary)
{
if (gc.hasCode)
{
byte[] data = gc.getBinary(1);
file.Write(data);
}
}
else
{
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
string cmd = gc.getAscii(false, false);
if (cmd.Length > 0)
file.Write(enc.GetBytes(cmd + "\n"));
}
}
}
示例3: Connect
public override bool Connect()
{
con.isMarlin = con.isRepetier = con.isSprinter = false;
connected = true;
virtualPrinter.open(int.Parse(baudRate));
GCode gc = new GCode();
gc.Parse("M105");
virtualPrinter.receiveLine(gc);
connected = true;
if (transferProtocol < 2)
binaryVersion = 0;
else binaryVersion = transferProtocol - 1;
con.binaryVersion = binaryVersion;
readyForNextSend = true;
lock (nackLines)
{
nackLines.Clear();
}
linesSend = errorsReceived = bytesSend = 0;
gc.Parse("N0 M110");
virtualPrinter.receiveLine(gc);
gc.Parse("M115");
virtualPrinter.receiveLine(gc);
gc.Parse("M105");
virtualPrinter.receiveLine(gc);
con.FireConnectionChange(Trans.T("L_CONNECTED") + ":" + con.printerName);
Main.main.Invoke(Main.main.UpdateJobButtons);
return true;
}
示例4: injectManualCommandFirst
public void injectManualCommandFirst(string command)
{
GCode gc = new GCode();
gc.Parse(command);
if (gc.comment) return;
lock (history)
injectCommands.AddFirst(gc);
if (job.dataComplete == false)
{
if (injectCommands.Count == 0)
{
firePrinterAction(Trans.T("L_IDLE"));
}
else
{
firePrinterAction(Trans.T1("L_X_COMMANDS_WAITING", injectCommands.Count.ToString()));
}
}
}
示例5: Analyze
public void Analyze(GCode code)
{
if (code.hostCommand)
{
string cmd = code.getHostCommand();
if (cmd.Equals("@hide"))
drawing = false;
else if (cmd.Equals("@show"))
drawing = true;
else if (cmd.Equals("@isathome"))
{
hasXHome = hasYHome = hasZHome = true;
x = Main.printerSettings.XHomePos;
y = Main.printerSettings.YHomePos;
z = Main.printerSettings.ZHomePos;
xOffset = yOffset = zOffset = 0;
}
return;
}
//if (code.forceAscii) return; // Don't analyse host commands and unknown commands
if (code.hasN)
lastline = code.N;
if (uploading && !code.hasM && code.M != 29) return; // ignore upload commands
if (code.hasG)
{
switch (code.G)
{
case 0:
case 1:
eChanged = false;
if (code.hasF) f = code.F;
if (relative)
{
if (code.hasX) x += code.X;
if (code.hasY) y += code.Y;
if (code.hasZ) z += code.Z;
if (code.hasE)
{
if (eChanged = code.E != 0)
{
if (code.E < 0) activeExtruder.retracted = true;
else if (activeExtruder.retracted)
{
activeExtruder.retracted = false;
activeExtruder.e = activeExtruder.emax;
}
else
activeExtruder.e += code.E;
}
}
}
else
{
if (code.hasX) x = xOffset + code.X;
if (code.hasY) y = yOffset + code.Y;
if (code.hasZ)
{
z = zOffset + code.Z;
}
if (code.hasE)
{
if (eRelative)
{
if (eChanged = code.E != 0)
{
if (code.E < 0) activeExtruder.retracted = true;
else if (activeExtruder.retracted)
{
activeExtruder.retracted = false;
activeExtruder.e = activeExtruder.emax;
}
else
activeExtruder.e += code.E;
}
}
else
{
if (eChanged = activeExtruder.e != (activeExtruder.eOffset + code.E))
{
activeExtruder.e = activeExtruder.eOffset + code.E;
if (activeExtruder.e < activeExtruder.lastE)
activeExtruder.retracted = true;
else if (activeExtruder.retracted)
{
activeExtruder.retracted = false;
activeExtruder.e = activeExtruder.emax;
activeExtruder.eOffset = activeExtruder.e - code.E;
}
}
}
}
}
if (x < Main.printerSettings.XMin) { x = Main.printerSettings.XMin; hasXHome = false; }
if (y < Main.printerSettings.YMin) { y = Main.printerSettings.YMin; hasYHome = false; }
if (z < 0 && FormPrinterSettings.ps.printerType!=3) { z = 0; hasZHome = false; }
if (x > Main.printerSettings.XMax) { hasXHome = false; }
if (y > Main.printerSettings.YMax) { hasYHome = false; }
if (z > printerHeight) { hasZHome = false; }
if (activeExtruder.e > activeExtruder.emax)
{
//.........这里部分代码省略.........
示例6: executeHostCommand
public void executeHostCommand(GCode code)
{
string com = code.getHostCommand();
string param = code.getHostParameter();
if (com.Equals("@info"))
{
conn.log(param, false, 3);
}
else if (com.Equals("@pause"))
{
conn.pause(param);
}
}
示例7: writeString
private void writeString(BinaryWriter file, string code, bool binary)
{
GCode gc = new GCode();
gc.Parse(code);
if (gc.hostCommand) return;
if (binary)
{
if (gc.hasCode)
{
byte[] data = gc.getBinary(1);
file.Write(data);
}
}
else
{
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
string cmd = gc.getAscii(false, false);
if (cmd.Length > 0)
file.Write(enc.GetBytes(cmd + "\n"));
}
}
示例8: Analyze
public void Analyze(GCode code)
{
if (code.hostCommand)
{
string cmd = code.getHostCommand();
if (cmd.Equals("@hide"))
drawing = false;
else if (cmd.Equals("@show"))
drawing = true;
else if (cmd.Equals("@isathome"))
{
hasXHome = hasYHome = hasZHome = true;
x = xOffset = 0;
y = yOffset = 0;
z = zOffset = 0;
}
return;
}
if (code.forceAscii) return; // Don't analyse host commands and unknown commands
if (code.hasN)
lastline = code.N;
if (uploading && !code.hasM && code.M != 29) return; // ignore upload commands
if (code.hasG)
{
switch (code.G)
{
case 0:
case 1:
if (code.hasF) f = code.F;
if (relative)
{
if (code.hasX) x += code.X;
if (code.hasY) y += code.Y;
if (code.hasZ) z += code.Z;
if (code.hasE) e += code.E;
}
else
{
if (code.hasX) x = xOffset + code.X;
if (code.hasY) y = yOffset + code.Y;
if (code.hasZ)
{
z = zOffset + code.Z;
}
if (code.hasE)
{
if (eRelative)
e += code.E;
else
e = eOffset + code.E;
}
}
if (x < 0) { x = 0; hasXHome = false; }
if (y < 0) { y = 0; hasYHome = false; }
if (z < 0) { z = 0; hasZHome = false; }
if (x > printerWidth) { hasXHome = false; }
if (y > printerDepth) { hasYHome = false; }
if (z > printerHeight) { hasZHome = false; }
if (e > emax)
{
emax = e;
if (z > lastZPrint)
{
layer++;
lastZPrint = z;
if (!privateAnalyzer && Main.conn.job.hasData() && Main.conn.job.maxLayer >= 0)
{
PrinterConnection.logInfo("Printing layer " + layer.ToString() + " of " + Main.conn.job.maxLayer.ToString());
}
}
}
if (eventPosChanged != null)
if (privateAnalyzer)
eventPosChanged(code, x, y, z);
else
Main.main.Invoke(eventPosChanged, code, x, y, z);
float dx = Math.Abs(x - lastX);
float dy = Math.Abs(y - lastY);
float dz = Math.Abs(z - lastZ);
float de = Math.Abs(e - lastE);
if (dx + dy + dz > 0.001)
{
printingTime += Math.Sqrt(dx * dx + dy * dy + dz * dz) * 60.0f / f;
}
else printingTime += de * 60.0f / f;
lastX = x;
lastY = y;
lastZ = z;
lastE = e;
break;
case 28:
case 161:
{
bool homeAll = !(code.hasX || code.hasY || code.hasZ);
if (code.hasX || homeAll) { xOffset = 0; x = 0; hasXHome = true; }
if (code.hasY || homeAll) { yOffset = 0; y = 0; hasYHome = true; }
if (code.hasZ || homeAll) { zOffset = 0; z = 0; hasZHome = true; }
if (code.hasE) { eOffset = 0; e = 0; emax = 0; }
if (eventPosChanged != null)
if (privateAnalyzer)
//.........这里部分代码省略.........
示例9: PushGCodeShortArray
public void PushGCodeShortArray(List<GCodeShort> codes)
{
foreach (GCodeShort line in codes)
{
if (line.Length == 0) continue;
ana.analyzeShort(line);
GCode gcode = new GCode();
gcode.Parse(line.text);
if (!gcode.comment)
{
jobList.AddLast(new GCodeCompressed(gcode));
totalLines++;
}
if (line.hasLayer)
maxLayer = line.layer;
}
computedPrintingTime = ana.printingTime;
}
示例10: Reduce
public void Reduce()
{
if (segments.Count < 2) return;
if (!liveView)
{
GCodePath first = segments.First.Value;
while (segments.Count > 1)
{
first.Join(segments.First.Next.Value);
segments.First.Next.Value.Free();
segments.Remove(segments.First.Next.Value);
}
}
else
{
LinkedListNode<GCodePath> act = segments.First, next;
while (act.Next != null)
{
next = act.Next;
if (next.Next == null) return; // Don't touch last segment we are writing to
GCodePath nextval = next.Value;
if (nextval.pointsCount < 2)
{
act = next;
if (act.Next != null)
act = act.Next;
}
else if (nextval.lastDist > minHotDist)
{
if (act.Value.pointsCount < 500)
{
act.Value.Join(nextval);
segments.Remove(nextval);
nextval.Free();
}
else
{
act = next;
}
}
else
if (act.Value.pointsCount < 5000 || (nextval.pointsCount >= 5000 && act.Value.pointsCount < 27000))
{
act.Value.Join(nextval);
segments.Remove(nextval);
nextval.Free();
}
else
{
act = next;
}
}
}
}
示例11: OnPosChange
void OnPosChange(GCode act, float x, float y, float z)
{
if (!ana.drawing)
{
lastx = x;
lasty = y;
lastz = z;
laste = ana.emax;
return;
}
float locDist = (float)Math.Sqrt((x - lastx) * (x - lastx) + (y - lasty) * (y - lasty) + (z - lastz) * (z - lastz));
bool isLastPos = locDist < 0.00001;
if (!act.hasG || (act.G > 1 && act.G != 28)) return;
if (segments.Count == 0 || laste >= ana.e) // start new segment
{
if (!isLastPos) // no move, no action
{
GCodePath p = new GCodePath();
p.Add(new Vector3(x, y, z), ana.emax, totalDist);
if (segments.Count > 0 && segments.Last.Value.pointsLists.Last.Value.Count == 1)
{
segments.RemoveLast();
}
segments.AddLast(p);
changed = true;
}
}
else
{
if (!isLastPos)
{
totalDist += locDist;
segments.Last.Value.Add(new Vector3(x, y, z), ana.emax, totalDist);
changed = true;
}
}
lastx = x;
lasty = y;
lastz = z;
laste = ana.emax;
}
示例12: OnPosChangeCreateCheckpoint
public void OnPosChangeCreateCheckpoint(GCode code, float x, float y, float z)
{
movementsCount++;
bool EnableCreateCheckpointOnNumberOfMovements = RegMemory.GetBool("enableCreateCheckpointOnNumberOfMovements", true);
long NumberOfMovementsToCreateCheckpoint = RegMemory.GetLong("numberOfMovementsToCreateCheckpoint", 10);
if (Main.conn.connector.IsJobRunning() && !Main.conn.connector.IsPaused && EnableCreateCheckpointOnNumberOfMovements && (NumberOfMovementsToCreateCheckpoint > 0 && movementsCount % NumberOfMovementsToCreateCheckpoint == 0))
{
checkpoints.CreateCheckpoint(MovementCountCheckpointType.Instance);
}
}
示例13: ResendLine
public override void ResendLine(int line)
{
if (line == openResend) return; // line was not send yet, do not do it twice
if (binaryVersion != 0)
{
int send = receivedCount();
//serial.DiscardOutBuffer();
System.Threading.Thread.Sleep(send * 10000 / int.Parse(baudRate)); // Wait for buffer to empty
byte[] buf = new byte[32];
for (int i = 0; i < 32; i++) buf[i] = 0;
serial.Write(buf, 0, 32);
System.Threading.Thread.Sleep(320000 / int.Parse(baudRate)); // Wait for buffer to empty
}
else
{
//serial.DiscardOutBuffer();
serial.WriteLine("");
System.Threading.Thread.Sleep(receiveCacheSize * 10000 / int.Parse(baudRate)); // Wait for buffer to empty
}
if (line > lastline) return; // resend request during connect can request unpossible resends
if (line == ignoreResendLine && con.isRepetier == true) // Ignore repeated resend requests
{
if (ignoreResendLineForXCalls > 0) ignoreResendLineForXCalls--;
if (ignoreResendLineForXCalls > 0) return;
}
ignoreResendLine = line;
ignoreResendLineForXCalls = 7;
/* if (!prequelFinished && line > lastline)
{
RLog.message("ignoring resend in prequel");
if (pingPong)
readyForNextSend = true;
return;
}*/
if (!connected) return;
errorsReceived++;
resendError++;
lock (nextlineLock)
{
if (serial == null) return;
/*if (ignoreXEqualResendsResend>0 && (line & 65535) == (lastResendLine & 65535))
{
ignoreXEqualResendsResend--;
return;
}
lastResendLine = line;
ignoreXEqualResendsResend = 15;*/
if (pingPong)
readyForNextSend = true;
lock (nackLines)
{
nackLinesBuffered.Clear();
nackLines.Clear(); // printer flushed all coming commands
}
lock (history)
{
LinkedListNode<GCode> node = history.Last;
GCode gc = null;
if (node == null)
{
gc = new GCode("N" + line + " M105");
openResend = line;
history.AddLast(gc);
resendNode = history.Last;
history.AddFirst(new GCode("N1 M110"));
return;
}
if (resendError > 5 || node == null)
{
con.log(Trans.T("L_RECEIVING_ONLY_ERRORS"), false, 2); // Receiving only error messages. Stopped communication.
con.close(true);
RepetierHost.view.SoundConfig.PlayError(false);
return; // give up, something is terribly wrong
}
line &= 65535;
do
{
gc = node.Value;
if (gc.hasN && (gc.N & 65535) == line)
{
openResend = line;
resendNode = node;
TrySendNextLine();
return;
}
if (node.Previous == null)
{
history.Clear();
openResend = line;
history.AddFirst(new GCode("N" + line + " M105"));
resendNode = history.First;
history.AddFirst(new GCode("N1 M110"));
return;
}
node = node.Previous;
//history.RemoveLast();
//node = history.Last;
} while (true);
}
}
//.........这里部分代码省略.........
示例14: AddGCode
/// <summary>
/// Add a GCode line to be visualized.
/// </summary>
/// <param name="g"></param>
public void AddGCode(GCode g)
{
act = g;
ana.Analyze(g);
laste = ana.activeExtruder.emax;
}
示例15: OnPosChange
void OnPosChange(GCode act, float x, float y, float z)
{
if (!ana.drawing)
{
lastx = x;
lasty = y;
lastz = z;
laste = ana.activeExtruder.emax;
return;
}
float locDist = (float)Math.Sqrt((x - lastx) * (x - lastx) + (y - lasty) * (y - lasty) + (z - lastz) * (z - lastz));
bool isLastPos = locDist < 0.00001;
if (!act.hasG || (act.G > 3 && act.G != 28)) return;
bool isTravel = (FormPrinterSettings.ps.printerType == 3 ? Math.Max(z, lastz) - ana.zOffset >= FormPrinterSettings.ps.cncZTop : !ana.eChanged);
int segpos = ana.activeExtruderId;
if (segpos < 0 || segpos >= MaxExtruder) segpos = 0;
LinkedList<GCodePath> seg = segments[segpos];
if (isTravel)
{
GCodeTravel travel = new GCodeTravel();
travel.fline = GCodePoint.toFileLine(fileid, actLine);
travel.p1.X = lastx;
travel.p1.Y = lasty;
travel.p1.Z = lastz;
travel.p2.X = x;
travel.p2.Y = y;
travel.p2.Z = z;
travelMoves.Add(travel);
if (FormPrinterSettings.ps.printerType == 3 && z - ana.zOffset < FormPrinterSettings.ps.cncZTop) // End od travel moves
{ // Start new milling move sequence
GCodePath p = new GCodePath();
p.Add(new Vector3(x, y, z), ana.activeExtruder.emax, totalDist, GCodePoint.toFileLine(fileid, actLine));
if (seg.Count > 0 && seg.Last.Value.pointsLists.Last.Value.Count == 1)
{
seg.RemoveLast();
}
seg.AddLast(p);
}
}
if (seg.Count == 0 || (laste >= ana.activeExtruder.e && FormPrinterSettings.ps.printerType != 3)) // start new segment
{
if (!isLastPos) // no move, no action
{
GCodePath p = new GCodePath();
p.Add(new Vector3(x, y, z), ana.activeExtruder.emax, totalDist, GCodePoint.toFileLine(fileid, actLine));
if (seg.Count > 0 && seg.Last.Value.pointsLists.Last.Value.Count == 1)
{
seg.RemoveLast();
}
seg.AddLast(p);
changed = true;
}
}
else
{
if (!isLastPos && (FormPrinterSettings.ps.printerType != 3 || !isTravel))
{
totalDist += locDist;
seg.Last.Value.Add(new Vector3(x, y, z), ana.activeExtruder.emax, totalDist, GCodePoint.toFileLine(fileid, actLine));
changed = true;
}
}
lastx = x;
lasty = y;
lastz = z;
laste = ana.activeExtruder.emax;
}