C# 클래스 AForge.Robotics.Lego.RCXBrick

Manipulation of Lego Mindstorms RCX device.

The class allows to manipulate with Lego Mindstorms RCX device, setting its motors' state, getting information about sensors' values and performing some other manipulations.

The class supports both types of IR towers - USB and serial (see RCXBrick.IRTowerType).

The class uses GhostAPI to communicate with Lego RCX device, so its libraries (GhostAPI.dll, PbkComm32.dll and PbkUsbPort.dll) should be placed into applications folder.

Sample usage:

// create an instance of RCX brick RCXBrick rcx = new RCXBrick( ); // connect to the device if ( rcx.Connect( RCXBrick.IRTowerType.USB ) ) { // set forward direction of motor A rcx.SetMotorDirection( RCXBrick.Motor.A, true ); // set power of motor rcx.SetMotorPower( RCXBrick.Motor.A, 1 ); // turm motor on rcx.SetMotorOn( RCXBrick.Motor.A, true ); // ... // turn off motors A, B and C rcx.SetMotorOn( RCXBrick.Motor.ABC, false ); // get first sensor's value short value; if ( rcx.GetSensorValue( RCXBrick.Sensor.First, out value ) ) { // ... } // ... }
파일 보기 프로젝트 열기: holisticware-admin/MonoVersal.AForgeNET

공개 메소드들

메소드 설명
ClearSensor ( Sensor sensor ) : bool

Clear the counter associated with the specified sensor by setting it to a value of zero.

Connect ( IRTowerType towerType ) : bool

Connect to Lego RCX brick.

If connection to RCX brick was established before the call, existing connection will be reused. If it is required to force reconnection, then Disconnect method should be called before.

Disconnect ( ) : void

Disconnnect from Lego RCX brick.

GetBatteryPower ( int &power ) : bool

Get battery power of RCX brick.

GetSensorValue ( Sensor sensor, short &value ) : bool

Get sensor's value.

GetVersion ( string &romVersion, string &firmwareVersion ) : bool

Get version information of RCX brick.

IsAlive ( ) : bool

Check if the RCX brick is alive and responds to messages.

PlaySound ( SoundType type ) : bool

Play one of supported sounds.

PlayTone ( short frequency, byte duration ) : bool

Play tone of specified frequency.

PowerOff ( ) : bool

Turn off the RCX brick.

RCXBrick ( ) : System

Initializes a new instance of the RCXBrick class.

SetMotorDirection ( Motor motors, bool isForward ) : bool

Set direction of specified motors.

SetMotorOn ( Motor motors, bool on ) : bool

Turn on/off specified motors.

SetMotorPower ( Motor motors, byte power ) : bool

Set power of specified motors.

SetSensorMode ( Sensor sensor, SensorMode mode ) : bool

Set sensor's mode.

SetSensorType ( Sensor sensor, SensorType type ) : bool

Set sensor's type.

SetTime ( byte hours, byte minutes ) : bool

Set current time for the RCX brick.

SetTransmitterRange ( bool isLongRange ) : bool

Set IR transmitter's range.

보호된 메소드들

메소드 설명
SendCommand ( byte command, byte reply, int expectedReplyLen ) : bool

Send command to Lego RCX brick and read reply.

메소드 상세

ClearSensor() 공개 메소드

Clear the counter associated with the specified sensor by setting it to a value of zero.
public ClearSensor ( Sensor sensor ) : bool
sensor Sensor Sensor to clear value of.
리턴 bool

Connect() 공개 메소드

Connect to Lego RCX brick.
If connection to RCX brick was established before the call, existing connection will be reused. If it is required to force reconnection, then Disconnect method should be called before.
public Connect ( IRTowerType towerType ) : bool
towerType IRTowerType Type of IR tower to use for communication with RCX brick.
리턴 bool

Disconnect() 공개 메소드

Disconnnect from Lego RCX brick.
public Disconnect ( ) : void
리턴 void

GetBatteryPower() 공개 메소드

Get battery power of RCX brick.
public GetBatteryPower ( int &power ) : bool
power int RCX brick's battery power in millivolts.
리턴 bool

GetSensorValue() 공개 메소드

Get sensor's value.
public GetSensorValue ( Sensor sensor, short &value ) : bool
sensor Sensor Sensor to get value of.
value short Retrieved sensor's value (units depend on current /// sensor's type and mode).
리턴 bool

GetVersion() 공개 메소드

Get version information of RCX brick.
public GetVersion ( string &romVersion, string &firmwareVersion ) : bool
romVersion string ROM version number.
firmwareVersion string Firmware version number.
리턴 bool

IsAlive() 공개 메소드

Check if the RCX brick is alive and responds to messages.
public IsAlive ( ) : bool
리턴 bool

PlaySound() 공개 메소드

Play one of supported sounds.
public PlaySound ( SoundType type ) : bool
type SoundType Sound type to play.
리턴 bool

PlayTone() 공개 메소드

Play tone of specified frequency.
public PlayTone ( short frequency, byte duration ) : bool
frequency short Tone frequency in Hz.
duration byte Tone duration in 1/100ths of a second.
리턴 bool

PowerOff() 공개 메소드

Turn off the RCX brick.
public PowerOff ( ) : bool
리턴 bool

RCXBrick() 공개 메소드

Initializes a new instance of the RCXBrick class.
public RCXBrick ( ) : System
리턴 System

SendCommand() 보호된 메소드

Send command to Lego RCX brick and read reply.
Communication can not be performed, because connection with /// RCX brick was not established yet. Reply buffer size is smaller than the reply data size. Reply does not correspond to command (first byte of reply /// should be complement (bitwise NOT) to the first byte of command orred with 0x08).
protected SendCommand ( byte command, byte reply, int expectedReplyLen ) : bool
command byte Command to send.
reply byte Buffer to receive reply into.
expectedReplyLen int Expected reply length.
리턴 bool

SetMotorDirection() 공개 메소드

Set direction of specified motors.
public SetMotorDirection ( Motor motors, bool isForward ) : bool
motors Motor Motors to set direction of.
isForward bool True to set forward direction, false to set backward.
리턴 bool

SetMotorOn() 공개 메소드

Turn on/off specified motors.
public SetMotorOn ( Motor motors, bool on ) : bool
motors Motor Motors to turn on/off.
on bool True to turn motors on, otherwise false.
리턴 bool

SetMotorPower() 공개 메소드

Set power of specified motors.
public SetMotorPower ( Motor motors, byte power ) : bool
motors Motor Motors to set power of.
power byte Power level to set, [0..7].
리턴 bool

SetSensorMode() 공개 메소드

Set sensor's mode.
public SetSensorMode ( Sensor sensor, SensorMode mode ) : bool
sensor Sensor Sensor to set mode of.
mode SensorMode Sensor mode to set.
리턴 bool

SetSensorType() 공개 메소드

Set sensor's type.
public SetSensorType ( Sensor sensor, SensorType type ) : bool
sensor Sensor Sensor to set type of.
type SensorType Sensor type to set.
리턴 bool

SetTime() 공개 메소드

Set current time for the RCX brick.
public SetTime ( byte hours, byte minutes ) : bool
hours byte Hours, [0..23].
minutes byte Minutes, [0..59].
리턴 bool

SetTransmitterRange() 공개 메소드

Set IR transmitter's range.
public SetTransmitterRange ( bool isLongRange ) : bool
isLongRange bool True if long range should be set, otherwise false.
리턴 bool