Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions src/main/java/modbuspal/binding/Binding.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import modbuspal.automation.AutomationExecutionListener;
import modbuspal.instanciator.Instantiable;
import modbuspal.slave.ModbusRegisters;
import modbuspal.slave.ModbusExtendedRegisters;

/**
* Defines a binding
Expand All @@ -28,6 +29,7 @@ public Object clone() throws CloneNotSupportedException {
private Automation automation;
private int order;
private ModbusRegisters registers;
private ModbusExtendedRegisters extendedRegisters;
private int registerAddress;

/** creates a new instance. */
Expand Down Expand Up @@ -60,6 +62,20 @@ public final void attach(ModbusRegisters l, int address)
automation.addAutomationExecutionListener(this);
}

/**
* This method is called by ModbusRegisters. It should not be called
* directly. Its purpose is to define which register is the target
* of the binding.
* @param l reference on the modbus registers to look into
* @param address address of the register that is the target of the binding
*/
public final void attachExtendedRegisters(ModbusExtendedRegisters l, int address)
{
extendedRegisters = l;
registerAddress = address;
automation.addAutomationExecutionListener(this);
}


/**
* This method is called by ModbusRegisters. It should not be called
Expand All @@ -72,6 +88,17 @@ public final void detach()
automation.removeAutomationExecutionListener(this);
}

/**
* This method is called by ModbusRegisters. It should not be called
* directly. Its purpose is to undefine which register is the target
* of the binding.
*/
public final void detachExtendedRegisters()
{
extendedRegisters=null;
automation.removeAutomationExecutionListener(this);
}

@Override
public void automationValueHasChanged(Automation source, double time, double value)
{
Expand Down Expand Up @@ -142,7 +169,7 @@ public final int getRegister()

/**
* Process the specified value and return the 16-word register corresponding
* to the requested order.
* to the requested order.
* @param order the rank of the 16-word register to return, depending of the
* mapping implemented by this binding.
* @param value the value to process
Expand All @@ -164,7 +191,7 @@ public final boolean getCoil()

/**
* Process the specified value and return the boolean value (coil) corresponding
* to the requested order.
* to the requested order.
* @param order the rank of the boolean (coil) to return, depending of the
* mapping implemented by this binding.
* @param value the value to process
Expand All @@ -186,7 +213,7 @@ public String toString()
}

/**
* Returns the name of the automation that
* Returns the name of the automation that
* has been associated to this binding by
* calling the setup() method.
* @return the name of the automation
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/modbuspal/main/ModbusConst.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* Defines the subset of the MODBUS specification that is currently
* supported by ModbusPal.
*
*
* @author nnovic
*/
public interface ModbusConst
Expand All @@ -20,6 +20,9 @@ public interface ModbusConst
public static final byte FC_WRITE_SINGLE_REGISTER = (byte)0x06;
public static final byte FC_WRITE_MULTIPLE_COILS = (byte)0x0F;
public static final byte FC_WRITE_MULTIPLE_REGISTERS = (byte)0x10;
public static final byte FC_READ_FILE_RECORD = (byte)0x14;
public static final byte FC_READ_EXTENDED_REGISTERS = (byte)0x14;
public static final byte FC_WRITE_FILE_RECORD = (byte)0x15;
public static final byte FC_READ_WRITE_MULTIPLE_REGISTERS = (byte)0x17;

public static final byte XC_SUCCESSFUL = (byte)0x00;
Expand Down
73 changes: 37 additions & 36 deletions src/main/java/modbuspal/main/ModbusPalPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ public class ModbusPalPane
{
/** Name and version of this application */
public static final String APP_STRING = "ModbusPal 1.6b";

/** Base registry key for the configuration of the application. */
public static final String BASE_REGISTRY_KEY = "modbuspal";

private ArrayList<ModbusPalProjectListener> listeners = new ArrayList<ModbusPalProjectListener>();

private ModbusMasterDialog modbusMasterDialog = null;
ScriptManagerDialog scriptManagerDialog = null;
private ModbusLink currentLink = null;
Expand Down Expand Up @@ -141,7 +141,7 @@ public void setProject(ModbusPalProject project)
// Init record/replay settings
setReplayFile(project.linkReplayFile);


//- - - - - - - - - - - - - -
// Refresh list of slaves
//- - - - - - - - - - - - - -
Expand Down Expand Up @@ -171,13 +171,13 @@ public void setProject(ModbusPalProject project)
{
scriptManagerDialog.setProject(modbusPalProject);
}

// Refresh MASTER
if( modbusMasterDialog!=null)
{
modbusMasterDialog.setProject(modbusPalProject);
}

System.out.printf("[%s] Project set\r\n", modbusPalProject.getName());

notifyModbusPalProjectChanged(old, modbusPalProject);
Expand Down Expand Up @@ -388,17 +388,17 @@ private void installCommPorts()
CardLayout layout = (CardLayout)jPanel1.getLayout();
layout.show(jPanel1, "disabled");
return;
}
}

// detect the comm ports
ModbusSerialLink.enumerate();

// get the list of comm ports (as strings)
// and put it in the swing list
comPortComboBox.setModel( ModbusSerialLink.getListOfCommPorts() );
}





Expand All @@ -423,7 +423,7 @@ public void pduNotServiced()
}



/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
Expand Down Expand Up @@ -940,7 +940,7 @@ private void startSerialLink(boolean isMaster)
{
int commPortIndex = comPortComboBox.getSelectedIndex();
currentLink = new ModbusSerialLink(modbusPalProject, commPortIndex, baudrate, parity, stopBits, xonxoff, rtscts);

if(isMaster)
{
currentLink.startMaster(this);
Expand All @@ -949,7 +949,7 @@ private void startSerialLink(boolean isMaster)
{
currentLink.start(this);
}

((TiltLabel)tiltLabel).start();
}
catch (Exception ex)
Expand All @@ -966,7 +966,7 @@ private void startSerialLink(boolean isMaster)
}

}

private void startTcpIpLink(boolean isMaster)
{
//portTextField.setEnabled(false);
Expand All @@ -991,7 +991,7 @@ private void startTcpIpLink(boolean isMaster)
{
System.out.printf("[%s] Start TCP/link (port=%d)\r\n", modbusPalProject.getName(), port);
currentLink = new ModbusTcpIpLink(modbusPalProject, port);

if( isMaster )
{
currentLink.startMaster(this);
Expand All @@ -1000,7 +1000,7 @@ private void startTcpIpLink(boolean isMaster)
{
currentLink.start(this);
}

((TiltLabel)tiltLabel).start();
}
catch (Exception ex)
Expand All @@ -1016,7 +1016,7 @@ private void startTcpIpLink(boolean isMaster)
return;
}
}

private void startReplayLink(boolean isMaster)
{
File recordFile = null;
Expand All @@ -1030,7 +1030,7 @@ private void startReplayLink(boolean isMaster)
try
{
currentLink = new ModbusReplayLink(modbusPalProject, recordFile);

if(isMaster)
{
currentLink.startMaster(this);
Expand All @@ -1039,7 +1039,7 @@ private void startReplayLink(boolean isMaster)
{
currentLink.start(this);
}

((TiltLabel)tiltLabel).start();
}
catch (Exception ex)
Expand All @@ -1066,7 +1066,7 @@ public void startLink()

masterToggleButton.setEnabled(false);
boolean isMaster = masterToggleButton.isSelected();

// if link is tcp/ip
if( linksTabbedPane.getSelectedComponent()==tcpIpSettingsPanel )
{
Expand All @@ -1089,7 +1089,7 @@ else if( linksTabbedPane.getSelectedComponent()==replaySettingsPanel )
{
throw new UnsupportedOperationException("not yet implemented");
}

if(isMaster)
{
// start the master
Expand All @@ -1106,14 +1106,14 @@ public void stopLink()
{
System.out.printf("[%s] Stop link\r\n", modbusPalProject.getName());
boolean isMaster = masterToggleButton.isSelected();


if(isMaster)
{
// stop the master
modbusMasterDialog.stop();
}

if( currentLink != null )
{
if(isMaster)
Expand All @@ -1127,16 +1127,16 @@ public void stopLink()
((TiltLabel)tiltLabel).stop();
currentLink = null;
}

if(modbusMasterDialog!=null)
{
if( modbusMasterDialog.isRunning() )
{
modbusMasterDialog.stop();
}
}


masterToggleButton.setEnabled(true);
GUITools.setAllEnabled(linksTabbedPane,true);
}
Expand Down Expand Up @@ -1189,6 +1189,7 @@ private void addModbusSlaveButtonActionPerformed(java.awt.event.ActionEvent evt)
{
ModbusSlave slave = new ModbusSlave(ids[i]);
slave.setName(name);
Logger.getLogger(ModbusPalPane.class.getName()).log(Level.SEVERE, slave.getName(), "Hello");
modbusPalProject.addModbusSlave(slave);
}
}
Expand Down Expand Up @@ -1259,7 +1260,7 @@ private void saveProjectButtonActionPerformed(java.awt.event.ActionEvent evt) {/
* @throws SAXException
* @throws IOException
* @throws InstantiationException
* @throws IllegalAccessException
* @throws IllegalAccessException
*/
public ModbusPalProject loadProject(String path)
throws ParserConfigurationException, SAXException, IOException, InstantiationException, IllegalAccessException
Expand Down Expand Up @@ -1314,7 +1315,7 @@ private void loadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FI


private void addAutomationButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addAutomationButtonActionPerformed

String name = Automation.DEFAULT_NAME + " #" + String.valueOf( modbusPalProject.idGenerator.createID() );
Automation automation = new Automation( name );
modbusPalProject.addAutomation(automation);
Expand Down Expand Up @@ -1648,7 +1649,7 @@ public void windowClosing(WindowEvent e)
public void windowClosed(WindowEvent e)
{
Object source = e.getSource();

if( source==modbusMasterDialog )
{
masterToggleButton.setSelected(false);
Expand Down Expand Up @@ -1717,7 +1718,7 @@ public void modbusSlaveRemoved(ModbusSlave slave)
ModbusSlaveAddress slaveID = slave.getSlaveId();

ModbusSlavePanel panel = findModbusSlavePanel(slaveID);

if( panel != null )
{
// the dialog will be disconnect, so remove it to:
Expand Down Expand Up @@ -1803,7 +1804,7 @@ public void linkBroken()
public void exit()
{
stopAll();

try {
// stop recorder
ModbusPalRecorder.stop();
Expand Down Expand Up @@ -1845,11 +1846,11 @@ public void showScriptManagerDialog()
}

/**
* Shows or hides the the Slaves list. Some applications that embbeds
* Shows or hides the the Slaves list. Some applications that embbeds
* ModbusPal might find it nice to hide this list.
* @param b true to show the slaves list. false to hide it.
*/
public void setSlavesListVisible(boolean b)
public void setSlavesListVisible(boolean b)
{
slavesListView.setVisible(b);
}
Expand Down Expand Up @@ -1922,13 +1923,13 @@ public void run()
}

@Override
public void modbusMasterTaskRemoved(ModbusMasterTask mmt)
public void modbusMasterTaskRemoved(ModbusMasterTask mmt)
{
//
}

@Override
public void modbusMasterTaskAdded(ModbusMasterTask mmt)
public void modbusMasterTaskAdded(ModbusMasterTask mmt)
{
//
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/modbuspal/main/ModbusPalXML.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public interface ModbusPalXML

/* REGISTER */
public static final String XML_HOLDING_REGISTERS_TAG = "holding_registers";
public static final String XML_EXTENDED_REGISTERS_TAG = "extended_registers";
public static final String XML_ADDRESS_ATTRIBUTE = "address";

/* COILS */
Expand Down
Loading