Page 1 of 2

Error: ';' expected! GRRR!

Posted: 15 Dec 2010, 02:51
by jojoguy14
Hey there everyone!

I'm trying to figure out the new Bricxcc 3.3.8.8 version with the new RS-485 communication controls. here's my code:

Code: Select all

task main();
     OnFwd(CONN_HS4, OUT_A, 50);
     Wait(SEC_1);
     Off(CONN_HS4, OUT_A);
But, when I compile it, there are 3 errors on lines 2,3 and 4 saying that a ";" was expected. but, don't I already have those at the end of each line???

jojoguy10

Re: Error: ';' expected! GRRR!

Posted: 15 Dec 2010, 03:23
by m-goldberg
The line "task main()" should not be terminated with ;

The other three lines of code should be surrounded with { ... }.

Re: Error: ';' expected! GRRR!

Posted: 15 Dec 2010, 03:49
by jojoguy14
You mean like this?

Code: Select all

task main()
    { 
     OnFwd(CONN_HS4, OUT_A, 50);
     Wait(SEC_1);
     Off(CONN_HS4, OUT_A);
     }

Re: Error: ';' expected! GRRR!

Posted: 15 Dec 2010, 04:09
by mattallen37
Like that, only typically, white space would be more like this.

Code: Select all

task main()
{
  OnFwd(CONN_HS4, OUT_A, 50);
  Wait(SEC_1);
  Off(CONN_HS4, OUT_A);
}

Re: Error: ';' expected! GRRR!

Posted: 15 Dec 2010, 07:04
by muntoo
mattallen37 wrote:Like that, only typically, white space would be more like this.

Code: Select all

task main()
{
  OnFwd(CONN_HS4, OUT_A, 50);
  Wait(SEC_1);
  Off(CONN_HS4, OUT_A);
}
Actually, there's lots of different coding styles, but I prefer this:

Code: Select all

class Animal
{
public:
    string name;
};

task main()
{
    Animal robot;
    robot.name = "Marvin";
    NumOut(0, 8, 6 * 9, 0);
    NumOut(0, 0, 42, 0);
    Wait(1000);
}
Also, I indent using tabs with width of 4 spaces.

Re: Error: ';' expected! GRRR!

Posted: 15 Dec 2010, 13:01
by jojoguy14
Sorry about all of this, I'm a noobie at Bricxcc. Anyway, I tried that, Mattallen, but it shows new errors:
Line 3: Error: ')' expected
Line 3: Error: ';' expected
Line 4: Unmatched close parenthesis
Line 4: Error: ';' expected
Line 5: Unmatched close parenthesis
Line 5: Error: ')' expected
Line 5: Error: ';' expected

Code: Select all

task main()
{
  OnFwd(CONN_HS4, OUT_A, 50);
  Wait(SEC_1);
  Off(CONN_HS4, OUT_A);
}
So...could this just be a bug? Maybe?

jojoguy10

Re: Error: ';' expected! GRRR!

Posted: 15 Dec 2010, 13:15
by HaWe
I tried my very latest published version (Bricxcc 3.3.8.8 plus test_release20101103.zip 03-Nov-2010 13:52)
but there is no such syntax supported yet, nor is a help implemented for RS485 direct control.

Maybe at Xmas?

Re: Error: ';' expected! GRRR!

Posted: 15 Dec 2010, 14:20
by jojoguy14
Hmmm... weird. I thought he said that in the new 3.3.8.8 release he added RS-485 control. OK, well, thanks!

jojoguy10

Re: Error: ';' expected! GRRR!

Posted: 15 Dec 2010, 17:14
by afanofosc
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);
  
}

Re: Error: ';' expected! GRRR!

Posted: 15 Dec 2010, 18:08
by mattallen37
muntoo wrote:Actually, there's lots of different coding styles, but I prefer this:
...
Also, I indent using tabs with width of 4 spaces.
Well, as you say, there are many different ways of using white space. When I program in BASIC, I only indent one space, but in NXC and NQC, I indent two spaces. I also use tab, but I have it set to 2 spaces.
jojoguy14 wrote:... So...could this just be a bug? Maybe?
Well, I didn't compile the code, I was just mentioning the whole thing with white space. I honestly doubted that it would compile, seeing an extra parameter in the OnFwd and Off commands.

Don't start using NXC with anything related to RS485. Start by making simple programs, and grow from them. The "NXC_tutorial" is a great place to start. In it, you can learn a TON about using NXC (through practice), but also a lot about syntax, white space, and fixing errors that cause compiler errors.