?
Solved

Low points tough question please help!!! SYNCDRIVE

Posted on 2003-03-24
20
Medium Priority
?
230 Views
Last Modified: 2010-04-17
short transmit(char *pMss, int leng)
{

   char *pSS={"\x0b"};
   char *pLL;


   strncpy(pLL,pMss,leng);
   printf("%c",pLL);
   getch();
   *pLL=*pSS+*pLL
   strcpy ((char *)pTxBuffer->BitT.comm_buffer, pLL);



   // Initialize the transmit buffer comm_block

   pTxBuffer->BitT.buffer_length = strlen((char*)pTxBuffer->BitT.comm_buffer);
   pTxBuffer->BitT.buffer_status = 0;
   pTxBuffer->BitT.idle_flag =  0;

#ifdef __OS2__
   rc = sync_transmit (pMPA_cfg, pTxBuffer, 10000);
#elif defined _WINDOWS
   rc = sync_transmit (pMPA_cfg, pTxBuffer, 0);
#else  // DOS
   rc = sync_transmit (pMPA_cfg, pTxBuffer);
#endif

   if (rc)
      {
      printf("Error starting frame transmission %04x", rc);
      return(-1);
      }

   while (!(pTxBuffer->BitT.buffer_status & (TxDone | TxAbort | TxError)));

   if (pTxBuffer->BitT.buffer_status & TxError)
      printf("Transmitter Error\n");
   if (pTxBuffer->BitT.buffer_status & TxAbort)
      printf("Transmitter underrun\n");

   return(pTxBuffer->BitT.buffer_status);

}
#define MAXLEN 50
void split(char *pMessage)
{
  int slen, leng;

  char *pE, *pF;

  slen = strlen(pMessage) ;
  pE = pMessage;
  do
  {
            pF = pE;
        leng = slen > MAXLEN ? MAXLEN : slen ;

        pE = pF + leng;

        while (*pE != ' ')
        {
               if (*pE == 0)
         break ;
             pE--;
         leng-- ;
        }

          leng=pE-pF ;

      printf("%*.*s\n", leng, leng, pF) ;

      getch() ;

      transmit(pF, leng);

      slen -= leng;

  } while(slen>0);

}

this is a small part out of the syncdrive program. Syncdrive is the example program provided by quatech for their communication card. the split function is to segment the message which is very long into 50 characters by 50 characters. by right when i strncpy(pLL,pMss,leng) i am suppose to get the segmented message correctly. but i realise that when i printf it , there are lots of unwanted characters behind my message. Why is that so? Another problem is i want to add hexadecimal 0B in front of the segmented message. SO i use the above method *pLL=*pSS+*pLL it doesnt seem to be able to work. THe characters in the message transmitted was in a mess.hopefully people out there can help me on this.
0
Comment
Question by:bbtss
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 9
20 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 8200449
short transmit(char *pMss, int leng){

  char *pSS={"\x0b"};
  char pLL[100];
  if( leng >= 100 ){
     fprintf(stderr,"not enough space in string for %d chars\n",leng);
     exit(1);
  }


  strncpy(pLL,pMss,leng);
  pLL[leng]='\0';

  printf("%c",pLL);
  getch();
  *pLL=*pSS+*pLL
  strcpy ((char *)pTxBuffer->BitT.comm_buffer, pLL);
0
 

Author Comment

by:bbtss
ID: 8200531
wow thanks. the message i send dun have rubbish behind it anymore. but i didnt get OB in front. instead i have a + sign in front which is equal to 2B?
how come?
0
 

Author Comment

by:bbtss
ID: 8200538
wow thanks. the message i send dun have rubbish behind it anymore. but i didnt get OB in front. instead i have a + sign in front which is equal to 2B?
how come?
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 30

Expert Comment

by:Mayank S
ID: 8201480
He used \x - which is an escape sequence for hexadecimal value. Anyways, \x0b will evaluate to 11 decimal, so the character shown should be different. '+' has an ASCII value of 43, so that should not be displayed. Might have something to do with encoding and might also depend upon the platform on which you are working.

You can try:

char * str = "\x0b" ;
printf ( "%s", str ) ;

printf ( "%c", ( (char) 11 ) ) ;

printf ( "%d", ( ( int ) '+' ) ) ;


Mayank.
0
 

Author Comment

by:bbtss
ID: 8208075
ya i do get ob now. but my programming is really lousy. i do not know how i can put it in front of my segmented message. what am i suppose to declare or what am i suppose to do?
0
 

Author Comment

by:bbtss
ID: 8208121
ya i do get ob now. but my programming is really lousy. i do not know how i can put it in front of my segmented message. what am i suppose to declare or what am i suppose to do?
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 8208147
I am sorry I don't quite understand your question..

Mayank.
0
 

Author Comment

by:bbtss
ID: 8208300
hm... i want to add hexadecimal 0B in front of my string pLL. How can i do this?
i tried char *pSS="\x0B";
        *pSS=*pSS+*pLL;
i cant get the the hexadecimal infront. is there any other way to do it?
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 8208326
If you want to get it in front of pLL (I think this is supposed to mean - first characater of string pLL), then why are you assigning it to * pSS? Make it: * pLL = '\x0b' ; // single-quotes

Mayank.
0
 

Author Comment

by:bbtss
ID: 8208360
i got a % symbol instead of a symbol that represent 0b in front. is there any other way to put this 0b as the first character?
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 8208386
If pLL is pointing to the first character, then * pLL = '\x0b' will modify the first character, otherwise which-ever character it is pointing to will be modified. If it still doesn't work, you can try:

* pLL = (char) 11 ;
printf ( "%c", * pLL ) ;

Mayank.
0
 

Author Comment

by:bbtss
ID: 8208400
but than i have to copy the whole string into the buffer. and not printf the ob.my motive is to send this whole string across. so i have to make this whole message into only 1 pointer. unless there is another way of copying string.
strcpy ((char *)pTxBuffer->BitT.comm_buffer, pSS);


0
 
LVL 30

Expert Comment

by:Mayank S
ID: 8208453
int len = strlen ( pLL ) ;
char * temp = new char[len+2] ;
* temp = (char) 11 ;

for ( i = 0 ; i < len ; i ++ )
  temp[i+1] = pLL[i] ; // end for

temp[i+1] = '\0' ;
pLL = realloc ( len + 2 ) ;
strcpy ( pLL, temp ) ;

Mayank.
0
 

Author Comment

by:bbtss
ID: 8208685
wow thanks it work. actually i could not really understand what u are writng. is it possible to write another hexadecimal number behind the first with a increment of 2?
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 8208745
Actually, I just allocated space for an extra character (only for one extra character, because pLL already has not len but len + 1 characters, including the NULL character). And then all I did was store the '\x0b' in the first character, copy the rest into a temporary string, and thn copy it back to pLL after reaalocating the extra memory for it.

Mayank.
0
 

Author Comment

by:bbtss
ID: 8208784
so how do i add a second hexidecimal behind the first hexidecimal??
0
 
LVL 30

Accepted Solution

by:
Mayank S earned 260 total points
ID: 8208860
Sameway.... I suggest you write the code which I provided in a function and pass pLL and the number as argument.

void func ( char * pLL, int val )
{
  int len = strlen ( pLL ), i ;
  char * temp = new char[len+2] ;
  * temp = (char) val ;

  for ( i = 0 ; i < len ; i ++ )
    temp[i+1] = pLL[i] ; // end for

  temp[i+1] = '\0' ;
  pLL = realloc ( len + 2 ) ;
  strcpy ( pLL, temp ) ;

} // end of func ()

..
..

func ( pLL, 11 ) ; // stores '\x0b' at the front.

Mayank.
0
 

Author Comment

by:bbtss
ID: 8212020
but than although i can call the function twice to add in another hex number . pLL still remains in the function    void func ( char * pLL, int val ). i need to return the value back to that function so i can call it again with the ob in front of the message.
example:
short transmit(char *pMss, int leng)
{


 char pLL[100];

 if( leng >= 100 )
 {
    fprintf(stderr,"not enough space in string for %d chars\n",leng);
    exit(1);
 }
 strncpy(pLL,pMss,leng);
 pLL[leng]='\0';
 func(pLL,11);
 func(pLL,2);
......
.....
........
....
}

it seems that the value of pLL in the func function is not return to the transmit function. i do not know how to return vaule to the transmit function. can help me with this?

 
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 8215428
Oh, God! Can't believe I ever did that mistake myself, after having corrected so many people on EE over it!


void func ( char * pLL, int val )
{
  for ( int i = strlen ( pLL ) + 1 ; i > 0 ; i -- )
    pLL[i] = pLL[i-1] ; // end for

  pLL[0] = ( char ) val ;

} // end of func ()


Mayank.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 8251398
Did it work?
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is about my first experience with programming Arduino.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Progress

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question