RS232/USB emulator weird issue

Status
Not open for further replies.

pratiken

Newbie level 5
Joined
Mar 13, 2014
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
85
Hey guys,
I don't totally understand why my emulator is doing this.
I can successfully connect to my PIC18F2550 device via serial COM port using Putty.

The issue is that it records every keystroke before hitting enter, even if I use the backspace due to a typo.

For example, "Command 1"
If I type "Command 1" without any mistakes, it's fine and the command is executed.
If I make a typo and hit backspace to fix, then press Enter, the command is not recognized even though I had "Command 1" entered in terminal.

Somehow, it's picking up all keystrokes prior to the Enter key. Any ideas why this would be?

Thanks for any help!!!



Code:
/********************************************************************
 * Function:        void ProcessIO(void)
 * Overview:        This function is a place holder for other user
 *                  routines. It is a mixture of both USB and
 *                  non-USB tasks.
 *******************************************************************/
void ProcessIO(void)
{
    BYTE numBytesRead;

    // User Application USB tasks
    if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) return;

    if (USBUSARTIsTxTrfReady())
    {
        numBytesRead = getsUSBUSART(USB_Out_Buffer, 64);
        if (numBytesRead != 0)
        {
            if (USB_Out_Buffer[0] == '\r')                      //Received ENTER? Ues-> End of Command
            {
                command_recvd = 0x01;
                Command[pos++] = '\0';
                putUSBUSART((char*) USB_Out_Buffer, 1);
                pos = 0;
            } else { Command[pos++] = USB_Out_Buffer[0]; Command[pos]='\0';}       //No:- Store Character to String

            if (command_recvd == 0x01)
            {
                if (strcmp((char*) Command, (char*) "Command 1") == 0)
                {
                    // COMMAND CODE HERE
                }
                else
                {
                    InvalidCommand = 0x01;
                }
                Command[0]='\0';
                if (InvalidCommand ==0x00) { sprintf(output_message, "\r\nCommand Sent...!!!!\r\n");} else {
                    InvalidCommand=0x00;
                    sprintf(output_message, "\r\nInvalid Command..!!\r\n");}

                putUSBUSART((char*) output_message, sizeof (output_message));
                command_recvd = 0x00;
            }
        }
    }
    CDCTxService();
}
 

it looks as though you are reading and buffering every character into Command[] until you receive \r - this probably includes any backspace characters

if so you need to check if the character received is backspace and if so remove the last character from Command[] (taking care not to go past the start of Command[])
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…