CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

why this doesn't work, please help (fprintf with pointers...

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
runtime



Joined: 15 Sep 2003
Posts: 36

View user's profile Send private message

why this doesn't work, please help (fprintf with pointers...
PostPosted: Tue Aug 31, 2004 3:27 pm     Reply with quote

Hello all,

I'm new to pointers, please help me out. Function SetTerminal is called from main subroutine to initialize modem. This does not work, I get nothing in PC stream nor MODEM stream...

Thank you in advance


// ------------------
// Function SendModem
// ------------------
void SendModem(int8 val) {
disable_interrupts(int_ext);
fputc(val, MODEM);
enable_interrupts(int_ext);
}

// ----------------
// Function SendCmd
// ----------------
void SendCmd(char *cmdstr)
{
int p;

// signalOk is made True when Modem answer
signalOk = False;

output_high(Connected);

q = 0;
do {
fprintf(PC,"%s\r\n",*cmdstr);
SendModem(*cmdstr);
for (p = 1; p <= 40; p++) { // 2 sec Timer to get response
delay_ms(50);
if (signalok) break;
}
q++;
CheckResponse();
} while (!signalOk && q < 11);

output_low(Connected);
delay_ms(500);

}

// --------------------
// Function SetTerminal // Configure Terminal
// --------------------
void SetTerminal(void)
{

fprintf(PC,"Programming GPRS Terminal...\r\n");

SendCmd("AT+WIND=4\r");
SendCmd("AT+CLIP=1\r"); // Caller Id
SendCmd("AT+CICB=2\r");
// ... More Commands ...
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Aug 31, 2004 3:43 pm     Reply with quote

See previous posts about pointers to constant strings:
http://www.ccsinfo.com/forum/viewtopic.php?t=18676
JPA
Guest







PostPosted: Wed Sep 01, 2004 2:43 am     Reply with quote

There are some strnge things I pointed out with your piece of code:

1) Pointer to constant string: due to the compiler behaviour (see previous posts), function SendCmd is called for each character in the constant string. Obviously, this is not what you want.

2) Your SendCmd function also have some problems: let's suppose the argument cmdstr points to the correct string (which is not the case , see pt 1 ), then I think that you should write
"fprintf(PC,"%s\r\n", cmdstr);" and not "fprintf(PC,"%s\r\n",*cmdstr);" see http://www.cplusplus.com/ref/cstdio/fprintf.html for more info.

The SendCmd function receives one byte as input and so will only send 1 char...
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group