While I was at LEGO World I worked up some example functions for Andreas Dreier but they are definitely not part of the NXC API at this point. I'm working on some changes to the enhanced NBC/NXC firmware that will support direct commands over RS485 but it isn't quite there yet either. The most recent changes involve adding a byte to the beginning of direct and system commands sent via RS485 so that you can address them to a specific NXT (CONN_HS_ALL, CONN_HS_1, CONN_HS_2, ... CONN_HS_8). Each brick will be able to set its own RS485 address using SetHSAddress(byte hsAddr) and the HS_ADDRESS_ALL, HS_ADDRESS_1, ... HS_ADDRESS_8 constants.
The high level motor control functions that support remote brick motor control will be named differently from the existing ones (something like what you see below, perhaps).
John Hansen
Code: Select all
#define RS485
#ifdef RS485
#define theConn CONN_HS4
#else
#define theConn CONN_BT1
#endif
void OnFwdAny(byte conn, byte output, char speed)
{
if (conn == CONN_BT0)
OnFwd(output, speed);
else
RemoteSetOutputState(conn, output, speed, OUT_MODE_MOTORON+OUT_MODE_BRAKE, OUT_REGMODE_IDLE, 0, OUT_RUNSTATE_RUNNING, 0);
}
void OffAny(byte conn, byte output)
{
if (conn == CONN_BT0)
Off(output);
else
RemoteSetOutputState(conn, output, 0, OUT_MODE_MOTORON+OUT_MODE_BRAKE, OUT_REGMODE_IDLE, 0, OUT_RUNSTATE_RUNNING, 0);
}
void OnRevAny(byte conn, byte output, byte speed)
{
if (conn == CONN_BT0)
OnRev(output, speed);
else
{
speed *= -1;
RemoteSetOutputState(conn, output, speed, OUT_MODE_MOTORON+OUT_MODE_BRAKE, OUT_REGMODE_IDLE, 0, OUT_RUNSTATE_RUNNING, 0);
}
}
long MotorRotationCountAny(byte conn, byte output)
{
if (conn == CONN_BT0)
return MotorRotationCount(output);
else
{
OutputStateType params;
params.Port = output;
RemoteGetOutputState(conn, params);
return params.RotationCount;
}
}
task main()
{
byte len, cmd, cnt;
string name;
byte data[];
int mvolts;
#ifdef RS485
UseRS485();
RS485Initialize();
SetHSDataMode(DATA_MODE_NXT);
#endif
RemotePlayTone(theConn, TONE_A5, 1000);
until(RemoteConnectionIdle(theConn));
Wait(SEC_1);
RemoteGetCurrentProgramName(theConn, name);
TextOut(0, LCD_LINE4, name);
Wait(SEC_5);
ClearScreen();
RemoteGetContactCount(theConn, cnt);
NumOut(0, LCD_LINE4, cnt);
Wait(SEC_5);
ClearScreen();
RemoteGetConnectionCount(theConn, cnt);
NumOut(0, LCD_LINE4, cnt);
Wait(SEC_5);
ClearScreen();
RemoteGetBatteryLevel(theConn, mvolts);
NumOut(0, LCD_LINE4, mvolts);
Wait(SEC_5);
ClearScreen();
OutputStateType params;
params.Port = OUT_A;
while (true) {
ClearScreen();
if (RemoteGetOutputState(theConn, params) != NO_ERR)
break;
NumOut(0, LCD_LINE1, params.Power);
NumOut(0, LCD_LINE2, params.Mode);
NumOut(0, LCD_LINE3, params.RegMode);
NumOut(0, LCD_LINE4, params.TurnRatio);
NumOut(0, LCD_LINE5, params.RunState);
NumOut(0, LCD_LINE6, params.TachoLimit);
NumOut(0, LCD_LINE7, params.TachoCount);
NumOut(0, LCD_LINE8, params.RotationCount);
Wait(MS_50);
}
while (true) {
OnFwdAny(CONN_BT1, OUT_A, 75);
Wait(SEC_4);
OnRevAny(CONN_BT1, OUT_A, 75);
Wait(SEC_4);
OffAny(CONN_BT1, OUT_A);
Wait(SEC_1);
NumOut(0, LCD_LINE1, MotorRotationCountAny(CONN_BT1, OUT_A));
}
Stop(true);
}