R
Rick
Hi,
Sorry, I couldn't find a better title for this post. Anyway, I got a piece
of C code which only works well if I put a fprintf in it. Here's the code :
unsigned int8 Port_getPortNum( char *port )
{
fprintf(DB9, "port = %s\r\n", port ); // Don't know why
but I need this fprintf?!
if ( port[1] == 'A' )
{
if ( port[2] == 'I' ) return port[3]-48; else // [3] is a
number 1..9
if ( port[2] == 'O' ) return port[3]-38;
}else
if ( port[1] == 'D' )
{
if ( port[2] == 'I' ) return port[3]-42; else
if ( port[2] == 'O' ) return port[3]-36;
}
fprintf(DB9, "ERROR [3] = %c\r\n", port[3] ); // It shouldn't come
this far
return 0;
} // Port_getPortName
The strange thing is, if I remove the first fprintf the result isn't correct
anymore. I test it with another method :
void PORT_EXPORT( char port[4], char *result, int16 *varlen, int16
*reslen )
{
char test;
test = Port_getPortNum(port);
fprintf( DB9, "PORTID= %i\r\n",test );
<...>
Yep, I need to use a char because I can't give up an integer as parameter.
Maybe the result is ok but the printf's or conversions are wrong... But if I
don't remove that fprintf the result seems to be OK. Sometimes I experience
this problem also in other languages (on fast computers with plenty of
RAM).... What's wrong?
For your information, DB9 in the fprintf is a stream towards a rs232, I use
HyperTerminal to read out the results as it comes from a microcontroller.
And the input port parameter is a string like this : "@AI3" which stands
for Analog Input number 3.
Greetings,
Rick
Sorry, I couldn't find a better title for this post. Anyway, I got a piece
of C code which only works well if I put a fprintf in it. Here's the code :
unsigned int8 Port_getPortNum( char *port )
{
fprintf(DB9, "port = %s\r\n", port ); // Don't know why
but I need this fprintf?!
if ( port[1] == 'A' )
{
if ( port[2] == 'I' ) return port[3]-48; else // [3] is a
number 1..9
if ( port[2] == 'O' ) return port[3]-38;
}else
if ( port[1] == 'D' )
{
if ( port[2] == 'I' ) return port[3]-42; else
if ( port[2] == 'O' ) return port[3]-36;
}
fprintf(DB9, "ERROR [3] = %c\r\n", port[3] ); // It shouldn't come
this far
return 0;
} // Port_getPortName
The strange thing is, if I remove the first fprintf the result isn't correct
anymore. I test it with another method :
void PORT_EXPORT( char port[4], char *result, int16 *varlen, int16
*reslen )
{
char test;
test = Port_getPortNum(port);
fprintf( DB9, "PORTID= %i\r\n",test );
<...>
Yep, I need to use a char because I can't give up an integer as parameter.
Maybe the result is ok but the printf's or conversions are wrong... But if I
don't remove that fprintf the result seems to be OK. Sometimes I experience
this problem also in other languages (on fast computers with plenty of
RAM).... What's wrong?
For your information, DB9 in the fprintf is a stream towards a rs232, I use
HyperTerminal to read out the results as it comes from a microcontroller.
And the input port parameter is a string like this : "@AI3" which stands
for Analog Input number 3.
Greetings,
Rick