Shop OBEX P1 Docs P2 Docs Learn Events
writing to sd card - Page 2 — Parallax Forums

writing to sd card

2»

Comments

  • claym53claym53 Posts: 36
    edited 2007-02-23 15:21
    Ok I have the variable to be written to the card set like this:

    int value = recbuf[noparse][[/noparse]k]+recbufA[noparse][[/noparse]k];

    What is happening is that it is adding the numbers and not putting them side by side...
    So I tried to use Concat... like this:

    int value = recbuf[noparse][[/noparse]k].concat(recbufA[noparse][[/noparse]k]);

    So value = 123456, not 579, but when I do this I get an error:

    'This type of expression,"int", is not a valid refrence type in this context.

    Please help
  • claym53claym53 Posts: 36
    edited 2007-02-23 15:35
    Here is the whole program I am working on... In case your curious I'm trying to get these arrays broken apart and put on the sd card, so I can then later read the data from the card and put it back into arrays...

    import stamp.core.*;
    import stamp.util.text.*;

    public class RecordPlay{


    final static int SERIAL_PIN = CPU.pin15;
    static Uart rxUart = new Uart( Uart.dirReceive, SERIAL_PIN, Uart.invert,Uart.speed19200,Uart.stop1 );

    static void main() {
    int[noparse]/noparse recbuf = new int[noparse][[/noparse]128]; //high periods
    int[noparse]/noparse recbufA = new int[noparse][[/noparse]128];

    CPU.writePin(CPU.pin2,false); //idle state output pin
    CPU.writePin(CPU.pin3,false);

    //record
    for (int i=0; i<128; i++) { //record 128 pulses
    recbuf = CPU.pulseIn(2350,CPU.pin0,true)+10; //record high period
    recbufA = CPU.pulseIn(2350,CPU.pin1,true)-10;
    CPU.pulseOut(recbuf,CPU.pin2); //high pulse out
    CPU.pulseOut(recbufA,CPU.pin3);
    System.out.println("record: "+recbuf+" - "+recbufA);
    CPU.delay(100); //wait 10msec 100
    }

    CPU.delay(10000); //wait some time
    Terminal.getChar();

    for (int i=0; i<128; i++) { //playback (on another pin)
    CPU.pulseOut(recbuf,CPU.pin2); //high pulse
    CPU.pulseOut(recbufA,CPU.pin3);
    System.out.println("play: "+recbuf+" - "+recbufA);
    CPU.delay(200); //wait 20msec 200
    }

    ////////////////// WRITE TO CARD
    int c;
    rxUart.setDirection(Uart.dirTransmit);
    rxUart.sendByte('!'); // wake up
    rxUart.sendByte('W');
    rxUart.sendByte('U');
    rxUart.sendByte('!'); // set pacing value
    rxUart.sendByte('P');
    rxUart.sendByte('V');
    rxUart.sendByte(30);
    while (!rxUart.sendBufferEmpty()) ; //wait until transmit buffer empty
    rxUart.setDirection(Uart.dirReceive);
    c = rxUart.receiveByte(); //get returned pacing
    if (c != 30) { //returned value invalid
    System.out.println("pacing set unsuccesful");
    while (true) ; //halt program
    }

    CPU.delay(2000);
    rxUart.setDirection(Uart.dirTransmit);
    rxUart.sendByte('!'); // attempt to close file
    rxUart.sendByte('C');
    rxUart.sendByte('F');
    while (!rxUart.sendBufferEmpty()) ; //wait until transmit buffer empty
    rxUart.setDirection(Uart.dirReceive);
    c = rxUart.receiveByte(); //get error code

    CPU.delay(2000);
    rxUart.setDirection(Uart.dirTransmit);
    rxUart.sendString("!OFDATA.TXT"); // attempt to open DATA.TXT
    while (!rxUart.sendBufferEmpty()) ; //wait until transmit buffer empty
    rxUart.setDirection(Uart.dirReceive);
    c = rxUart.receiveByte(); //get error code
    if (c!=0) {
    System.out.println("file not opened");
    while (true) ; //halt program
    }


    Format.printf("writing to card...");
    for (int k=0; k<128; k++) {
    CPU.delay(2000);
    char[noparse]/noparse buf = new char[noparse][[/noparse]11]; //holds sign + 5 decimals + CR + LF + closing null
    int value = recbuf[noparse][[/noparse]k]+recbufA[noparse][[/noparse]k];
    Format.sprintf(buf,"%d\r\n",value); //convert binary to ascii (8 bytes + null)
    rxUart.setDirection(Uart.dirTransmit);
    rxUart.sendByte('!');
    rxUart.sendByte('A');
    rxUart.sendByte('S');
    int i = 0;
    while (buf!=0) rxUart.sendByte(buf[noparse][[/noparse]i++]); //send string
    while (!rxUart.sendBufferEmpty()) ; //wait until transmit buffer empty
    // display response (if any)
    rxUart.setDirection(Uart.dirReceive);
    c = rxUart.receiveByte(); //get error code
    if (c!=0) {
    Format.printf("/n"+"appending string failed, errorcode %d\n",c);
    while (true) ; //halt program
    }
    }


    CPU.delay(2000);
    rxUart.setDirection(Uart.dirTransmit);
    rxUart.sendByte('!'); // attempt to close file
    rxUart.sendByte('C');
    rxUart.sendByte('F');
    while (!rxUart.sendBufferEmpty()) ; //wait until transmit buffer empty
    rxUart.setDirection(Uart.dirReceive);
    c = rxUart.receiveByte(); //get error code
    Format.printf("closed file, errorcode %d\n",c);
    while (true) ; //halt program
    }


    }
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-02-23 15:49
    int value· = (recbuf[noparse][[/noparse]k]<<8) | (recbufA[noparse][[/noparse]k]&0xFF);

    edit: note that this only works if recbuf[noparse][[/noparse]k] and recbufA[noparse][[/noparse]k] have values 0 to 255

    regards peter
  • claym53claym53 Posts: 36
    edited 2007-02-23 16:50
    Ok , I tried that:

    int[noparse]/noparse recbuf = new int[noparse][[/noparse]128];
    recbuf = 234;
    recbuf = 134;

    int value = (recbuf<<8) | (recbuf&0xFF);
    System.out.println(value);

    It prints the value as -5498, but I need it to be 234134
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-02-23 19:23
    If you need to print two values adjacent:
    System.out.print(recbuf[noparse][[/noparse]k]);
    System.out.println(recbufA[noparse][[/noparse]k]);

    To create a string
    char[noparse]/noparse buf = new char[noparse][[/noparse]13];
    int n = Format.bprintf(buf,0,"%05u",recbuf[noparse][[/noparse]k]);
    n = Format.bprintf(buf,n,"%05u\r\n",recbufA[noparse][[/noparse]k]);
    buf[noparse][[/noparse]n]=0;
    If recbuf[noparse][[/noparse]k] is 123 and recbufA[noparse][[/noparse]k] is 456 then
    buf is "0012300456",CR,LF,0

    I used %05u to print unsigned decimal values 00000-65535
    Without a fixed length of the values you won't be able to split
    the string at a later time. If you use %u then
    buf is "123456",CR,L,0

    regards peter
  • claym53claym53 Posts: 36
    edited 2007-02-28 14:56
    The code if have now, records 128 pulses from both channels, plays them back and then records them to data.txt on the sd card. The problem is, say I want to record pulses for like 15 minutes, that wouldn't work because that big of an array would cause the javelin to run out of memory and throw an error. So what I tried to do was as the pulse came in I would just try to write it to the file and not put it in the buffer array. The problem with this is that it takes to long to write to the card and then the pulse timing is off.

    So what I want to be able to do is something like this:

    while (CPU.pin10 = true) // while button is pressed record

    (record pulses and write to card)

    }


    Here is the code I have now:

    import stamp.core.*;
    import stamp.util.text.*;
    public class RecordPlay{

    final static int SERIAL_PIN = CPU.pin15;
    static Uart rxUart = new Uart( Uart.dirReceive, SERIAL_PIN, Uart.invert,Uart.speed19200,Uart.stop1 );
    static void main() {
    int[noparse]/noparse recbuf = new int[noparse][[/noparse]128]; //high periods
    int[noparse]/noparse recbufA = new int[noparse][[/noparse]128];
    CPU.writePin(CPU.pin2,false); //idle state output pin
    CPU.writePin(CPU.pin3,false);
    //record
    for (int i=0; i<128; i++) { //record 128 pulses
    recbuf[noparse][[/noparse]i] = CPU.pulseIn(2350,CPU.pin0,true)+10; //record high period
    recbufA[noparse][[/noparse]i] = CPU.pulseIn(2350,CPU.pin1,true)-10;
    CPU.pulseOut(recbuf[noparse][[/noparse]i],CPU.pin2); //high pulse out
    CPU.pulseOut(recbufA[noparse][[/noparse]i],CPU.pin3);
    System.out.println("record: "+recbuf[noparse][[/noparse]i]+" - "+recbufA[noparse][[/noparse]i]);
    CPU.delay(100); //wait 10msec·· 100
    }
    CPU.delay(10000); //wait some time
    Terminal.getChar();
    for (int i=0; i<128; i++) {··· //playback (on another pin)
    CPU.pulseOut(recbuf[noparse][[/noparse]i],CPU.pin2); //high pulse
    CPU.pulseOut(recbufA[noparse][[/noparse]i],CPU.pin3);
    System.out.println("play: "+recbuf[noparse][[/noparse]i]+" - "+recbufA[noparse][[/noparse]i]);
    CPU.delay(200); //wait 20msec 200
    }
    ////////////////// WRITE TO CARD
    int c;
    rxUart.setDirection(Uart.dirTransmit);
    rxUart.sendByte('!'); // wake up
    rxUart.sendByte('W');
    rxUart.sendByte('U');
    rxUart.sendByte('!'); // set pacing value
    rxUart.sendByte('P');
    rxUart.sendByte('V');
    rxUart.sendByte(30);
    while (!rxUart.sendBufferEmpty()) ; //wait until transmit buffer empty
    rxUart.setDirection(Uart.dirReceive);
    c = rxUart.receiveByte(); //get returned pacing
    if (c != 30) { //returned value invalid
    · System.out.println("pacing set unsuccesful");
    · while (true) ; //halt program
    }
    CPU.delay(2000);
    rxUart.setDirection(Uart.dirTransmit);
    rxUart.sendByte('!'); // attempt to close file
    rxUart.sendByte('C');
    rxUart.sendByte('F');
    while (!rxUart.sendBufferEmpty()) ; //wait until transmit buffer empty
    rxUart.setDirection(Uart.dirReceive);
    c = rxUart.receiveByte(); //get error code
    CPU.delay(2000);
    rxUart.setDirection(Uart.dirTransmit);
    rxUart.sendString("!OFDATA.TXT"); // attempt to open DATA.TXT
    while (!rxUart.sendBufferEmpty()) ; //wait until transmit buffer empty
    rxUart.setDirection(Uart.dirReceive);
    c = rxUart.receiveByte(); //get error code
    if (c!=0) {
    · System.out.println("file not opened");
    · while (true) ; //halt program
    }

    Format.printf("writing to card... \n");
    for (int k=0; k<128; k++) {
    CPU.delay(2000);
    char[noparse]/noparse buf = new char[noparse][[/noparse]13];
    int n = Format.bprintf(buf,0,"%u",recbuf[noparse][[/noparse]k]);
    n = Format.bprintf(buf,n,"%u\r\n",recbufA[noparse][[/noparse]k]);
    buf[noparse][[/noparse]n]=0;
    rxUart.setDirection(Uart.dirTransmit);
    rxUart.sendByte('!');
    rxUart.sendByte('A');
    rxUart.sendByte('S');
    int i = 0;
    while (buf[noparse][[/noparse]i]!=0) rxUart.sendByte(buf[noparse][[/noparse]i++]); //send string
    while (!rxUart.sendBufferEmpty()) ; //wait until transmit buffer empty
    // display response (if any)
    rxUart.setDirection(Uart.dirReceive);
    c = rxUart.receiveByte(); //get error code
    if (c!=0) {
    · Format.printf("appending string failed, errorcode %d\n",c);
    · while (true) ; //halt program
    }
    }

    CPU.delay(2000);
    rxUart.setDirection(Uart.dirTransmit);
    rxUart.sendByte('!'); // attempt to close file
    rxUart.sendByte('C');
    rxUart.sendByte('F');
    while (!rxUart.sendBufferEmpty()) ; //wait until transmit buffer empty
    rxUart.setDirection(Uart.dirReceive);
    c = rxUart.receiveByte(); //get error code
    Format.printf("closed file, errorcode %d\n",c);
    while (true) ; //halt program
    }

    }

    Post Edited (claym53) : 2/28/2007 6:50:27 PM GMT
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-03-03 11:07
    You can save 50% of ram used by the arrays, by defining them as char arrays.
    Because the pulses are servo pulses, their high periods are 1 to 2 msec.
    This corresponds to 115 to 230 ticks of 8.68usec.
    recbuf[noparse][[/noparse]i] = (char)CPU.pulseIn(2350,CPU.pin0,true)+10; //record high period
    This decreases also the time to store the value since only 1 byte is stored.
    Note that the special values -1 and 0 of the pulseIn() are stored as 255 and 0,
    so these do not interfere with normal pulse values.

    You can record approx. 4 minutes that way.
    2 channels * 50 pulses/sec = 100 pulses/sec = 100 bytes/sec
    4 minutes = 240 secs = 240*100 bytes = 24kBytes
    That still leaves you 8kBytes for code.

    regards peter
  • claym53claym53 Posts: 36
    edited 2007-03-07 02:39
    Do I also need to declare my arrays as char when I declare them?

    int[noparse]/noparse recbuf = new int[noparse][[/noparse]128]; //high periods
    int[noparse]/noparse recbufA = new int[noparse][[/noparse]128];

    I tried this:

    char[noparse]/noparse recbuf = new char[noparse][[/noparse]128]; //high periods
    char[noparse]/noparse recbufA = new char[noparse][[/noparse]128];

    But I get errors...
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-03-07 02:49
    When you declare the arrays as char arrays,
    you must cast the pulsIn result to char.

    static void main() {
    char[noparse]/noparse recbuf = new char[noparse][[/noparse]128]; //high periods
    char[noparse]/noparse recbufA = new char[noparse][[/noparse]128];
    CPU.writePin(CPU.pin2,false); //idle state output pin
    CPU.writePin(CPU.pin3,false);
    //record
    for (int i=0; i<128; i++) { //record 128 pulses
    recbuf[noparse][[/noparse]i] = (char)(CPU.pulseIn(2350,CPU.pin0,true)+10); //record high period
    recbufA[noparse][[/noparse]i] = (char)(CPU.pulseIn(2350,CPU.pin1,true)-10);
    CPU.pulseOut(recbuf[noparse][[/noparse]i]&0xFF,CPU.pin2); //high pulse out
    CPU.pulseOut(recbufA[noparse][[/noparse]i]&0xFF,CPU.pin3);
    System.out.println("record: "+recbuf[noparse][[/noparse]i]+" - "+recbufA[noparse][[/noparse]i]);
    CPU.delay(100); //wait 10msec·· 100
    }
    CPU.delay(10000); //wait some time
    Terminal.getChar();
    for (int i=0; i<128; i++) {··· //playback (on another pin)
    CPU.pulseOut(recbuf[noparse][[/noparse]i]&0xFF,CPU.pin2); //high pulse
    CPU.pulseOut(recbufA[noparse][[/noparse]i]&0xFF,CPU.pin3);
    System.out.println("play: "+recbuf[noparse][[/noparse]i]+" - "+recbufA[noparse][[/noparse]i]);
    CPU.delay(200); //wait 20msec 200
    }

    regards peter
  • claym53claym53 Posts: 36
    edited 2007-03-07 03:17
    I got this:

    "Error: Type java/lang/Character was not found"

    Is there a library I need to include or something? and if so where do I get it?
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-03-07 03:26
    Type char is a builtin type, just like int.
    Are you sure you used char, and not Char or Character?

    Also check your classpath
    Menu Project->Global options
    If you installed the Javelin IDE in the default directory, you should have
    c:\program files\Parallax inc\Javelin Stamp IDE\lib;
    If not, browse to this directory using the button on the right.

    regards peter
  • claym53claym53 Posts: 36
    edited 2007-03-07 03:37
    Yes, I used char not Char or Character and the classpath is correct.
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-03-07 03:49
    Can you post your program
    as an attachment?

    regards peter
  • claym53claym53 Posts: 36
    edited 2007-03-07 03:51
    My classpath is set to this:
    C:\Program Files\Parallax Inc\Javelin Stamp IDE\lib;C:\Program Files\Parallax Inc\Javelin Stamp IDE\Projects

    and my full code is this:

    import stamp.core.*;
    import stamp.util.text.*;

    public class RecordPlay{

    final static int SERIAL_PIN = CPU.pin15;
    static Uart rxUart = new Uart( Uart.dirReceive, SERIAL_PIN, Uart.invert,Uart.speed19200,Uart.stop1 );
    static void main() {
    char[noparse]/noparse recbuf = new char[noparse][[/noparse]128]; //high periods
    char[noparse]/noparse recbufA = new char[noparse][[/noparse]128];
    CPU.writePin(CPU.pin2,false); //idle state output pin
    CPU.writePin(CPU.pin3,false);
    //record
    for (int i=0; i<128; i++) { //record 128 pulses
    recbuf = (char)(CPU.pulseIn(2350,CPU.pin0,true)+10); //record high period
    recbufA = (char)(CPU.pulseIn(2350,CPU.pin1,true)-10);
    CPU.pulseOut(recbuf&0xFF,CPU.pin2); //high pulse out
    CPU.pulseOut(recbufA&0xFF,CPU.pin3);
    System.out.println("record: "+recbuf+" - "+recbufA);
    CPU.delay(100); //wait 10msec 100
    }
    CPU.delay(10000); //wait some time
    Terminal.getChar();
    for (int i=0; i<128; i++) { //playback (on another pin)
    CPU.pulseOut(recbuf&0xFF,CPU.pin2); //high pulse
    CPU.pulseOut(recbufA&0xFF,CPU.pin3);
    System.out.println("play: "+recbuf+" - "+recbufA);
    CPU.delay(200); //wait 20msec 200
    }
    ////////////////// WRITE TO CARD
    int c;
    rxUart.setDirection(Uart.dirTransmit);
    rxUart.sendByte('!'); // wake up
    rxUart.sendByte('W');
    rxUart.sendByte('U');
    rxUart.sendByte('!'); // set pacing value
    rxUart.sendByte('P');
    rxUart.sendByte('V');
    rxUart.sendByte(30);
    while (!rxUart.sendBufferEmpty()) ; //wait until transmit buffer empty
    rxUart.setDirection(Uart.dirReceive);
    c = rxUart.receiveByte(); //get returned pacing
    if (c != 30) { //returned value invalid
    System.out.println("pacing set unsuccesful");
    while (true) ; //halt program
    }
    CPU.delay(2000);
    rxUart.setDirection(Uart.dirTransmit);
    rxUart.sendByte('!'); // attempt to close file
    rxUart.sendByte('C');
    rxUart.sendByte('F');
    while (!rxUart.sendBufferEmpty()) ; //wait until transmit buffer empty
    rxUart.setDirection(Uart.dirReceive);
    c = rxUart.receiveByte(); //get error code
    CPU.delay(2000);
    rxUart.setDirection(Uart.dirTransmit);
    rxUart.sendString("!OFDATA.TXT"); // attempt to open DATA.TXT
    while (!rxUart.sendBufferEmpty()) ; //wait until transmit buffer empty
    rxUart.setDirection(Uart.dirReceive);
    c = rxUart.receiveByte(); //get error code
    if (c!=0) {
    System.out.println("file not opened");
    while (true) ; //halt program
    }

    Format.printf("writing to card... \n");
    for (int k=0; k<128; k++) {
    CPU.delay(2000);
    char[noparse]/noparse buf = new char[noparse][[/noparse]13];
    int n = Format.bprintf(buf,0,"%u",recbuf[noparse][[/noparse]k]);
    n = Format.bprintf(buf,n,"%u\r\n",recbufA[noparse][[/noparse]k]);
    buf[noparse][[/noparse]n]=0;
    rxUart.setDirection(Uart.dirTransmit);
    rxUart.sendByte('!');
    rxUart.sendByte('A');
    rxUart.sendByte('S');
    int i = 0;
    while (buf!=0) rxUart.sendByte(buf[noparse][[/noparse]i++]); //send string
    while (!rxUart.sendBufferEmpty()) ; //wait until transmit buffer empty
    // display response (if any)
    rxUart.setDirection(Uart.dirReceive);
    c = rxUart.receiveByte(); //get error code
    if (c!=0) {
    Format.printf("appending string failed, errorcode %d\n",c);
    while (true) ; //halt program
    }
    }

    CPU.delay(2000);
    rxUart.setDirection(Uart.dirTransmit);
    rxUart.sendByte('!'); // attempt to close file
    rxUart.sendByte('C');
    rxUart.sendByte('F');
    while (!rxUart.sendBufferEmpty()) ; //wait until transmit buffer empty
    rxUart.setDirection(Uart.dirReceive);
    c = rxUart.receiveByte(); //get error code
    Format.printf("closed file, errorcode %d\n",c);
    while (true) ; //halt program
    }

    }

    and I'm still getting that error and still confused as to why?

    maybee importing the stamp.util.text.* is conflicting with char?
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-03-07 04:09
    The error is caused by the lines
    System.out.println("record: "+recbuf+" - "+recbufA);
    and
    System.out.println("play: "+recbuf+" - "+recbufA);

    Change them to
    System.out.print("record: ");
    System.out.print(recbuf[noparse][[/noparse]i]&0xFF);
    System.out.print(" - ");
    System.out.println(recbufA[noparse][[/noparse]i]&0xFF);
    and
    System.out.print("play: ");
    System.out.print(recbuf[noparse][[/noparse]i]&0xFF);
    System.out.print(" - ");
    System.out.println(recbufA[noparse][[/noparse]i]&0xFF);

    regards peter
  • claym53claym53 Posts: 36
    edited 2007-03-07 15:14
    Ok now this code:

    import stamp.core.*;
    import stamp.util.text.*;
    public class RecordPlay{
    final static int SERIAL_PIN = CPU.pin15;
    static Uart rxUart = new Uart( Uart.dirReceive, SERIAL_PIN, Uart.invert,Uart.speed19200,Uart.stop1 );
    static void main() {
    char[noparse]/noparse recbuf = new char[noparse][[/noparse]128]; //high periods
    char[noparse]/noparse recbufA = new char[noparse][[/noparse]128];
    CPU.writePin(CPU.pin2,false); //idle state output pin
    CPU.writePin(CPU.pin3,false);
    //record
    for (int i=0; i<128; i++) { //record 128 pulses
    recbuf = (char)(CPU.pulseIn(2350,CPU.pin0,true)+10); //record high period
    recbufA = (char)(CPU.pulseIn(2350,CPU.pin1,true)-10);
    CPU.pulseOut(recbuf&0xFF,CPU.pin2); //high pulse out
    CPU.pulseOut(recbufA&0xFF,CPU.pin3);
    System.out.print("record: ");
    System.out.print(recbuf[noparse][[/noparse]i]&0xFF);
    System.out.print(" - ");
    System.out.println(recbufA[noparse][[/noparse]i]&0xFF);
    CPU.delay(100); //wait 10msec 100
    }
    CPU.delay(10000); //wait some time
    Terminal.getChar();
    for (int i=0; i<128; i++) { //playback (on another pin)
    CPU.pulseOut(recbuf&0xFF,CPU.pin2); //high pulse
    CPU.pulseOut(recbufA&0xFF,CPU.pin3);
    System.out.print("play: ");
    System.out.print(recbuf[noparse][[/noparse]i]&0xFF);
    System.out.print(" - ");
    System.out.println(recbufA[noparse][[/noparse]i]&0xFF);
    CPU.delay(200); //wait 20msec 200
    }
    ////////////////// WRITE TO CARD
    int c;
    rxUart.setDirection(Uart.dirTransmit);
    rxUart.sendByte('!'); // wake up
    rxUart.sendByte('W');
    rxUart.sendByte('U');
    rxUart.sendByte('!'); // set pacing value
    rxUart.sendByte('P');
    rxUart.sendByte('V');
    rxUart.sendByte(30);
    while (!rxUart.sendBufferEmpty()) ; //wait until transmit buffer empty
    rxUart.setDirection(Uart.dirReceive);
    c = rxUart.receiveByte(); //get returned pacing
    if (c != 30) { //returned value invalid
    System.out.println("pacing set unsuccesful");
    while (true) ; //halt program
    }
    CPU.delay(2000);
    rxUart.setDirection(Uart.dirTransmit);
    rxUart.sendByte('!'); // attempt to close file
    rxUart.sendByte('C');
    rxUart.sendByte('F');
    while (!rxUart.sendBufferEmpty()) ; //wait until transmit buffer empty
    rxUart.setDirection(Uart.dirReceive);
    c = rxUart.receiveByte(); //get error code
    CPU.delay(2000);
    rxUart.setDirection(Uart.dirTransmit);
    rxUart.sendString("!OFDATA.TXT"); // attempt to open DATA.TXT
    while (!rxUart.sendBufferEmpty()) ; //wait until transmit buffer empty
    rxUart.setDirection(Uart.dirReceive);
    c = rxUart.receiveByte(); //get error code
    if (c!=0) {
    System.out.println("file not opened");
    while (true) ; //halt program
    }
    Format.printf("writing to card... \n");
    for (int k=0; k<128; k++) {
    CPU.delay(2000);
    char[noparse]/noparse buf = new char[noparse][[/noparse]13];
    int n = Format.bprintf(buf,0,"%u",recbuf[noparse][[/noparse]k]);
    n = Format.bprintf(buf,n,"%u\r\n",recbufA[noparse][[/noparse]k]);
    buf[noparse][[/noparse]n]=0;
    rxUart.setDirection(Uart.dirTransmit);
    rxUart.sendByte('!');
    rxUart.sendByte('A');
    rxUart.sendByte('S');
    int i = 0;
    while (buf!=0) rxUart.sendByte(buf[noparse][[/noparse]i++]); //send string
    while (!rxUart.sendBufferEmpty()) ; //wait until transmit buffer empty
    // display response (if any)
    rxUart.setDirection(Uart.dirReceive);
    c = rxUart.receiveByte(); //get error code
    if (c!=0) {
    Format.printf("appending string failed, errorcode %d\n",c);
    while (true) ; //halt program
    }
    }
    CPU.delay(2000);
    rxUart.setDirection(Uart.dirTransmit);
    rxUart.sendByte('!'); // attempt to close file
    rxUart.sendByte('C');
    rxUart.sendByte('F');
    while (!rxUart.sendBufferEmpty()) ; //wait until transmit buffer empty
    rxUart.setDirection(Uart.dirReceive);
    c = rxUart.receiveByte(); //get error code
    Format.printf("closed file, errorcode %d\n",c);
    while (true) ; //halt program
    }
    }

    and here is a screenshot of my errors:

    http://www.carefulconsumer.com/errors.bmp
    ·
  • claym53claym53 Posts: 36
    edited 2007-03-07 15:21
    Ok nevermind, after the recbuf and recbufA needed to be recbuf and recbufA....
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-03-07 15:29
    You did leave out the array indices for recbuf,recbufA and buf.
    The attachement compiles without error.

    regards peter
Sign In or Register to comment.