main() { auto int channel, gaincode, ch; char tempbuf[64]; char sendbuf[128]; char i; brdInit(); seropen(BAUDRATE); serrdFlush(); serwrFlush(); if (PRINTDEBUG) { printf("Block size = 0x%x\n", 4096*GetIDBlockSize()); printf("ADC single-ended address 0x%x\n", ADC_CALIB_ADDRS); //single-ended address start printf("DAC single-ended address 0x%x\n", DAC_CALIB_ADDRS); //single-ended address start printf("\nRead constants from user block\n"); } anaInEERd(ALLCHAN); //read all single-ended input anaOutEERd(ALLCHAN); //read all single-ended output memset(sendbuf, '\x0', sizeof(sendbuf)); while(serrdFree() != INBUFSIZE) sergetc(); // Send data out the serial port to the PC serputs("Uploading calibration table . . .\n\r\x0"); serputs("Enter the serial number of your controller = \x0"); ch = 0; i=0; while (ch != '\r') { // make sure you have local echo enabled in Tera Term, so that the // serial number will written to the calibration file. while ((ch = sergetc()) == -1); // Check for a BACKSPACE...allow editing of the serial number if (ch == '\b' && i > 0) { --i; } else tempbuf[i++] = ch; } tempbuf[i] = '\x0'; sprintf(sendbuf, "\n\r::\n\rSN"); strcat(sendbuf, tempbuf); strcat(sendbuf, "\n\r\x0"); serputs(sendbuf); //// //// if (PRINTDEBUG) printf("\n\nFormatting single-ended channels to transmit\n"); sprintf(sendbuf, "ADSE\n\r\x0"); serputs(sendbuf); for(channel = STARTAD; channel <= ENDAD; channel++) { memset(sendbuf, '\x0', sizeof(sendbuf)); sprintf(sendbuf, "%d\n\r\x0", channel); sprintf(tempbuf, "%9.6f,%9.6f,", _adcCalibS[channel].kconst, _adcCalibS[channel].offset); strcat(sendbuf, tempbuf); strcat(sendbuf, "\n\r\x0"); serwrite(sendbuf, sizeof(sendbuf)); } //// //// if (PRINTDEBUG) printf("\n\nFormatting single-ended channels to transmit\n"); sprintf(sendbuf, "DASE\n\r\x0"); serputs(sendbuf); for(channel = STARTDA; channel <= ENDDA; channel++) { memset(sendbuf, '\x0', sizeof(sendbuf)); sprintf(sendbuf, "%d\n\r\x0", channel); sprintf(tempbuf, "%9.6f,%9.6f,", _dacCalibS[channel].kconst, _dacCalibS[channel].offset); strcat(sendbuf, tempbuf); strcat(sendbuf, "\n\r\x0"); serwrite(sendbuf, sizeof(sendbuf)); } sprintf(sendbuf, "END\n\r::\n\r\x0"); serputs(sendbuf); serEputs("End of table upload\n\n\r\x0"); // Make sure all data gets transmitted before exiting the program while (serwrFree() != OUTBUFSIZE); while((RdPortI(SXSR)&0x08) || (RdPortI(SXSR)&0x04)); serclose(); }
void serclear(fifo_t *fp) { while (seravailable(fp) > 0) { sergetc(fp); } }