PC keeps shutting down my Arduino USB Com Port???

I am trying to establish communications between and Arduino Uno and a script language called "Lua" running on my pc via the USB connection. However, every time I launch the lua script the serial data coming from the Arduino stops flowing.

I'm watching the serial data using a serial monitor program called "Device Monitor Studio". I have a very simple program running on the Arduino as a test. It sends the string "A45" and "A46" alternately every two seconds. The lua script is supposed to open the com port and listen for data. Upon receiving either of the strings above it should take certain actions on the pc.

However, as soon as I launch the lua script and it opens the com port Device Monitor Studio shows that the data stops flowing.

Does the Arduino expect any flow control signals such as RTS/DTS or XOn/XOff ? I don't think that's the problem but thought I would check. The lua "com.open" function can be configured via it's third parameter to send one, the other, both or, nothing and I've tried four options.

Any thoughts or ideas on what would be stalling the serial data flow would be welcome. THANKS!

Here's my simple test program on the Arduino:

void setup() {
  Serial.begin(9600);
}
void loop() {
  Serial.println("A45");
  delay(2000);
  Serial.println("A46");
  delay(2000);
}

And here's the lua code:

speed = 9600
handshake = 3
ArdComPrt = com.open("COM8", Speed, handshake)

if ArdComPrt == 0 then
    ipc.display("Could not open ARDUINO Com Port")
	ipc.sleep(2000)
    ipc.exit()
else
    ipc.display("Arduino Com Port Open")
	ipc.sleep(2000)
	ipc.display("")
end

function ArdData(ArdComPrt, datastring, length)

    if datastring == "A45" then
        ipc.writeLvar("L:kma26SelectorKnob_pos",1)
    elseif datastring == "A46" then
        ipc.writeLvar("L:kma26SelectorKnob_pos",2)
    end
end

event.com(ArdComPrt, 5, 1, 10, "ArdData")

You can disable the reset functionality with a 10uf capacitor between the Arduino Reset Pin and GND. (make sure to do this after your sketch is loaded to the Arduino)

HazardsMind:
You can disable the reset functionality with a 10uf capacitor between the Arduino Reset Pin and GND. (make sure to do this after your sketch is loaded to the Arduino)

I just tried that. Unfortunately. no joy. The serial data still stalls. Is there any way in my code to monitor or disable that reset?

Not to my knowledge. Then again I haven't really dwelled deep enough into the Arduino core to see if such a thing is possible. To my understanding the reset pin just resets the Arduino when given a low signal (to ground) and that 10uf cap should disable the pin from going low.

I think Moderator Nick Gammon has something on this subject. You should be able to navigate to his Arduino page via his name here on the forum.

HazardsMind:
Not to my knowledge. Then again I haven't really dwelled deep enough into the Arduino core to see if such a thing is possible. To my understanding the reset pin just resets the Arduino when given a low signal (to ground) and that 10uf cap should disable the pin from going low.

I think Moderator Nick Gammon has something on this subject. You should be able to navigate to his Arduino page via his name here on the forum.

THANKS!!!

Your response brought a question to mind. It may be something you can shed some light on or, as you suggest, I may have to bring this to someone lick Nick.

I assume the reset also happens when I activate the Arduino IDEs Serial Monitor, yes?

If so, what is different there that serial communications restarts as compared to when I open it from my lua script? I wonder if there's a flow control string that it sends that I could add to my script?

I assume the reset also happens when I activate the Arduino IDEs Serial Monitor, yes?

Yes it is a command sent by the Arduino IDE to successfully upload the sketch to the Arduino, I do know that. However I don't know what the command actually is. It might actual be a sequence of lines, idk.

But yes, try to reach out to Nick or perhaps another moderator, like CrossRoads or Coding Badly.

Tom_G_2010:
However, as soon as I launch the lua script and it opens the com port Device Monitor Studio shows that the data stops flowing.

Stops entirely or stops for about one second?

event.com(ArdComPrt, 5, 1, 10, "ArdData")

Are you really supposed to pass the name of the function to this function? It might be required, but try without, eg.

event.com(ArdComPrt, 5, 1, 10, ArdData)

[quote author=Coding Badly link=msg=2569085 date=1453010720]
Stops entirely or stops for about one second?[/quote]

Stops entirely.

I can still see the Transmit LED on the Arduino flashing every 2 seconds but Device Monitor Studio shows no data flowing at all.

I can restart the data flow by toggling the Arduino IDE's serial monitor on and off. Hence the question what is it doing differently when it opens the com port.

What does "handshake = 3" do?

Nick, I just tried it with and without the function name and with and without quotes around the function name and a few other variations and anything other than the original syntax causes the lua script to stop executing.

I also stripped everything out of the lua except the line that opens the com port and even executing just that one line stalls the data flow.

I ran just this:

speed = 9600
handshake = 0
ArdComPrt = com.open("COM18", Speed, handshake)

So it would seem it's isolated to that. I keep looking back at the fact that even the Arduino IDEs Serial Monitor triggers a reset but, the data starts flowing again after that reset. What is it doing differently when it opens the Com port?

aarg:
What does "handshake = 3" do?

The com open function supports four different handshake options:

0 = none
1 = RTS / DTR line levels
2 = XON / XOFF
3 = Both of the above

I have tested it with all four. I assumed the correct option was 0 but, I've tested it with all four, no difference. The data still stops flowing.

Well, XON/XOFF embeds control codes in the serial stream. Does your sketch implement the protocol?

PROBLEM SOLVED!!!

I'll be circling back with the developer of the com library I'm using in Lua but it appears the com port problem is solved.

My original com open statement in the Lua script looked like this:

speed = 9600
handshake = 1
ArdComPrt = com.open("COM8", Speed, handshake)

Just now to strip it all the way down and eliminate any other problem sources I took out the variable declarations and ran it as follows:

ArdComPrt = com.open("COM8", 9600, 1)

That works! The Com Port opens and the data keeps flowing.

Tom_G_2010:
PROBLEM SOLVED!!!

I'll be circling back with the developer of the com library I'm using in Lua but it appears the com port problem is solved.

My original com open statement in the Lua script looked like this:

speed = 9600

handshake = 1
ArdComPrt = com.open("COM8", Speed, handshake)




Just now to strip it all the way down and eliminate any other problem sources I took out the variable declarations and ran it as follows:



ArdComPrt = com.open("COM8", 9600, 1)




That works! The Com Port opens and the data keeps flowing.

Is the script case sensitive? You have "speed" and "Speed".

aarg:
Is the script case sensitive? You have "speed" and "Speed".

Arrggghhhh!!!!!

That was it!!!

Lua is case-sensitive.