To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.nqcOpen lugnet.robotics.rcx.nqc in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / NQC / 1538
1537  |  1539
Subject: 
Re: write files2
Newsgroups: 
lugnet.robotics.rcx.nqc
Date: 
Thu, 2 Oct 2003 14:44:32 GMT
Viewed: 
5205 times
  
In lugnet.robotics.rcx.nqc, Markus Wegmann wrote:
the rcx is always connected with the PC.
now i have a lightsensor and i want to
save the results of the lightsensor every 2 seconds
to my log.txt file ;)

What is the best and easyiest way to do that?

You probably do not want to use the datalog if you just want to get the latest
lightsensor reading every two seconds.

Here's a way to do it if you can use JavaScript and if you have BricxCC
installed (since BricxCC implements an out-of-process COM server):

// RCXType
rtRCX = 0;
rtCybermaster = 1;
rtScout = 2;
rtRCX2 = 3;
rtSpy = 4;

//  PortNum
pnCOM1 = 1;
pnCOM2 = 2;
pnCOM3 = 3;
pnCOM4 = 4;
pnUSB1 = 9;

var x = new ActiveXObject('BricxCC.BricxCCSpirit');

x.RCXType = rtRCX2;
x.PortNum = pnUSB1;

var f = new ActiveXObject('Scripting.FileSystemObject');
var s = f.CreateTextFile('output.txt');

if (x.Open())
{
  // read sensor value every 2 seconds (10 times)
  for (i = 0; i < 10; i++)
  {
    var value = x.GetInputValue(0);
    s.WriteLine(value);
    sleep(2000);
  }


  x.Close();
}
else
{
  s.WriteLine("unable to open RCX");
}

function sleep(ms)
{
  var then = new Date().getTime();
  var now = then;
  while ((now-then) < ms)
    now = new Date().getTime();
}


An alternative would be to use nqc:

nqc -Susb -raw 120900

This means poll (0x12) the value of input (0x09) number 0 (0x00).  You'll get
back two hex bytes (something like FD 03 ).  You can do the same for other
things:

120000 -- 120031 = poll variable values
120300 -- 120302 = poll motor status values
121500 -- 121502 = poll counter values
120100 -- 120103 = poll timer values
120F00 = poll the message value

Or you can use my RCXTool:

RCXTool /COM=9 -raw=120900

Same thing.

Or you can use the brand new version of RCXTool
(http://members.aol.com/johnbinder/rcxtool.zip) which has some new features:

   -input=<N> : read input N (0-2)
   -output=<N> : read the status of output N (0-2)
   -var=<N> : read the value of variable N (0-31)
   -timer=<N> : read the value of timer N (0-3)
   -counter=<N> : read the value of timer N (0-2)
   -msgVal : read the current message
   -incCounter=N : increment counter N
   -decCounter=N : increment counter N

RCXTool /COM=9 -input=0

This will output the value in a more traditional fashion:

RCXTool /COM=9 /RCX=3 -input=1
1021

Hope this helps.

John Hansen
http://members.aol.com/johnbinder/bricxcc.htm



Message is in Reply To:
  write files2
 
thx for your answers. let me specify the problem better: the rcx is always connected with the PC. now i have a lightsensor and i want to save the results of the lightsensor every 2 seconds to my log.txt file ;) What is the best and easyiest way to (...) (21 years ago, 1-Oct-03, to lugnet.robotics.rcx.nqc)

5 Messages in This Thread:



Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR