|
|
View previous topic :: View next topic |
Author |
Message |
runtime
Joined: 15 Sep 2003 Posts: 36
|
why this doesn't work, please help (fprintf with pointers... |
Posted: Tue Aug 31, 2004 3:27 pm |
|
|
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
|
|
|
JPA Guest
|
|
Posted: Wed Sep 01, 2004 2:43 am |
|
|
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... |
|
|
|
|
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
|