Quantcast

PySerial & RXTX query

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

PySerial & RXTX query

Corgi
I have had no success with opening a serial port (device is a Prolific USB
to serial comm port [COM9]) from Jython (2.7) using PySerial (tried both 2.7
and 3.1.1) and the RXTX replacement for javax.comm on windows 64 bit.  I
have tried the usual googling for examples but found no really helpful
jython specific ones.  If anyone has an example program that works, I should
be really grateful to see it!

It all works fine in Python 2.7 !

Thanks in advance,

Graham

(Apologies if this is posted twice)


------------------------------------------------------------------------------
_______________________________________________
Jython-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: PySerial & RXTX query

Adam Burke-2
Hi, do you get exceptions, or can you share a simple test program?

Adam

> 在 24 Sep 2016,4:15 PM,Corgi <[hidden email]> 写道:
>
> I have had no success with opening a serial port (device is a Prolific USB
> to serial comm port [COM9]) from Jython (2.7) using PySerial (tried both 2.7
> and 3.1.1) and the RXTX replacement for javax.comm on windows 64 bit.  I
> have tried the usual googling for examples but found no really helpful
> jython specific ones.  If anyone has an example program that works, I should
> be really grateful to see it!
>
> It all works fine in Python 2.7 !
>
> Thanks in advance,
>
> Graham
>
> (Apologies if this is posted twice)
>
>
> ------------------------------------------------------------------------------
> _______________________________________________
> Jython-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/jython-users

------------------------------------------------------------------------------
_______________________________________________
Jython-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: PySerial & RXTX query

Corgi
Thanks, I've added two listings:
Python 2.7
import sys, socket, serial
ser = serial.Serial(port="COM9",baudrate=9600)
if ser.is_open:
    ser.close()
    print "Closed"
ser.open() #open port
print(ser.portstr) # confirm which port was really used
s="Test"
ser.write(s)
print "written:",s

This works fine and I can see the data being written to the port.

Jython 2.7
import sys, socket, serial, gnu.io
ser = serial.Serial(port="COM9",baudrate=9600)
if ser.is_open:
    ser.close()
    print "Closed"
ser.open() #open port
print(ser.portstr) # confirm which port was really used
s="Test"
ser.write(s)
print "written:",s

This fails with the following trace back

Traceback (most recent call last):
File "C:\jee-neon\eclipse\workspace\JythonTest\src\Jython_USB_232.py", line
9, in <module>
ser = serial.Serial(port="COM9",baudrate=9600)
File "C:\jython2.7.0\Lib\site-packages\serial\serialutil.py", line 182, in
__init__
self.open()
File "C:\jython2.7.0\Lib\site-packages\serial\serialjava.py", line 69, in
open
portId = comm.CommPortIdentifier.getPortIdentifier(self._port)
at
javax.comm.CommPortIdentifier.getPortIdentifier(CommPortIdentifier.java:105)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
javax.comm.NoSuchPortException: javax.comm.NoSuchPortException

It all seems to be to do with javax.comm and its replacement (in theory) by
gnu.io (RXTX)
The RXTX jar is in the JRE and pythonpath and is the 64 bit version also
installed is the serial.dll that is required.

Any help gratefully appreciated - I'm sure it's something very simple that
I've misunderstood!

Graham


----- Original Message -----
From: "Adam Burke" <[hidden email]>
To: "Corgi" <[hidden email]>
Cc: <[hidden email]>
Sent: Saturday, September 24, 2016 9:25 AM
Subject: Re: [Jython-users] PySerial & RXTX query


Hi, do you get exceptions, or can you share a simple test program?

Adam

> 在 24 Sep 2016,4:15 PM,Corgi <[hidden email]> 写道:
>
> I have had no success with opening a serial port (device is a Prolific USB
> to serial comm port [COM9]) from Jython (2.7) using PySerial (tried both
> 2.7
> and 3.1.1) and the RXTX replacement for javax.comm on windows 64 bit.  I
> have tried the usual googling for examples but found no really helpful
> jython specific ones.  If anyone has an example program that works, I
> should
> be really grateful to see it!
>
> It all works fine in Python 2.7 !
>
> Thanks in advance,
>
> Graham
>
> (Apologies if this is posted twice)
>
>
> ------------------------------------------------------------------------------
> _______________________________________________
> Jython-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/jython-users 


------------------------------------------------------------------------------
_______________________________________________
Jython-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: PySerial & RXTX query

Corgi
Thanks, I've now sorted out how to use the RXTX module!

I'll post a listing shortly.

Graham

------------------------------------------------------------------------------
_______________________________________________
Jython-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: PySerial & RXTX query

Corgi
Here's a listing to demonstrate serial port connection
with Jython and the RXTX module.
Much more needs to be done to make it a useful
program but it demonstrates the key points
to make a connection!
Hope this helps anyone just starting out on a similar project.

Graham

#Jython.py Serial Port connection with RXTX

import sys, socket, gnu.io
import gnu.io.RXTXPort as RXTX

#Open port COM3
portId=gnu.io.CommPortIdentifier.getPortIdentifier("COM3")
serialPort=portId.open("Demo1",2000)        #(Name,delay)

#Set port parameters
serialPort.setSerialPortParams(9600,RXTX.DATABITS_8,RXTX.STOPBITS_1,RXTX.PARITY_NONE)

#Open input & output streams
outStream=serialPort.getOutputStream()
inStream=serialPort.getInputStream()

#Define some output and write it to the serial port
toOutput="Test output to serial port"
outStream.write(toOutput)

#Close inStream, outStream before closing the port itself
outStream.close()
inStream.close()
serialPort.close()


----- Original Message -----
From: "Corgi" <[hidden email]>
To: <[hidden email]>
Sent: Monday, September 26, 2016 8:54 AM
Subject: Re: [Jython-users] PySerial & RXTX query


> Thanks, I've now sorted out how to use the RXTX module!
>
> I'll post a listing shortly.
>
> Graham
>
> ------------------------------------------------------------------------------
> _______________________________________________
> Jython-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/jython-users 


------------------------------------------------------------------------------
_______________________________________________
Jython-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-users
Loading...