Redler Technologies Inc.

Welcome to the Motor Controller Documentation

This is an API and help page for the Redler Technologies' Motion Communication Library.

Installing The NuGet Package

To get started, click here here to view the feed. Click "Connect To Feed" and select the Visual Studio tab. Follow the instructions. After that, install the NuGet package "Redler.Motion.Communication".

Configuring Your Project

To run the communication library, your project must be cofigured to the platform "x64" and the target must be at least .net7, with OS windows.

Using The Library

Add the using statements:

C#
using Redler.Motion.Communication.MotionCom;
using Redler.Motion.Communication.MotionPackets;

Run this code to test the library:

C#
MotionSerialCom com = new("COMXXX", 230400); // Fill the converter name that connected to your PC 
com.ConnectCom();

// Integer parameters
MotionDataPacket getMotorOn = new((1, 0)); // getting the status of the motor. In the response - 0 is off, o/w on

// Set Packet
byte[] newRollHighValueBytes = [0, 0, 0, 0];
Random.Shared.NextBytes(newRollHighValueBytes);
int newRollHighValue = int.Abs(BitConverter.ToInt32(newRollHighValueBytes));
Console.WriteLine("Creating Hall Roll High packet with new value - {0}", newRollHighValue);
MotionDataPacket getHallRollHigh = new((70, 2), newRollHighValue); // Set Hall roll high to some random number

// Get Packets
MotionDataPacket getHallRollLow = new((70, 3)); // Hall roll low
MotionDataPacket getHallDirection = new((70, 4)); // Hall direction
// Float parameters
MotionDataPacket getHallSpeedPLF = new((70, 6), true); // Hall speed LPF [Hz]
MotionDataPacket getIPhaseA = new((30, 10), true); // I Phase A
MotionDataPacket getIPhaseB = new((30, 11), true); // I Phase B
MotionDataPacket getIPhaseC = new((30, 12), true); // I Phase C
IEnumerable<MotionDataPacket> parametersToGet =
[
    getMotorOn,
    getHallRollHigh,
    getHallRollLow,
    getHallDirection,
    getHallSpeedPLF,
    getIPhaseA,
    getIPhaseB,
    getIPhaseC,
];

Console.WriteLine("Sending Packets...");
// sending all the packets
foreach (var packet in parametersToGet)
{
    Console.WriteLine("Sending {0}[{1}]...", packet.Index, packet.SubIndex);
    await com.SendPacketAsync(packet);
}
// waiting for a bit to let the packets arrive
await Task.Delay(1000);

// initiating new list of response packets
List<MotionDataPacket> responses = [];

// receiving all the pending packets on the RX buffer
Console.WriteLine("Receiving Responses...");
while (true)
{
    var response = await com.ReceivePacketAsync();
    if (response.ErrorFlag)
    {
        //await Console.Error.WriteLineAsync($"Failed to receive packet. Error Code: {(MotionPacketHelper.ErrorCodes)((MotionDataPacket)response).Payload[0]}");
        break;
    }

    responses.Add((MotionDataPacket)response);
}

foreach (var response in responses)
{
    if (response.Command == (100, 0)) // the driver send a driver fault - parse it
    {
        var (commandID, index, errorCode) = MotionPacketHelper.ParseDriverFault(response.Payload);
        Console.WriteLine($"{commandID}[{index}] - {errorCode}");
        continue;
    }

    if (response.IsFloat) // if the response is marked as float, show the value as float
    {
        Console.WriteLine($"{response}, As Float - {response.PayloadAsFloat:F6}");
    }
    else // the response is marked as int, show the value as int
    {
        Console.WriteLine($"{response}, As Int - {response.PayloadAsInt}");
    }
}

await com.CloseComAsync();

See Also

Other Resources