Workshop: USB, serial and remote communications with C#

This entry is part 2 of 6 in the series Bioloid Workshop

[Previous post: Workshop: Dynamixel communications with C#]

Bioloid SerialPort2Dynamixel C#

Bioloid SerialPort2Dynamixel C#

SerialPort2Dynamixel

Encapsulating  the SerialPort .Net class offers an easy way to use the serial port and receive Dynamixel Zig messages with the Dynamixel protocol.

.

.

Collaborator classes:

Bioloid SerialPort2Dynamixel C# Collaborators

Bioloid SerialPort2Dynamixel C# Collaborators

– The SerialPort .Net class.

RCDataReader class, which unpack the Dynamixel Zigbee sequence offering the clean data received.

Operations:

The public interface that others classes will use offers principally these operations:

public void setRemoteControlMode(bool on), which sets on or off the reception of data


public void setRemoteControlMode(bool on)
{
if (on)
setReceiveDataMethod(rdDataReader.rawRemoteDataReceived);
else
setReceiveDataMethod(null);
}

public void setReceiveDataMethod(remoteControlDataReceived rcDataReceived), that sets the method that will be called when serial port data is received.

And some basics serial port data operations:

Raspberry Pi - USB2Dynamixel - CM510

Raspberry Pi – USB2Dynamixel – CM510

public bool open(String com, int speed), to open the serial port which name is in the com parameter. Wireless communications and USB ports, as used by Zig or USB2Dynaniel, are also serial ports  (COM1, COM2, … or /ttyUSB0, ttyUSB1).

public void close(), it will do nothing if the port is already closed.

public byte[] query(byte[] buffer, int pos, int wait), send (write) a query and gets (read) the result.

public void rawWrite(byte[] buffer, int pos), well… it will write whatever contains the buffer in the first pos positions

public byte[] rawRead() , read and returns the data received.

Notes:

To avoid concurrency problems all the operations that use the Dynamixel bus are protected with a Mutex object that avoids that two or more concurrent objects use SerialPort2Dynamixel simultaneously entering the same operation or using the same resources, like variables, objects or the Dynamixel bus.

Xevel USB2AX

Xevel USB2AX

USB2AX over USB2DYNAMIXEL

USB2AX over USB2DYNAMIXEL

RCDataReader

Bioloid RCDataReader C#

Bioloid RCDataReader C#

Remote communications

RemoteCommunications

Its responsability is to receive the Dynamixel Zig packets and extract the data.

Collaborator class:

– The ZigSequence enum, with the Dynamixels protocols data sections

RC-100 packet

RC-100 packet

Operations:

Robotis RC-100 remote controller values

Robotis RC-100 remote controller values

public void rawRemoteDataReceived(byte[] rcData), receives the Zigbee data.

public int getValue(), returns the last value received

Series Navigation<< Workshop: Programming a Bioloid robot workbench using C# and C++C++, Bioloid and Raspberry Pi (v0.2) >>
%d bloggers like this: