steveohara / j2mod

Enhanced Modbus library implemented in the Java programming language
Apache License 2.0
267 stars 111 forks source link

jSerialComm library decoupled from implementation #28

Closed felHR85 closed 8 years ago

felHR85 commented 8 years ago

Hi @steveohara I want Modbus support for Android devices using the USB port and j2mod is the obvious starting point to begin with. I plan to use my library UsbSerial so decoupling jSerialComm was needed.

In this pull request I've added an abstract class called SerialConnectionInterface that represents an abstract serial port connection. I've respected jSerialComm constants for backwards compatibility.

All jSerialComm references are embedded inside a class inheriting SerialConnectionInterface called SerialConnection as the previous existing class to avoid compatibility issues.

The previous constructors and factory methods are the same, I just added a new constructor for ModbusSerialListener

public ModbusSerialListener(SerialParameters params, SerialConnectionInterface serialCon)

And a new createCustomModbusMaster method:

private static AbstractModbusTransport createCustomModbusMaster(String address, SerialConnectionInterface serialConnection)

I've made some tests and seems to be sending an receiving data but it would be very good if someone with more Modbus expertise could test it further.

Thanks! Felipe

steveohara commented 8 years ago

Hi Felipe,

This is great - the abstraction of the comms port was one of the casualties of the huge number of changes to get j2mod into a production fit state so I'm very happy to see it come back. This work will also resolve https://github.com/steveohara/j2mod/issues/3

I'm on holiday for a couple of weeks but when I'm back, I'll pull your changes and try it out with the serial devices we have here.

Thanks, Steve

felHR85 commented 8 years ago

Cool! Enjoy your holidays!

DinoFontana commented 8 years ago

Thanks felHR85 and SteveoHara !

steveohara commented 8 years ago

I have pulled this into the development and master builds after doing some testing locally. There were some javadoc issues and a nasty recursive loop when closing the SerialConnection. I've also renamed the interface class to fit in with the j2mod naming convention. Take a look and let me know whet you think

felHR85 commented 8 years ago

I will try to take a look as soon as possible! :)