Modbus Serial Master Jamod Write
- Modbus Serial Master Jamod Writer
- Serial Master Collection Cs6
- Serial Master Collection Cs5
- Dnp3 Serial Master Tester
- Modbus is a serial communications protocol published by Modicon in 1979 for use with its programmable logic controllers (PLCs). It has become a de facto standard communications protocol in industry, and is now the most commonly available means of connecting industrial electronic devices.
- This document is a tutorial for writing Modbus/Serial Slave applications utilizing the jamod library. It explains the basics and walk's you through a simple command line Slave implementation,that will serve the values from a static process image on Master requests.
- The following example SerSimple.java shows how to configure a serial Modbus protocol and read values. // Write data set 3 to. ('FieldTalk(tm) Modbus Master.
- Modbus serial RTU simulator. Compiles with Visual C++ 6.0, and runs on Windows 2000 and probably 95/98.• The FieldTalk(tm) utility modpoll is a command line based Modbus master simulator and test utility.
Jamod (Java Modbus Library) is a pure Java library that can be used to implement Modbus Master and Slave both in IP and serial transport flavours. Bvh files breakdance competition. The library is well documented as it provides both complete API documentation and guidelines on how to use jamod.
PermalinkJoin GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Modbus Serial Master Jamod Writer
Sign up Find file Copy path
Serial Master Collection Cs6
Cannot retrieve contributors at this time
Serial Master Collection Cs5
/*** |
* Copyright 2002-2010 jamod development team |
* |
* Licensed under the Apache License, Version 2.0 (the 'License'); |
* you may not use this file except in compliance with the License. |
* You may obtain a copy of the License at |
* |
* http://www.apache.org/licenses/LICENSE-2.0 |
* |
* Unless required by applicable law or agreed to in writing, software |
* distributed under the License is distributed on an 'AS IS' BASIS, |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
* See the License for the specific language governing permissions and |
* limitations under the License. |
* |
* Original implementation by jamod development team. |
* This file modified by Charles Hache <chache@brood.ca> |
***/ |
packagenet.wimpi.modbus.io; |
importnet.wimpi.modbus.Modbus; |
importnet.wimpi.modbus.ModbusException; |
importnet.wimpi.modbus.ModbusIOException; |
importnet.wimpi.modbus.ModbusSlaveException; |
importnet.wimpi.modbus.msg.ExceptionResponse; |
importnet.wimpi.modbus.msg.ModbusRequest; |
importnet.wimpi.modbus.msg.ModbusResponse; |
importnet.wimpi.modbus.net.SerialConnection; |
importnet.wimpi.modbus.util.AtomicCounter; |
importnet.wimpi.modbus.util.Mutex; |
/** |
* Class implementing the <tt>ModbusTransaction</tt> interface. |
* |
* @author Dieter Wimberger |
* @author Charles Hache |
* @version @version@ (@date@) |
*/ |
publicclassModbusSerialTransactionimplementsModbusTransaction { |
// class attributes |
privatestaticAtomicCounter c_TransactionID =newAtomicCounter( |
Modbus.DEFAULT_TRANSACTION_ID); |
// instance attributes and associations |
privateModbusTransport m_IO; |
privateModbusRequest m_Request; |
privateModbusResponse m_Response; |
privateboolean m_ValidityCheck =Modbus.DEFAULT_VALIDITYCHECK; |
privateint m_Retries =Modbus.DEFAULT_RETRIES; |
privateint m_TransDelayMS =Modbus.DEFAULT_TRANSMIT_DELAY; |
privateSerialConnection m_SerialCon; |
privateMutex m_TransactionLock =newMutex(); |
/** |
* Constructs a new <tt>ModbusSerialTransaction</tt> instance. |
*/ |
publicModbusSerialTransaction() { |
}// constructor |
/** |
* Constructs a new <tt>ModbusSerialTransaction</tt> instance with a given |
* <tt>ModbusRequest</tt> to be sent when the transaction is executed. |
* <p/> |
* |
* @param request |
* a <tt>ModbusRequest</tt> instance. |
*/ |
publicModbusSerialTransaction(ModbusRequestrequest) { |
setRequest(request); |
}// constructor |
/** |
* Constructs a new <tt>ModbusSerialTransaction</tt> instance with the given |
* <tt>SerialConnection</tt> |
* <p/> |
* |
* @param con |
* a <tt>SerialConnection</tt> instance. |
*/ |
publicModbusSerialTransaction(SerialConnectioncon) { |
setSerialConnection(con); |
}// constructor |
/** |
* Sets the serial connection on which this <tt>ModbusTransaction</tt> |
* should be executed. |
* <p> |
* <p/> |
* |
* @param con |
* a <tt>SerialConnection</tt>. |
*/ |
publicvoidsetSerialConnection(SerialConnectioncon) { |
m_SerialCon = con; |
m_IO = con.getModbusTransport(); |
}// setConnection |
publicintgetTransactionID() { |
return c_TransactionID.get(); |
}// getTransactionID |
publicvoidsetRequest(ModbusRequestreq) { |
m_Request = req; |
}// setRequest |
publicModbusRequestgetRequest() { |
return m_Request; |
}// getRequest |
publicModbusResponsegetResponse() { |
return m_Response; |
}// getResponse |
publicvoidsetCheckingValidity(booleanb) { |
m_ValidityCheck = b; |
}// setCheckingValidity |
publicbooleanisCheckingValidity() { |
return m_ValidityCheck; |
}// isCheckingValidity |
publicintgetRetries() { |
return m_Retries; |
}// getRetries |
publicvoidsetRetries(intnum) { |
m_Retries = num; |
}// setRetries |
/** |
* Get the TransDelayMS value. |
* |
* @return the TransDelayMS value. |
*/ |
publicintgetTransDelayMS() { |
return m_TransDelayMS; |
} |
/** |
* Set the TransDelayMS value. |
* |
* @param newTransDelayMS |
* The new TransDelayMS value. |
*/ |
publicvoidsetTransDelayMS(intnewTransDelayMS) { |
this.m_TransDelayMS = newTransDelayMS; |
} |
publicvoidexecute() throwsModbusIOException, ModbusSlaveException, |
ModbusException { |
// 1. assert executeability |
assertExecutable(); |
try { |
// 2. Lock transaction |
/** |
* Note: The way this explicit synchronization is implemented at the |
* moment, there is no ordering of pending threads. The Mutex will |
* simply call notify() and the JVM will handle the rest. |
*/ |
m_TransactionLock.acquire(); |
// 3. write request, and read response, |
// while holding the lock on the IO object |
synchronized (m_IO) { |
int tries =0; |
boolean finished =false; |
// toggle the id |
m_Request.setTransactionID(c_TransactionID.increment()); |
do { |
try { |
if (m_TransDelayMS >0) { |
try { |
Thread.sleep(m_TransDelayMS); |
} catch (InterruptedException ex) { |
System.err.println('InterruptedException: ' |
+ ex.getMessage()); |
} |
} |
// write request message |
m_IO.writeMessage(m_Request); |
// read response message |
m_Response = m_IO.readResponse(); |
m_Response.setReference(m_Request.getReference()); |
finished =true; |
} catch (ModbusIOException e) { |
if (++tries >= m_Retries) { |
throw e; |
} |
System.err.println('execute try '+ tries +' error: ' |
+ e.getMessage()); |
} |
} while (!finished); |
} |
// 4. deal with exceptions |
if (m_Response instanceofExceptionResponse) { |
thrownewModbusSlaveException( |
((ExceptionResponse) m_Response).getExceptionCode()); |
} |
if (isCheckingValidity()) { |
checkValidity(); |
} |
} catch (InterruptedException ex) { |
thrownewModbusIOException( |
'Thread acquiring lock was interrupted.'); |
} finally { |
m_TransactionLock.release(); |
} |
}// execute |
/** |
* Asserts if this <tt>ModbusSerialTransaction</tt> is executable. |
* |
* @throws ModbusException |
* if the transaction cannot be asserted. |
*/ |
privatevoidassertExecutable() throwsModbusException { |
if (m_Request null m_SerialCon null) { |
thrownewModbusException( |
'Assertion failed, transaction not executable'); |
} |
}// assertExecuteable |
/** |
* Checks the validity of the transaction, by checking if the values of the |
* response correspond to the values of the request. |
* |
* @throws ModbusException |
* if the transaction is not valid. |
*/ |
protectedvoidcheckValidity() throwsModbusException { |
}// checkValidity |
}// class ModbusSerialTransaction |
Dnp3 Serial Master Tester
Copy lines Copy permalink