Reply To: Error: Wrong Number of Bytes received.

HomeForumsMonoBrick Communication LibraryError: Wrong Number of Bytes received.Reply To: Error: Wrong Number of Bytes received.

#4016
Author Image
Sumit Goyal
Participant

Ya sure!

The code chunk is:

do {

Console.Write(“Loop:”+ i);
// Error comes here in the next statement
int CurrentReading = brick.Sensor1.Read();
Console.Write(” CSR: “+ CurrentReading);

Error = SetPoint – CurrentReading;

Integral = 0.5 * Integral + Error;
Derivative = Error – PrevError;
PrevError = Error;

Dgain = Derivative * Kd;
Igain = Integral * Ki;
Pgain = Error * Kp;
gain= Dgain+Igain+Pgain;

Total= (Dgain+Igain+Pgain)*-1;
Total= Convert.ToInt16(Total);

if(Total<-100)
Total= -100;
if(Total>100)
Total=100;

spower = Convert.ToSByte(Total);
Console.Write(” spower:”+ spower);
brick.MotorB.On (spower);
brick.MotorC.On (spower);
i=i+1;

Console.Write(” Power: ” + Total+”\n”);

// Thread.Sleep(30); helps, but does not solve

} while(i<1000);

watch.Stop();
var elapsedMs = watch.ElapsedMilliseconds/1000;
Console.Write(” Time: ” + elapsedMs);

brick.MotorB.Off();
brick.MotorC.Off();
brick.MotorA.Off();
brick.Connection.Close();
}

Posted in

Make a donation