elixir_serial icon indicating copy to clipboard operation
elixir_serial copied to clipboard

Port process does not exit

Open rockwood opened this issue 9 years ago • 6 comments

I'm running into an issue where the port process isn't exiting after Elixir terminates. Unless I kill the offending process, my computer will crash if I unplug the usb connection.

I'm using the Sparkfun WRL-08687.

$ ps aux | grep serial
rockwood         5061   0.0  0.0  2445080    788 s004  S+    3:18PM   0:00.00 grep serial

I can then run the following:

{:ok, serial} = Serial.start_link

Serial.open(serial, "/dev/tty.usbserial-AM01VFAJ")
Serial.set_speed(serial, 9600)
Serial.connect(serial)
Serial.send_data(serial, "+++")

Serial.close(serial)
Serial.disconnect(serial)

And the process remains after elixir has exited.

$ ps aux | grep serial
rockwood         5110   0.0  0.0  2434840    752 s004  S+    3:21PM   0:00.00 grep serial
rockwood         5098   0.0  0.0  2434824    632   ??  Ss    3:21PM   0:00.00 /Users/rockwood/devel/exbee/_build/dev/lib/serial/priv/serial -erlang

I've tried modifying serial.ex to manually Port.close(port) on exit, but the process still remains.

Any ideas?

rockwood avatar Feb 20 '16 20:02 rockwood

The computer crashing on disconnection is likely a problem with the OS X FTDI driver. I cannot reproduce the issue you describe. It would be interesting to know, if multiple send/receive operation work or if the first of them blocks everything. Also, how do you kill the process? Is SIGTERM enough or do you have to use SIGKILL?

bitgamma avatar Feb 22 '16 19:02 bitgamma

It appears the the first call to send_data() blocks everything. I don't even see the TX led fire on the FTDI module. Doing a SIGTERM (with kill PROCESS_ID) works fine.

FWIW I was able to connect to the same device with ruby-serialport. In looking at the C code, I wasn't able to figure out what it's doing differently.

rockwood avatar Feb 23 '16 00:02 rockwood

I experience this same issue on Mac OSX. @rockwood were you able to actually communicate with your serial device, it just persisted the port post-shutdown, or did you also have problems communicating to your usbserial?

I'm having problems with both, but the later may be some yet-discovered issue in my own code.

dhanson358 avatar Aug 23 '16 18:08 dhanson358

@dhanson358 I ended up switching to Nerves UART. So far that's been working well with my Sparkfun XBee link.

rockwood avatar Aug 24 '16 00:08 rockwood

Tried that out this morning and the Nerves UART works well for me also. Thanks!

For what it's worth, on this (elixir_serial) project, I put the C application into debug mode and it seems like it could connect over serial just fine, but the SEND was never actually making it to the C app from elixir. I could see it being sent to the port, but it's like it never arrived to the "serial" executable.

If I put my own "Port" connection (to the compiled C app) in IEX and did the same steps all in sequence, it seemed to work, but not as part of the GenServer. That's pretty much where I got stuck.

Using the same code on Linux (ubuntu 16) did work fine. So there's definitely something funny going on with the port communication between the GenServer and the serial binary particular to Mac OSX.

dhanson358 avatar Aug 24 '16 17:08 dhanson358

I suggest using Nerves UART. This project was started before Nerves UART existed and is a port of a 20 year old Erlang project.

bitgamma avatar Aug 24 '16 18:08 bitgamma