Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7016469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:47:21+00:00 2026-05-27T22:47:21+00:00

Edit – here are some resources in response to comments: costate: http://bamafolks.com/randy/students/embedded/dynamicC_mtask.html writeUserBlockArray: http://ftp1.digi.com/support/documentation/html/DynCFunctionReference/12fun595.htm#1259708

  • 0

Edit – here are some resources in response to comments:

costate: http://bamafolks.com/randy/students/embedded/dynamicC_mtask.html

writeUserBlockArray: http://ftp1.digi.com/support/documentation/html/DynCFunctionReference/12fun595.htm#1259708

The error I am getting is `-1: Invalid address or range’.

#define MAX_SAMPLES 20
#define REPORT_AFTER 3

main()
{
    int i;
    int report;

    int write_result;
    int read_result;

    struct temp_struct {
        float celcius;
        float fahrenheit;
    } temperature_data;

    struct temp_struct save_data[MAX_SAMPLES];
    struct temp_struct read_data[MAX_SAMPLES];
    unsigned int save_lens[MAX_SAMPLES];

    float *pTempC, *pTempF;

    pTempC = &temperature_data.celcius;
    pTempF = &temperature_data.fahrenheit;

    i = 0;
    report = 0;

    brdInit();

    while(1)
    {
       costate
       {
           sampleTemp(&temperature_data.celcius, &temperature_data.fahrenheit);

           save_data[i].celcius = *pTempC;
           save_data[i].fahrenheit = *pTempF;
           save_lens[i] = sizeof(temperature_data);

           if(i==MAX_SAMPLES) i=0; else i++;
           report=1; // Sample has been taken, a report can be produced
           waitfor(DelaySec(SAMPLE_DELAY_SECS));
       }

       // If REPORT_AFTER set to 3, this executed every third sample taken.
       // "report" the last set of data saved by printing out
       if(report && i%REPORT_AFTER==0 && i!=0)
       {
          write_result = writeUserBlockArray(i-REPORT_AFTER, save_data, save_lens, REPORT_AFTER);
          // Read data to check it was saved correctly
          read_result = readUserBlockArray(read_data, save_lens, REPORT_AFTER, i-REPORT_AFTER);

          // Print out all data saved here.

          report = 0; // Do not report again until another sample has been taken.
          break; // Stops after first report. Can be removed later
       } // end if
    } // end while
} // end main

float sampleTemp(float *tempC, float *tempF)
{
   auto float  Tk,      //calculated temperature kelvins
                    Draw;       //raw data value
   auto int i;

   printf("Getting temperature\n\n");

   Draw = anaIn(7, SINGLE, GAIN_1);

   //calculate temperature in kelvins
   Tk = (Bt*Tkstd) / ( Tkstd * ( log( fabs( (-Draw*Rs) / (Rtstd*(Draw-(Dmax*Gain))) ) ) ) + Bt );

   *tempC = Tk - 273.15;                //convert to celcius
   *tempF = 1.8*(Tk - 255.37);      //calculate fahrenheit

   return 0;
}

This is all relevant code. I am consistently getting -1 returned from the writeUserBlockArray() method which symbolises an invalid address or range.

I don’t think the fact that it is Dynamic-C makes much difference but the offending method’s outline is this:

writeUserBlockArray(addrOffset, arraySources, arraySourceSizes, numSources);

I am new to C and I think I am doing something wrong with the way I am saving the data to the array?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:47:22+00:00Added an answer on May 27, 2026 at 10:47 pm

    The problem was that I was trying to write an array of data to the memory. The actual way of using the writeUserBlockArray(…) method is to specify an array of pointers.

    New, working, code:

    #define SAMPLE_DELAY_SECS 5
    #define MAX_SAMPLES 20
    #define REPORT_AFTER 3
    
    main()
    {
       int temp;
    
       int i; // Iteration #
       int report; // Whether to produce a report or not
    
       int write_result; // The numerical result of the write-to-memory operation
       int read_result; // The numerical result of the read-from-memory operation
    
       // Define a structure which can be used to hold both temperature measurements
       struct temp_struct {
            float celcius;
          float fahrenheit;
       } temperature_data;
    
       void *save_pointers[MAX_SAMPLES]; // An array of pointers pointing to the data to be saved in memory
       struct temp_struct save_data[MAX_SAMPLES]; // Array of actual data which can be loaded with the read operation
       unsigned int save_lens[MAX_SAMPLES]; // An array of the size (in bytes) of each element in the save_data array
    
       i = 0;
       report = 0;
    
       brdInit(); // Needs to be called before any operations are performed with the hardware.
    
       while(1)
       {
          /*
           * Costate is a way of multitasking in Dynamic-C. By using a costate block in
           * conjunction with the waitfor keyword, the block can be paused until it
           * has finished waiting.
           *
           * Further info:
           * http://bamafolks.com/randy/students/embedded/dynamicC_mtask.html
           */
          costate
          {
            // Method taken from: http://read.pudn.com/downloads107/sourcecode/embed/441399/Samples/RCM3700/Tcpip/RabbitWeb/TEMPERATURE.C__.htm
            sampleTemp(&temperature_data.celcius, &temperature_data.fahrenheit);
    
            save_pointers[i] = &temperature_data;
            save_lens[i] = sizeof(temperature_data);
    
            printf("save_data[%d].celcius is %f\n", i, save_data[i].celcius);
            printf("save_data[%d].fahrenheit is %f\n\n", i, save_data[i].fahrenheit);
    
            if(i==MAX_SAMPLES) i = 0; else i++;
    
            report=1; // Sample has been taken, a report can be produced
            waitfor(DelaySec(SAMPLE_DELAY_SECS));
          }
    
          /*
           * This IF block is used to produce a report every so often, either by
           * emailing out some data, updating the web interface or simply printing
           * it to the screen.
           *
           * A report will be produced when:
           *   a) a new sample has been taken (report)
           *   b) the desired number of samples has been reached (i%REPORT_AFTER==0)
           *   c) it is not the very first sample to be taken (i!=0)
           */
          if(report && i%REPORT_AFTER==0 && i!=0) // For every third sample
          {
             /*
              * writeUserBlockArray(address_offset (unsigned int),
              *             sources (array),
              *             source_sizes (array),
              *             num_sources (int));
              * Documentation:
              * http://ftp1.digi.com/support/documentation/html/DynCFunctionReference/12fun595.htm#1259708
              */
             write_result = writeUserBlockArray(i-REPORT_AFTER, save_pointers, save_lens, REPORT_AFTER);
    
             /*
              * readUserBlockArray(destinations (array),
              *            destination_sizes (array),
              *            num_sources (int),
              *            address_offset (unsigned int));
              * Documentation:
              * http://ftp1.digi.com/support/documentation/html/DynCFunctionReference/12fun441.htm#1259907
              */
             read_result = readUserBlockArray(save_data, save_lens, REPORT_AFTER, i-REPORT_AFTER);
    
             printf("Write Result: %d\nRead Result: %d\n\n", write_result, read_result);
    
             printf("Most recent data...\n");
             for(temp = 0; temp < REPORT_AFTER; temp++)
             {
            printf("save_data[%d].C: %f\n", temp, save_data[temp].celcius);
                printf("save_data[%d].F: %f\n", temp, save_data[temp].fahrenheit);
             }
    
             report = 0; // Do not report again until another sample has been taken.
          }// End if
       }// End while
    }// End main
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT My jsfiddle entry is here : http://jsfiddle.net/ehNrE/3/ All the codes(only those required) below
Edit: Rewritting question I use the Project Management Library from http://dlhsoft.com/Home.aspx in my WPF
Edit: This was accidentally posted twice. Original: VB.NET Importing Classes I've seen some code
Edit ok, great feedback here, got me pointed in the right direction. Use case
Edit: Updating post based on Martins comments below Hello, I'm just trying to get
EDIT: for those who come here with a similar problem, now i know this
Edit: Made an official bug report at developers.Facebook.com GETing either of the following: graph.facebook.com/me/photos
EDIT Per the comment below, here's my attempt at splitting / combining / converting
EDIT: looking for this: http://diminishing.org/extending-formtastic-with-a-sprinkle-of-jquery (If this works I'll answer my own question) I've
EDIT: Here's my call stack. System.ServiceModel.dll!System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(System.ServiceModel.Channels.Message reply, System.ServiceModel.Channels.MessageFault fault, string action, System.ServiceModel.Channels.MessageVersion version, System.ServiceModel.Channels.FaultConverter

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.