Skip to content

Commit

Permalink
better fix for #86
Browse files Browse the repository at this point in the history
  • Loading branch information
arkypita committed Aug 30, 2017
1 parent a07e0f7 commit 917150b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 33 deletions.
8 changes: 8 additions & 0 deletions LaserGRBL/GrblCommand.cs
Expand Up @@ -211,6 +211,14 @@ public bool IsGrblCommand

public bool IsEmpty
{get{return mLine.Length == 0;}}

public bool IsWriteEEPROM
{ get { return IsGrblCommand && IsSetConf; } } //maybe need to add G10/G28.1/G30.1 ?

System.Text.RegularExpressions.Regex confRegEX = new System.Text.RegularExpressions.Regex(@"^[$](\d+) *= *(\d+\.?\d*)");
private bool IsSetConf
{ get { return confRegEX.IsMatch(mLine); } }


#region G Codes

Expand Down
16 changes: 5 additions & 11 deletions LaserGRBL/GrblCore.cs
Expand Up @@ -632,7 +632,9 @@ private bool CanSend()

private GrblCommand PeekNextCommand()
{
if (CurrentStreamingMode == StreamingMode.Buffered && mQueuePtr.Count > 0) //sono buffered e ho roba da trasmettere
if (mPending.Count > 0 && mPending.Peek().IsWriteEEPROM) //if managing eeprom write act like sync
return null;
else if (CurrentStreamingMode == StreamingMode.Buffered && mQueuePtr.Count > 0) //sono buffered e ho roba da trasmettere
return mQueuePtr.Peek();
else if (CurrentStreamingMode != StreamingMode.Buffered && mPending.Count == 0) //sono sync e sono vuoto
if (mRetryQueue != null) return mRetryQueue;
Expand Down Expand Up @@ -969,17 +971,9 @@ public decimal LoopCount
{ get { return mLoopCount; } set { mLoopCount = value; if (OnLoopCountChange != null) OnLoopCountChange(mLoopCount); } }

private StreamingMode CurrentStreamingMode
{
get
{
if (IsImportExportStream)
return StreamingMode.Synchronous;
else
return (StreamingMode)Settings.GetObject("Streaming Mode", StreamingMode.Buffered);
}
}
{ get {return (StreamingMode)Settings.GetObject("Streaming Mode", StreamingMode.Buffered); }}

public bool IsImportExportStream { get { return !object.ReferenceEquals(mQueue, mQueuePtr); } }
//public bool IsImportExportStream { get { return !object.ReferenceEquals(mQueue, mQueuePtr); } }

private static string mDataPath;
public static string DataPath
Expand Down
37 changes: 15 additions & 22 deletions LaserGRBL/GrblEmulator/GrblEmulator.cs
Expand Up @@ -98,10 +98,6 @@ protected override void OnMessage(MessageEventArgs e)
{ mPaused = false; SendStatus(); }
else if (e.RawData.Length == 1 && e.RawData[0] == 24)
GrblReset();
else if (e.Data == "$$\n")
SendConfig();
else if (IsSetConf(e.Data))
SetConfig(e.Data);
else
EnqueueRX(e);
}
Expand All @@ -114,8 +110,7 @@ private void SetConfig(string p)
{
try
{
Console.Write(p);

System.Threading.Thread.Sleep(1000);
System.Text.RegularExpressions.MatchCollection matches = confRegEX.Matches(p);
int key = int.Parse(matches[0].Groups[1].Value);

Expand All @@ -128,23 +123,22 @@ private void SetConfig(string p)
else if (configTable[key] is bool)
configTable[key] = int.Parse(matches[0].Groups[2].Value) == 0 ? false : true;

ImmediateTX("ok");
EnqueueTX("ok");
}
else
ImmediateTX("error");
EnqueueTX("error");
}
catch(Exception ex)
{
ImmediateTX("error");
EnqueueTX("error");
}
}

private Dictionary<int, object> configTable = new Dictionary<int, object> { { 0, 10 }, { 1, 25 }, { 2, 0 }, { 3, 0 }, { 4, false }, { 5, false }, { 6, false }, { 10, 1 }, { 11, 0.010m }, { 12, 0.002m }, { 13, false }, { 20, false }, { 21, false }, { 22, false }, { 23, 0 }, { 24, 25.000m }, { 25, 500.000m }, { 26, 250 }, { 27, 1.000m }, { 30, 1000.0m }, { 31, 0.0m }, { 32, false }, { 100, 250.000m }, { 101, 250.000m }, { 102, 250.000m }, { 110, 500.000m }, { 111, 500.000m }, { 112, 500.000m }, { 120, 10.000m }, { 121, 10.000m }, { 122, 10.000m }, { 130, 200.000m }, { 131, 200.000m }, { 132, 200.000m } };

private void SendConfig()
{
Console.WriteLine("$$");
ImmediateTX("ok");
EnqueueTX("ok"); //REPLY TO $$
foreach (KeyValuePair<int, object> kvp in configTable)
{
if (kvp.Value is decimal)
Expand Down Expand Up @@ -221,17 +215,14 @@ private void ManageRX()
{
string line = rxBuf.Dequeue();


LaserGRBL.GrblCommand C = new GrblCommand(line);
EmulateCommand(C);

Console.WriteLine(C.Command.Trim("\n".ToCharArray()));

//System.Random rnd = new Random();
//if (rnd.Next(10) == 5)
// EnqueueTX("error");
//else
EnqueueTX("ok");
if (line == "$$\n")
SendConfig();
else if (IsSetConf(line))
SetConfig(line);
else
EmulateCommand(new GrblCommand(line));

Console.WriteLine(line.Trim("\n".ToCharArray()));
}
catch (Exception ex)
{
Expand Down Expand Up @@ -313,6 +304,8 @@ private void EmulateCommand(GrblCommand cmd)

catch (Exception ex) { throw ex; }
finally { cmd.DeleteHelper(); }

EnqueueTX("ok");
}
}

Expand Down

0 comments on commit 917150b

Please sign in to comment.