编辑 - 以下是一些回应评论的资源:
成本:http : //bamafolks.com/randy/students/embedded/dynamicC_mtask.html
writeUserBlockArray:http ://ftp1.digi.com/support/documentation/html/DynCFunctionReference/12fun595.htm#1259708
我得到的错误是'-1:无效的地址或范围'。
#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;
}
这是所有相关的代码。我一直从表示无效地址或范围-1
的方法返回。writeUserBlockArray()
我不认为它是 Dynamic-C 的事实有很大的不同,但有问题的方法的大纲是这样的:
writeUserBlockArray(addrOffset, arraySources, arraySourceSizes, numSources);
我是 C 新手,我认为我将数据保存到数组的方式有问题?
提前致谢。