I am trying to send / receive a string through C #, in C # I just do:
SerialPort.WriteLine("A6");
but in CCS, if I try to send a char string after a char, it does not work at all, neither with ReadLine nor with ReadExisting! This is what I tried to create an array, so every time we enter the pragma RXBUFF, we add the resulting char array to the array until the array is full (I accidentally determined the size of the array to 2, which means that we are dealing with 2- char -longed strings) and end up sending the string by sending char after char:
#pragma vector = USCI_A1_VECTOR __interrupt void USCI_A1_ISR(void) if(__even_in_range(UCA1IV,18) == 0x02){ // Vector 2 - RXIFG if(counter==0) { Data[0]=UCA1RXBUF; counter++; } else { Data[1]=UCA1RXBUF; counter=0; UCA1TXBUF=Data[0]; while(!(UCA1IFG & UCTXIFG)); // until UCTXBUF1 is empty UCA1TXBUF=Data[1]; } }
in C #:
listBox2.Items.Add(SerialPort.ReadExisting());
I get the text without meaning, for example: ?????? sometimes:???? etc., but with:
listBox2.Items.Add(SerialPort.ReadLine());
the first time I press the "Send" button, which sends "A6", I get nothing, the second time I get non-meaning, like ReadExisting behavior.
By the way, even if I try to send a string in the simplest way (without an array and conditions), I mean like this:
#pragma vector = USCI_A1_VECTOR __interrupt void USCI_A1_ISR(void) UCA1TXBUF='A'; while(!(UCA1IFG & UCTXIFG));
I also get inconsistent items in the list.
However, if I do this:
#pragma vector = USCI_A1_VECTOR __interrupt void USCI_A1_ISR(void) UCA1TXBUF=UCA1RXBUF;
I get "A6" in the list and everything just works fine (with ReadLine and ReadExisting)! can anyone just tell me why this is happening?