Switch/Case not responding as expected

I am trying to write a sketch that shows some messages after receiving a command true the USB.
It displays it on a serial LCD. In my opinion the code is straight forward but it doenst work.

#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif

boolean _gs232WActice = false;  // gs232 W command in process
int _gs232AzElIndex = 0;        // position in gs232 Az El sequence
long _gs232Azimuth = 0;          // gs232 Azimuth value
long _gs232Elevation = 0;        // gs232 Elevation value
boolean _azimuthMove = false;     // azimuth move needed
boolean _elevationMove = false;   // elevation move needed

String azRotorMovement;   // string for az rotor move display
String elRotorMovement;   // string for el rotor move display

#include <SoftwareSerial.h>
const int TxPin = 7;          // Define the transmit pin to LCD
                              // There is no receive pin from the LCD
// Create a software Serial instance for the Serial LCD
SoftwareSerial serLCD = SoftwareSerial(255, TxPin);

void setup() {
// setup standard serial USB
  Serial.begin(9600);
    
// setup serial LCD and display welcome message
  pinMode(TxPin, OUTPUT);
  digitalWrite(TxPin, HIGH);        // Neccesary if no display attached
  
  serLCD.begin(9600);               // The Parralax display used has a max baudrate of 19200
  delay(100);
  startUp();
}

void loop()
{
  // Check for serial data
  if(Serial.available()>0)
    {
      decodeGS232(Serial.read());
    }
}

// Decode received command from terminal or other program
void decodeGS232(char character)
{
    switch(character)
     {
      case's':
      case'S':        // Stop all movements
      {
       serLCD.write(148);
       serLCD.print("Emergency Stop");
       break; 
      } 
     }
}

// Initialize the LCD and show the copyright message
void startUp()
{
  serLCD.write(12);                 // Clear LCD           
  serLCD.write(17);                 // Turn backlight on
  serLCD.write(22);                 // Set cursor off
  delay(50);                        // Required delay
  serLCD.print("GS-232 Monitor");  // First line
  serLCD.write(13);                 // Form feed
  serLCD.print("Ver 0.1 (c) 2013");   // Second line
  serLCD.write(212);                // Quarter note
  serLCD.write(220);                // A tone
  delay(3000);                      // Wait 3 seconds
  serLCD.write(12);                 // Clear LCD
  serLCD.write(25);                 // Set cursor on and character blink
  serLCD.print("Waiting..");        // Goto input mode
}

Any help is welcome

Does the code do anything when you run it ?

This looks suspicious

  serLCD.begin(9600);               // The Parralax display used has a max baudrate of 19200

Does the baud rate have to be set on the display itself or does it adapt automatically ?

What made you put 255 in here as RX?

SoftwareSerial serLCD = SoftwareSerial(255, TxPin);

but it doenst work.

too vague, 2 questions:

What did you expect?

What did you got?

#UKHeliBob
It functions until the switch/case part.
Shows the welcome message and then when typing something on the terminal no response is displayed.
Looks like nothing is received.

#HazardsMind
This is as suggested by Paralax here

#robtillaart
Sorry but i am not so experience as all the others here

Sorry but i am not so experience as all the others here

It doesn't take experience to see what is on the LCD screen. Does anything at all go on the screen? Have you tried just sending the data to the serial monitor?

Even if you have no experience there should be some output you expected?

Give this variation a try. I expect it will generate always some output, some char between <>

// Decode received command from terminal or other program
void decodeGS232(char character)
{
  switch(character)
  {
    case 's':
    case 'S':        // Stop all movements
      serLCD.write(148);
      serLCD.print("Emergency Stop");
      break; 
    default:
      serLCD.write(148);
      serLCD.print("<");
      serLCD.print(character);
      serLCD.print(">");
      break; 
   }
}

Hi Rob,

It moves to the second line and prints the < character, nothing else.
I know the connection to the LCD is correct becourse direct sent message are visable.

I am very puzzeld

What is Serial.read(); getting? You can see what it is if you do Serial.println(Serial.read());

I would personally read the serial data into a variable before putting it into the call to your display routine.

something like

byte c = Serial.read();
decodeGS232(c);

It doesn't logically make sense why it make a difference, but the inner workings of interrupts and functions may be at work here.

When you ran the code that Rob gave you, you noticed that it stopped completely after printing "<"

That clues me that when it went to do the character part, everything went bonkers.

If it just had null as characters, it should have continued on and printed the ">" part. So, something threw your code off the rails.

Are you sure you are sending your character in the right format? Char = byte not a proper ascii string, so perhaps you need to send a null terminated string to the display. The serLCD.print function is probably looking for the null at the end of your string, and you aren't providing one so, it is hung up waiting for it.

try serLCD.print(character + "\0")

serLCD.print(character + "\0")

Maybe single quotes?

Yep... lol. Thanks AWOL

I only said "maybe" - it still doesn't look right

Does the IDE know how to concatnate with +? why not just send them like this, just to be safe.

serLCD.print(character);
serLCD.print( '\0');

Because it may get hung up in the first line as it is now. If the print routine itself is waiting for that null character, it will never go to the second line of code because it won't exit.

I am fairly certain that I have used the + in my code many times to add parts to a string to print. I may be wrong, but I am 99% certain.

I am fairly certain that I have used the + in my code many times to add parts to a string to print

A String maybe, but not a string.

char characters[] = { character,'\0' };
serLCD.print(characters);

Perhaps that, then?

HazardsMind:
What is Serial.read(); getting? You can see what it is if you do Serial.println(Serial.read());

Nothing
According to the suggestion of Rob i now changed the code to:

byte incomingByte = 0;

void loop()
{
  // Check for serial data
  if(Serial.available() > 0)
    {
      incomingByte = Serial.read();
      decodeGS232(incomingByte);
    }
}

// Decode received command from terminal or other program
void decodeGS232(byte character)
{
    switch(character)
     {
      case's':
      case'S':        // Stop all movements
      {
       serLCD.write(148);
       serLCD.print("Emergency Stop");
       break; 
      } 
    default:
      serLCD.write(148);
      serLCD.print("<");
      serLCD.print(character);
      serLCD.print(">");
      break;
      }
}

The result now is that the display shows <255> and then freezes

I made a mistake, it should be Serial.write(Serial.read()); , not println.