ROBOTC.net forums
http://www.robotc.net/forums/

Help with Irlink sensor and HTRCXReadResp()
http://www.robotc.net/forums/viewtopic.php?f=41&t=4569
Page 1 of 1

Author:  cheechr1 [ Mon May 21, 2012 10:09 pm ]
Post subject:  Help with Irlink sensor and HTRCXReadResp()

Hi. Im having a hard time getting my program to compile using this command. Example:

#pragma config(Sensor, S1, HTRCX, sensorI2CCustom)

#include "HTRCX-driver.h"
int rcxmessage[0];
bool rcxmessagesuccess = 0;
task main ()
{
while (1==1)
{
if (HTRCXreadResp(HTRCX, rcxmessage,rcxmessagesuccess ) != 0)
{
rcxmessage = HTRCXreadResp(HTRCX, rcxmessage,rcxmessagesuccess);

eraseDisplay();

nxtDisplayString(3, "RCX: %d", rcxmessage);
}
}
}

Can someone please tell me the proper way to use this command? Thanks.

Author:  NeXT-Generation [ Mon May 21, 2012 10:38 pm ]
Post subject:  Re: Help with Irlink sensor and HTRCXReadResp()

You want to display the message received from the RCX, right? I think that this code will accomplish that:
Code:
#pragma config(Sensor, S1, HTRCX, sensorI2CCustom)

#include "drivers/HTRCX-driver.h"
unsigned byte rcxmessage[1];
task main ()
{
  while (1==1)
  {
    HTRCXreadResp(HTRCX, rcxmessage[0]);
   
    if (rcxmessage[0] != 0)
    {
      eraseDisplay();

      nxtDisplayString(3, "RCX: %d", rcxmessage);
    }
  }
}
(Please put your code in the
Code:
[code][/code]
tags next time.)

I'm not positive, but I think this should work. I've never used the IRLink with the RCX in RobotC before.

Author:  mightor [ Tue May 22, 2012 12:17 am ]
Post subject:  Re: Help with Irlink sensor and HTRCXReadResp()

Try this code:
Code:
#pragma config(Sensor, S1, HTRCX, sensorI2CCustom)

#include "drivers/HTRCX-driver.h"
tByteArray rcxmessage;

task main ()
{
  while (1==1)
  {
    if (HTRCXreadResp(HTRCX, rcxmessage))
    {
      eraseDisplay();
      nxtDisplayString(3, "RCX: %d", rcxmessage[0]);
    }
  }
}


Please note that HTRCXreadResp() is flaky at the best of times and dumps the whole register, so be sure to check more than just rcxmessage[0]. I never got it working reliably as a means to read something from the RCX. The buffer will be overwritten in the sensor whenever something new comes along. It's a real pain in the butt.

- Xander

Author:  cheechr1 [ Tue May 22, 2012 1:08 am ]
Post subject:  Re: Help with Irlink sensor and HTRCXReadResp()

Thanks guys I knew it was something simple. Ill report back on how I make out with this.

Author:  cheechr1 [ Tue May 22, 2012 4:22 am ]
Post subject:  Re: Help with Irlink sensor and HTRCXReadResp()

No problem sending to the RCX but receiving, as far as I can tell, is a no go.

Author:  NeXT-Generation [ Tue May 22, 2012 8:56 am ]
Post subject:  Re: Help with Irlink sensor and HTRCXReadResp()

Did you try what Xander said and read the whole register? You can use a "for()" loop for that instead of typing out the display command 8 times.

Author:  cheechr1 [ Tue May 22, 2012 1:20 pm ]
Post subject:  Re: Help with Irlink sensor and HTRCXReadResp()

Im sorry im no programming expert, I use Robot C because NXT-G is almost unusable. I really dont know what you mean by "the whole register". Ill show you what I tried..
NXT Program:

Code:
#include "drivers/HTRCX-driver.h"
unsigned byte rcxmessage[1];
task main ()
{
  while (1==1)
  {
    HTRCXreadResp(HTRCX, rcxmessage[0]);
   
    if (rcxmessage[0] != 0)
    {
      eraseDisplay();

      nxtDisplayString(3, "RCX: %d", rcxmessage);
    }
  }
}


RCX Program:

Code:
task main()

{
  while (1==1)
  {
    sendMessageWithParm(2);
    wait10Msec(1000);
    sendMessageWithParm(3);
  }
}


So far I am finding Robot C to be a great programming environment for the NXT its just when it comes to hex things and registers I become lost. Thanks for all the help and if you can think of any online sources where I could read on this a bit more I would be most grateful. Thanks again!

Note: I am using Robot C 3.08 for the NXT and 2.03 for the RCX

Author:  elibm [ Sun Oct 06, 2013 5:25 pm ]
Post subject:  Re: Help with Irlink sensor and HTRCXReadResp()

Hi ,
following Xander indications,
I managed to send some commands from my RCX 2.0 to my NXT using the IRLink sensor.
I receive garbage on the NXT most of the times.
Then How can we know when the NXT has received the right data, and when can we read it ??
Well, I found a pattern that helps me to filter the data received by the NXT.
Here is the code.

if (HTRCXreadResp(HTRCX, rcxmessage))
{
if (rcxmessage[1] == 247 && rcxmessage[2]==8 && rcxmessage[3] != 147 ){
data = rcxmessage[3];
nxtDisplayString(1,"RCX sent: %d ",rcxmessage[3]);
}else if (rcxmessage[2] == 8) {
data = rcxmessage[3];
nxtDisplayString(1,"RCX sent: %d ",rcxmessage[3]);
}else if (rcxmessage[1] == 8 && rcxmessage[2] != 247) {
dato = rcxmessage[2];
nxtDisplayString(1,"RCX sent: %d ",rcxmessage[2]);
}
}

Hope you can find it useful.
Here are some videos that show how it works ...

http://www.youtube.com/watch?v=jF5_3Y_G4P0
http://www.youtube.com/watch?v=6RtNWyx-9_Q


Best regards.
Elias.

Author:  elibm [ Sun Oct 06, 2013 5:28 pm ]
Post subject:  Re: Help with Irlink sensor and HTRCXReadResp()

well, the yellow face with sun glasses , should be number "8)"
Some how the string "8)" has been replaced by that smilie

Author:  roboRed [ Sat Oct 19, 2013 1:14 pm ]
Post subject:  Re: Help with Irlink sensor and HTRCXReadResp()

NeXT-Generation wrote:
You want to display the message received from the RCX, right? I think that this code will accomplish that:
Code:
    HTRCXreadResp(HTRCX, rcxmessage[0]);
(Please put your code in the
Code:
[code][/code]
tags next time.)

I'm not positive, but I think this should work. I've never used the IRLink with the RCX in RobotC before.

So the "HTRCX" command prefix designates talking to a rcx via an infrared link? :?

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/