我最近下载了一些需要用python文件更改到目录的软件,并在终端中运行Arrays.asList(s1)
。
然后通过尝试package oracle.forms.demo;
import jssc.SerialPortEvent;
import jssc.SerialPortEventListener;
import jssc.SerialPort;
import jssc.SerialPortException;
import oracle.forms.handler.IHandler;
import oracle.forms.ui.CustomEvent;
import oracle.forms.properties.ID;
import oracle.forms.ui.VBean;
public class Comm extends VBean{
static IHandler mHandler;
static SerialPort serialPort;
int com_port;
int baud_rate;
int scale_parity;
int scale_databits;
int scale_stop_bits;
boolean scale_dtr;
boolean scale_rts;
String scale_command;
int scale_time_out;
//protected static final ID SETPROPS = ID.registerProperty("SETPROPS");
protected static final ID GETDATA = ID.registerProperty("GETDATA");
protected static final ID SETPORT = ID.registerProperty("SETPORT");
protected static final ID SETBAUD = ID.registerProperty("SETBAUD");
protected static final ID SETPARITY = ID.registerProperty("SETPARITY");
protected static final ID SETDATABITS = ID.registerProperty("SETDATABITS");
protected static final ID SETSTOPBITS = ID.registerProperty("SETSTOPBITS");
protected static final ID SETDTR = ID.registerProperty("SETDTR");
protected static final ID SETRTS = ID.registerProperty("SETRTS");
protected static final ID SETCOMMAND = ID.registerProperty("SETCOMMAND");
protected static final ID SETTIMEOUT = ID.registerProperty("SETTIMEOUT");
// events you can raise
protected static final ID EVT_01 = ID.registerProperty("EVT_01");
public Comm()
{
super();
}
public void init(IHandler handler)
{
super.init(handler);
mHandler = handler;
// put your initialisation instructions here
}
/**
* Get the properties of the bean
**/
public boolean setProperty(ID property, Object value)
{
if (property == SETPORT)
{
com_port = Integer.parseInt((String)value);
System.out.println("In RSET_PORT");
return true;
}
else if(property == SETBAUD)
{
baud_rate = Integer.parseInt((String)value);
System.out.println("In SET_BAUD");
return true;
}
else if (property == SETPARITY)
{
scale_parity = Integer.parseInt((String)value);
return true;
}
else if (property == SETDATABITS)
{
scale_parity = Integer.parseInt((String)value);
System.out.println("In DATA_BITS");
return true;
}
else if (property == SETSTOPBITS)
{
scale_stop_bits = Integer.parseInt((String)value);
System.out.println("In SET_STOP_BITS");
return true;
}
else if(property == SETDTR)
{
if (Integer.parseInt((String)value) == 0)
{
scale_dtr = false;
System.out.println("In DTR");
return true;
}
else
{
scale_dtr = true;
System.out.println("In DTR");
return true;
}
}
else if(property == SETRTS)
{
if(Integer.parseInt((String)value) == 0)
{
scale_rts = false;
System.out.println("In RTS");
return true;
}
else
{
scale_rts = true;
System.out.println("In RTS");
return true;
}
}
else if(property == SETCOMMAND)
{
scale_command = (String)value;
System.out.println("In SET_COMMAND");
return true;
}
else if(property == SETTIMEOUT)
{
scale_time_out = Integer.parseInt((String)value);
System.out.println("In SET_TIME_OUT");
return true;
}
else // default behaviour
{
return super.setProperty(property, value);
}
}
/**
* Get the properties of the bean
**/
public Object getProperty(ID property)
{
if(property == GETDATA){
System.out.println("Running comProp");
System.out.println("com_port: " + com_port);
System.out.println("baud_rate: " + baud_rate);
System.out.println("scale_parity: " + scale_parity);
System.out.println("scale_databits: " + scale_databits);
System.out.println("scale_stop_bits: " + scale_stop_bits);
System.out.println("scale_dtr: " + scale_dtr);
System.out.println("scale_rts: " + scale_rts);
System.out.println("scale_command: " + scale_command);
System.out.println("scale_time_out: " + scale_time_out);
System.out.println("Serialport");
SerialPort serialPort = new SerialPort("COM1");
boolean leave = false;
int i = 1;
String str = null;
System.out.println("while loop");
//In the constructor pass the name of the port with which we work
while(leave == false){
try
{
serialPort.openPort();
serialPort.setParams(baud_rate,scale_parity,scale_databits,scale_stop_bits, scale_rts, scale_dtr);
serialPort.writeString(scale_command + (char)13 + (char)10);
str = serialPort.readString(i,scale_time_out );
i = i + 1;
serialPort.closePort();
}
catch (Exception exc)
{
//System.out.println(exc);
leave = true;
//System.out.println("Length: " + (i-1));
System.out.println("String: "+ str);
}
}
return str;
}
else
{
return super.getProperty(property);
}
}
public void dispatch_event( ID id )
{
CustomEvent ce = new CustomEvent(mHandler, id);
dispatchCustomEvent(ce);
}
}
这适用于我的终端。但是,当我在笔记本中尝试Exception in thread "AWT-EventQueue-3" java.lang.ExceptionInInitializerError
at jssc.SerialPort.<init>(SerialPort.java:120)
at oracle.forms.demo.Comm.getProperty(Comm.java:151)
at oracle.forms.handler.UICommon.onGet(Unknown Source)
at oracle.forms.engine.Runform.onGetHandler(Unknown Source)
at oracle.forms.engine.Runform.processMessage(Unknown Source)
at oracle.forms.engine.Runform.processSet(Unknown Source)
at oracle.forms.engine.Runform.onMessageReal(Unknown Source)
at oracle.forms.engine.Runform.onMessage(Unknown Source)
at oracle.forms.engine.Runform.processEventEnd(Unknown Source)
at oracle.ewt.lwAWT.LWComponent.redispatchEvent(Unknown Source)
at oracle.ewt.lwAWT.LWComponent.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.security.AccessControlException: access denied (java.util.PropertyPermission user.home read)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPropertyAccess(Unknown Source)
at java.lang.System.getProperty(Unknown Source)
at jssc.SerialNativeInterface.<clinit>(SerialNativeInterface.java:85)
... 26 more
时,它永远不会起作用。所以,这让我觉得我必须在iPython笔记本中安装python setup.py install --user
文件。
如何做到这一点?
答案 0 :(得分:0)
不,在终端中安装python模块就足够了。在IPython笔记本中没有安装这样的东西。
安装完成后,只需重新启动IPython笔记本即可。如果它仍然不起作用,你可能没有在两者之间使用相同的python解释器:check python version(CheckChanged
),确保你没有使用虚拟环境,并且which python
不是某种程度上不同,等等。
答案 1 :(得分:0)
您可能使用的是错误版本的iPython笔记本。
也许您一直在使用ipython notebook
代替ipython3 notebook
,反之亦然。如果Python2.7包含您想要的包,那么如果您尝试将其导入sudo pip3 install package_name
,它将无法运行。
如果版本不匹配,那么您通常可以使用sudo pip install package_name
或sudo apt-get install python3-pip
获取相关包,具体取决于您想要的版本。
当然pip可以通过{3}获得Python 3,sudo apt-get install python-pip
获得Python2.7。