So any input via Serial is passed to NSS and vise versa. The device I have attached via NSS is setup so that when it recieves '$$$' it returns 'CMD'. If I run this with the Arduino serial monitor and pass in '$$$', nss.print gets called 3 times, and I get back the expected 'CMD'.
What I want is for the code to internally issue the '$$$'. So I change the setup function to this;
But instead of getting the 'CMD' returned without having to pass in '$$$' I get back either nothing or 3 odd characters.
Any idea why this would not work?
There a blocking and non-blocking functions. A blocking function waits until everything that it is supposed to do is done, and then returns. Nothing else can happen until the blocking function returns.
A non-blocking function starts an action and returns, before that action is complete.
I think that NewSoftSerial::begin() and Serial::begin() are non-blocking functions.
Therefore, what is happening is that you are sending data before the NewSoftSerial port is read to send data. Try adding a short delay, maybe 50 milliseconds, between nss.begin() and nss.print().
When you get "3 odd characters", are they always the same 3 characters? What are they? You could try adding ,DEC to the Serial.print() statement, to make it print the actual value received, rather than the ASCII character that the value represents. Perhaps there is some clue in the actual values received that is masked by printing the ASCII equivalent, if the values aren't meant to be interpreted as ASCII characters.