privateQueue<string>sentCommandQueue;//Keeps track of commands sent to printer to be used in translation (only keeps strings until printer responses to command)
//To avoid spamming resends so fast that we lag mattercontrol we wait 20ms before checking response Also if there is an active dwell we wait the dwell duration before accepting the OK
//After response is translated we check to see if the lockout of a M109 is active
if(printerDetails.heatingLockout)
{//Check if the previous M105 has sent all of its associated packets (1-3 packets per M105)
if(QueueIsEmpty())
{
//check to see if we have reached target temperature(s) and either disable the lock out or send another M105
if(ExtruderIsReady(translatedReply)&&BedIsReady(translatedReply)&&secondExtruderIsReady(translatedReply))//Maker bot seems to stop the lockout when within 2 Degrees so we will match it
{
printerDetails.heatingLockout=false;
}
else
{
translatedReply=supressOk(translatedReply);//don't send an ok back until we are done heating
booltemp;//Normally we check if we need to send this command to the printer but if a RS is requested it has to be sent
printerDetails.targetBedTemp=0;//Flashforges seem to lose the ability to maintain this temperature, rather than locking them out forever we remove the requirement after reached once
}
returnisReady;
}
privatestringsupressOk(stringtranslatedReply)
{
if(translatedReply.Contains("ok"))
{
translatedReply=translatedReply.Replace("ok","");
}
returntranslatedReply;
}
privateboolhasFullPacket()
{
boolresult=false;
intbyteCount=port.BytesToRead;
byte[]bytesRead;
if(readPacket.Count>0&&byteCount>0)//if the readPacket already has values and the input buffer has bytes to read
{
if(byteCount>readPacket.ElementAt(1))
{
bytesRead=newbyte[readPacket.ElementAt(1)+1];
port.Read(bytesRead,0,readPacket.ElementAt(1)+1);
readPacket.AddRange(bytesRead);
result=true;
}
}
elseif(byteCount>2)//if the input buffer has bytes to read and you get here then we start filling the readPacket
{
bytesRead=newbyte[2];
port.Read(bytesRead,0,2);
if(bytesRead[0]==0xD5)//checks for start bit from printer
{
readPacket.AddRange(bytesRead);
if(readPacket.ElementAt(1)<byteCount)//checks packet size against how full the buffer is
{
bytesRead=newbyte[readPacket.ElementAt(1)+1];
port.Read(bytesRead,0,readPacket.ElementAt(1)+1);
readPacket.AddRange(bytesRead);
result=true;
}
}
else
{
if(bytesRead[1]==0xD5)//checks for start bit in second spot in case we somehow got a stray bit in here somehow
{
readPacket.Add(bytesRead[1]);//Add the start bit and retrieve packet length from the buffer (may need to check buffer size before reading)
bytesRead=newbyte[1];
port.Read(bytesRead,0,1);
readPacket.Add(bytesRead[0]);
if(readPacket.ElementAt(1)<byteCount)//checks packet size against how full the buffer is