📄 talsim.java
字号:
/* * Created on 12.04.2004 * * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments */package simhw;import java.io.*;import javax.comm.*;import com.jopdesign.sys.Const;/** * @author martin * * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments */public class TALSim extends BaseSim { private String portName = null; private CommPortIdentifier portId; private InputStream is = null; private OutputStream os = null; private SerialPort serialPort; private TALWindow twin; /** * */ public TALSim() { super(); twin = new TALWindow(); twin.setTsim(this);setPortName("COM4"); } private void openSerialPort() { try { if (portId!=null) { try { is.close(); os.close(); is = null; os = null; } catch (Exception e1) { } serialPort.close(); } portId = CommPortIdentifier.getPortIdentifier(portName); serialPort = (SerialPort) portId.open(getClass().toString(), 2000); serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_RTSCTS_OUT | SerialPort.FLOWCONTROL_RTSCTS_IN); serialPort.setSerialPortParams(115200, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); is = serialPort.getInputStream(); os = serialPort.getOutputStream(); } catch (Exception e) { is = null; os = null; System.out.println("Problem with serial port "+portName); System.out.println(e.getMessage()); // System.exit(-1); } } public int rd(int address) { int i = 0; switch (address) { case Const.IO_STATUS: case Const.IO_STATUS2: i = 0; if (is!=null) { try { if (is.available()!=0) i |= Const.MSK_UA_RDRF; } catch (IOException e1) { e1.printStackTrace(); } // rdrf } i |= Const.MSK_UA_TDRE; // tdre is alwais true on OutputStream return i; case Const.IO_UART:// System.out.println("Native: read() '"+(char) i+"'"); break; case Const.IO_UART2: try { i = is.read(); } catch (IOException e) { e.printStackTrace(); } return i; case Const.IO_IN: return twin.getInPort(); case Const.IO_ADC1: return twin.getAdc1(); case Const.IO_ADC2: return twin.getAdc2(); case Const.IO_ADC3: return twin.getAdc3(); default: return super.rd(address); } return 0; } public void wr(int val, int address) { switch (address) { case Const.IO_STATUS:System.out.println("setDTR on System.out()! "+val); break; case Const.IO_UART: System.out.print((char) val); // debug serial break; case Const.IO_STATUS2:System.out.println("setDTR "+val); if (serialPort!=null) { serialPort.setDTR(val==1); try { if ((val&0x04)==0) { serialPort.setSerialPortParams(2400, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); } else { serialPort.setSerialPortParams(115200, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); } if ((val&0x02)==0) { serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_NONE); } else { serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_RTSCTS_OUT | SerialPort.FLOWCONTROL_RTSCTS_IN); } } catch (UnsupportedCommOperationException e1) { e1.printStackTrace(); } } break; case Const.IO_UART2: if (os==null) return; try { os.write(val); } catch (IOException e) { e.printStackTrace(); } break; case Const.IO_WD: twin.setWd(val!=0); break; case Const.IO_OUT: twin.setOutPort(val); break; case Const.IO_LED: twin.setLedPort(val); break; default : super.wr(val, address); break; } } /** * @return */ public String getPortName() { return portName; } /** * @param string */ public void setPortName(String string) {System.out.println("set port: "+string); portName = string; openSerialPort(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -