Fix: Linux Native Serial IO
parent
c6f2f57919
commit
769f93c8eb
Binary file not shown.
|
@ -18,7 +18,7 @@ public class NativeSerialPort extends SerialPort {
|
||||||
@Override
|
@Override
|
||||||
public int read() throws IOException {
|
public int read() throws IOException {
|
||||||
if (!isOpen())
|
if (!isOpen())
|
||||||
throw new IOException("Port nicht gešffnet!");
|
throw new IOException("Port nicht ge<EFBFBD>ffnet!");
|
||||||
|
|
||||||
int ch = native_getch(nativeHandle,getTimeout());
|
int ch = native_getch(nativeHandle,getTimeout());
|
||||||
//System.err.println(String.format("RX: 0x%08x", ch));
|
//System.err.println(String.format("RX: 0x%08x", ch));
|
||||||
|
@ -34,7 +34,7 @@ public class NativeSerialPort extends SerialPort {
|
||||||
@Override
|
@Override
|
||||||
public void write(int arg0) throws IOException {
|
public void write(int arg0) throws IOException {
|
||||||
if (!isOpen())
|
if (!isOpen())
|
||||||
throw new IOException("Port nicht gešffnet!");
|
throw new IOException("Port nicht ge<EFBFBD>ffnet!");
|
||||||
//System.err.println(String.format("TX: 0x%08x", arg0));
|
//System.err.println(String.format("TX: 0x%08x", arg0));
|
||||||
native_putch(nativeHandle, getTimeout(), arg0);
|
native_putch(nativeHandle, getTimeout(), arg0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ public class ServiceRegisterCache {
|
||||||
public IntegerCacheItem(int ax,int node,int register)
|
public IntegerCacheItem(int ax,int node,int register)
|
||||||
{
|
{
|
||||||
super(ax,node,register);
|
super(ax,node,register);
|
||||||
intValue = 0;
|
intValue = null;
|
||||||
}
|
}
|
||||||
Integer intValue;
|
Integer intValue;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,127 @@
|
||||||
|
package org.hwo.io.servicelink.register;
|
||||||
|
|
||||||
|
import java.awt.Component;
|
||||||
|
import java.awt.event.FocusEvent;
|
||||||
|
import java.awt.event.FocusListener;
|
||||||
|
import java.math.BigInteger;
|
||||||
|
import java.util.Hashtable;
|
||||||
|
|
||||||
|
import javax.swing.JComboBox;
|
||||||
|
import javax.swing.JComponent;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JTextField;
|
||||||
|
|
||||||
|
import org.hwo.io.servicelink.ServiceLink;
|
||||||
|
import org.hwo.ui.JComboBoxEx;
|
||||||
|
|
||||||
|
import java.awt.GridBagLayout;
|
||||||
|
import java.awt.GridBagConstraints;
|
||||||
|
|
||||||
|
public class IndexedListRegisterEditor extends JPanel implements ServiceRegisterControl {
|
||||||
|
|
||||||
|
public static class IndexedItem {
|
||||||
|
private Integer index;
|
||||||
|
private String label;
|
||||||
|
|
||||||
|
public IndexedItem(Integer index,String label) {
|
||||||
|
this.index = index;
|
||||||
|
this.label = label;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return String.format("%d: %s", this.index, this.label);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getIndex() {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIndex(Integer index) {
|
||||||
|
this.index = index;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLabel() {
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLabel(String label) {
|
||||||
|
this.label = label;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
private ServiceRegister serviceRegister;
|
||||||
|
private JComboBoxEx cbValue;
|
||||||
|
|
||||||
|
private IndexedItem[] items;
|
||||||
|
|
||||||
|
|
||||||
|
public IndexedListRegisterEditor()
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
GridBagLayout gridBagLayout = new GridBagLayout();
|
||||||
|
gridBagLayout.columnWidths = new int[]{0, 0};
|
||||||
|
gridBagLayout.rowHeights = new int[]{0, 0};
|
||||||
|
gridBagLayout.columnWeights = new double[]{1.0, Double.MIN_VALUE};
|
||||||
|
gridBagLayout.rowWeights = new double[]{0.0, Double.MIN_VALUE};
|
||||||
|
setLayout(gridBagLayout);
|
||||||
|
|
||||||
|
cbValue = new JComboBoxEx();
|
||||||
|
GridBagConstraints gbc_tfValue = new GridBagConstraints();
|
||||||
|
gbc_tfValue.fill = GridBagConstraints.HORIZONTAL;
|
||||||
|
gbc_tfValue.gridx = 0;
|
||||||
|
gbc_tfValue.gridy = 0;
|
||||||
|
add(cbValue, gbc_tfValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Component getComponent() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setServiceRegister(ServiceRegister serviceRegister) {
|
||||||
|
this.serviceRegister = serviceRegister;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeValue() {
|
||||||
|
this.serviceRegister.writeIntegerValue(((IndexedItem)cbValue.getSelectedItem()).getIndex());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readValue() {
|
||||||
|
Integer i = this.serviceRegister.readIntegerValue();
|
||||||
|
if ( i == null )
|
||||||
|
i = 0;
|
||||||
|
|
||||||
|
for (IndexedItem item : items) {
|
||||||
|
if (item.getIndex().equals(i)) {
|
||||||
|
cbValue.setSelectedItem(item);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
IndexedItem item = new IndexedItem(i, "Unkown Index");
|
||||||
|
cbValue.setSelectedItem(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean requestFocusInWindow() {
|
||||||
|
return cbValue.requestFocusInWindow();
|
||||||
|
}
|
||||||
|
|
||||||
|
public IndexedItem[] getItems() {
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setItems(IndexedItem[] items) {
|
||||||
|
this.items = items;
|
||||||
|
|
||||||
|
cbValue.removeAllItems();
|
||||||
|
for (IndexedItem item: items){
|
||||||
|
cbValue.addItem(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,76 @@
|
||||||
|
package org.hwo.io.servicelink.register;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Hashtable;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
|
||||||
|
import javax.swing.JComponent;
|
||||||
|
|
||||||
|
import org.hwo.bitfields.BitField;
|
||||||
|
import org.hwo.io.servicelink.ServiceLink;
|
||||||
|
import org.hwo.io.servicelink.register.IndexedListRegisterEditor.IndexedItem;
|
||||||
|
import org.hwo.xml.NodeListIterator;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
|
public class IndexedListServiceRegister extends ServiceRegister {
|
||||||
|
|
||||||
|
IndexedListRegisterEditor editor;
|
||||||
|
Hashtable<Integer, IndexedItem> items;
|
||||||
|
|
||||||
|
public IndexedListServiceRegister(ServiceLink serviceLink)
|
||||||
|
{
|
||||||
|
super(serviceLink);
|
||||||
|
editor = new IndexedListRegisterEditor();
|
||||||
|
editor.setServiceRegister(this);
|
||||||
|
|
||||||
|
items = new Hashtable<Integer, IndexedListRegisterEditor.IndexedItem>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setRegisterNode(Element registerNode) {
|
||||||
|
super.setRegisterNode(registerNode);
|
||||||
|
|
||||||
|
Element listNode = (Element)registerNode.getElementsByTagName("List").item(0);
|
||||||
|
|
||||||
|
LinkedList<IndexedItem> items = new LinkedList<IndexedListRegisterEditor.IndexedItem>();
|
||||||
|
|
||||||
|
for (Element listItem: new NodeListIterator(listNode.getElementsByTagName("Item"))){
|
||||||
|
IndexedItem item = new IndexedItem(Integer.parseInt(listItem.getAttribute("index")), listItem.getTextContent());
|
||||||
|
items.add(item);
|
||||||
|
this.items.put(item.getIndex(), item);
|
||||||
|
}
|
||||||
|
editor.setItems(items.toArray(new IndexedItem[0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
private IndexedItem getIndexedItem(Integer index) {
|
||||||
|
if (this.items.containsKey(index)) {
|
||||||
|
return this.items.get(index);
|
||||||
|
}
|
||||||
|
IndexedItem unknown = new IndexedItem(index, "Unkown");
|
||||||
|
return unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTextRepresentation() {
|
||||||
|
Integer i = readIntegerValue();
|
||||||
|
if (i == null)
|
||||||
|
return "";
|
||||||
|
return getIndexedItem(i).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JComponent getEditorComponent() {
|
||||||
|
return editor;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void acceptEditorValue() {
|
||||||
|
editor.writeValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateEditorValue() {
|
||||||
|
editor.readValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -155,7 +155,7 @@ public abstract class ServiceRegister {
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
this.serviceLink.writeFloat(ax.byteValue(), node.byteValue(), register.shortValue(),value);
|
this.serviceLink.writeFloat(ax.byteValue(), node.byteValue(), register,value);
|
||||||
} catch (Exception e)
|
} catch (Exception e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -183,6 +183,7 @@ public abstract class ServiceRegister {
|
||||||
serviceRegisterTypes.put("Integer", IntegerServiceRegister.class);
|
serviceRegisterTypes.put("Integer", IntegerServiceRegister.class);
|
||||||
serviceRegisterTypes.put("Float", FloatServiceRegister.class);
|
serviceRegisterTypes.put("Float", FloatServiceRegister.class);
|
||||||
serviceRegisterTypes.put("BitField", BitFieldServiceRegister.class);
|
serviceRegisterTypes.put("BitField", BitFieldServiceRegister.class);
|
||||||
|
serviceRegisterTypes.put("IndexedList", IndexedListServiceRegister.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue