Skip to content
This repository has been archived by the owner on Apr 5, 2020. It is now read-only.

Added StartProgram to run a program on the brick. #18

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Lego.Ev3.Core/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,25 @@ public void OutputReady(OutputPort ports)
AddParameter((byte)ports); // ports
}

/// <summary>
/// Run a program on the brick
/// </summary>
/// <param name="filePath">Filepath on the brick of the program to run</param>
public void StartProgram(string filePath)
{
AddOpcode(Opcode.File);
AddRawParameter(0x08); // File subcode command
AddRawParameter(0x01); // User program slot
AddParameter(filePath); // "../prjs/Project/Program.rbf"
AddRawParameter(0x40); // LV0(0) // Set
AddRawParameter(0x44); // LV0(4) // Set
AddRawParameter(0x03); // Opcode.Program_Start
AddRawParameter(0x01); // User program slot
AddRawParameter(0x40); // LV0(0) // Get
AddRawParameter(0x44); // LV0(4) // Get
AddRawParameter(0x00); // Debug mode normal
}

/// <summary>
/// End and send a Command to the EV3 brick.
/// </summary>
Expand Down
29 changes: 28 additions & 1 deletion Lego.Ev3.Core/DirectCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,26 @@ internal DirectCommand(Brick brick)
;
}

/// <summary>
/// Run a program on the brick
/// </summary>
/// <param name="filePath">Filepath on the brick of the program to run</param>
/// <returns></returns>
public
#if WINRT
IAsyncAction
#else
Task
#endif
StartProgramAsync(string filePath)
{
return StartProgramAsyncInternal(filePath)
#if WINRT
.AsAsyncAction()
#endif
;
}

internal async Task TurnMotorAtPowerAsyncInternal(OutputPort ports, int power)
{
Command c = new Command(CommandType.DirectNoReply);
Expand Down Expand Up @@ -1220,5 +1240,12 @@ internal async Task OutputReadyAsyncInternal(OutputPort ports)
c.OutputReady(ports);
await _brick.SendCommandAsyncInternal(c);
}
}

internal async Task StartProgramAsyncInternal(string filePath)
{
Command c = new Command(CommandType.DirectNoReply);
c.StartProgram(filePath);
await _brick.SendCommandAsyncInternal(c);
}
}
}
4 changes: 3 additions & 1 deletion Lego.Ev3.Core/DummyCommunication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ public void Disconnect()
string s = string.Empty;
for(int i = 3; i < data.Length; i++)
s += data[i].ToString("X2") + " ";
Debug.WriteLine("Write: " + s);
bool contains = s.Contains("00 00 5E 00 99 05 81 00 81 00 E1 00 E1 01 99 1D 81 00 81 00 81 00 81 00 81 01 E1 02 99 1C 81 00 81 00 81 00 81 00 81 01 E1 06 99 1B 81 00 81 00 81 00 81 00 81 01 E1 0A 99 05 81 00 81 01 E1 0B E1 0C 99 1D 81 00 81 01 81 00 81 00 81 01 E1 0D 99 1C 81 00 81 01 81 00 81 00 81 01 E1 11 99 1B 81 00 81 01 81 00 81 00 81 01 E1 15 99 05 81 00 81 02 E1 16 E1 17 99 1D 81 00 81 02 81 00 81 00 81 01 E1 18 99 1C 81 00 81 02 81 00 81 00 81 01 E1 1C 99 1B 81 00 81 02 81 00 81 00 81 01 E1 20 99 05 81 00 81 03 E1 21 E1 22 99 1D 81 00 81 03 81 00 81 00 81 01 E1 23 99 1C 81 00 81 03 81 00 81 00 81 01 E1 27 99 1B 81 00 81 03 81 00 81 00 81 01 E1 2B 99 05 81 00 81 10 E1 2C E1 2D 99 1D 81 00 81 10 81 00 81 00 81 01 E1 2E 99 1C 81 00 81 10 81 00 81 00 81 01 E1 32 99 1B 81 00 81 10 81 00 81 00 81 01 E1 36 99 05 81 00 81 11 E1 37 E1 38 99 1D 81 00 81 11 81 00 81 00 81 01 E1 39 99 1C 81 00 81 11 81 00 81 00 81 01 E1 3D 99 1B 81 00 81 11 81 00 81 00 81 01 E1 41 99 05 81 00 81 12 E1 42 E1 43 99 1D 81 00 81 12 81 00 81 00 81 01 E1");
if (!contains)
Debug.WriteLine("Write: " + s);
})
#if WINRT
.AsAsyncAction()
Expand Down
3 changes: 3 additions & 0 deletions Lego.Ev3.Core/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ enum Opcode
OutputStepSync = 0xb0,
OutputTimeSync = 0xb1,

File = 0xC0,
Program_Start = 0x03,

Tst = 0xff,
}

Expand Down