0

I have the following code:

import serial 

arduino = serial.Serial('/dev/tty.usbmodem14111') 
print(arduino.portstr) 

And I got the following error:

Traceback (most recent call last): 
 File "/Users/miguelangelcallejonbosque/Documents/workspace/proyectp/principal/hola.py", line 2, in <module> 
   import serial 
 File "/Library/Python/2.7/site-packages/pyserial-3.3-py2.7.egg/serial/__init__.py", line 31, in <module> 
 File "/Library/Python/2.7/site-packages/pyserial-3.3-py2.7.egg/serial/serialjava.py", line 36, in <module> 
 File "/Library/Python/2.7/site-packages/pyserial-3.3-py2.7.egg/serial/serialjava.py", line 30, in detect_java_comm 
ImportError: No Java Communications API implementation found 

Can you help me solve it?

Thanks in advance

Hung Cao
  • 3,130
  • 3
  • 20
  • 29
calle
  • 1

1 Answers1

0

This is not the correct form to open a serial port on arduino. try this

arduino = serial.Serial(
port='/dev/ttyACM0',
baudrate=9600,
parity=serial.PARITY_ODD,
stopbits=serial.STOPBITS_TWO,
bytesize=serial.SEVENBITS
)

Please note that values depens by your board (these should work on arduino). Also note that you must manage an serial.serialutil.SerialException exception.

Here you can find an example of working code (works on genuino UNO)

UPDATE Figured out that the problem was a version incompatibility between library and jython

Thecave3
  • 762
  • 12
  • 27
  • I still get the same error. Maybe you have to see that I use mac os x? – calle Mar 15 '17 at 20:45
  • This one is working on linux after library installation. [Have you installed](http://stackoverflow.com/questions/31228787/install-pyserial-mac-os-10-10) serial library on your mac? – Thecave3 Mar 15 '17 at 20:52
  • This [one](http://stackoverflow.com/questions/8030975/add-javax-comm-api-on-a-mac) could help maybe. Please look at the correct answer. – Thecave3 Mar 15 '17 at 21:14
  • Could you please give more information about your problem and your machine? – Thecave3 Mar 16 '17 at 17:36
  • I try to connect arduino with python to port serial. My computer is a Mac Os, but I have done it with a windows and the error is the same – calle Mar 16 '17 at 17:48
  • are changing every time that you plug your board in the right port? – Thecave3 Mar 17 '17 at 13:49
  • In windows for example is not tty but COMX (where x is an integer that defines your physical port) – Thecave3 Mar 17 '17 at 13:50
  • Also seems the problem is on the import line, could you please show what version of python you're using (I don't know if serial is supported in jython). – Thecave3 Mar 17 '17 at 13:50
  • Thanks to your contribution, I have been able to verify that running the code with the python interpreter works, but with the jython interpreter it does not work. – calle Mar 17 '17 at 15:32
  • coud you please mark this as resolved (I have updated the answer)? Would be very apprecciate – Thecave3 Mar 17 '17 at 18:43
  • Still not solved, because I need the serial with jython and only works well with python – calle Mar 17 '17 at 19:08
  • You can create your own module using [sockets](http://www.jython.org/docs/library/socket.html), that seems your only option. – Thecave3 Mar 17 '17 at 20:38