Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[improve]add Plc protocol , Modbus monitor #2850

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

ZY945
Copy link
Member

@ZY945 ZY945 commented Dec 1, 2024

What's changed?

The plc4x project is used to implement the collection of PLC protocol. Currently, the retention register and coil collection of modBus protocol have been introduced, which can collect data from different slave devices with the same IP address

Checklist

  • I have read the Contributing Guide
  • I have written the necessary doc or comment.
  • I have added the necessary unit tests and all cases have passed.

Add or update API

  • I have added the necessary e2e tests and all cases have passed.

@github-actions github-actions bot added doc Improvements or additions to documentation license labels Dec 1, 2024
@ZY945 ZY945 changed the title Plc protocol [improve]add Plc protocol , Modbus monitor Dec 1, 2024
@ZY945 ZY945 linked an issue Dec 1, 2024 that may be closed by this pull request
[improve] fix PlcCollectImpl check-license-header error

[improve] fix PlcCollectImpl check markdown
[improve] fix ModBus check markdown and License check
[improve] fix app-nebulaGraph.yml dead links found

[improve] fix app-nebulaGraph.yml dead links found to app-nebula_graph.yml
@ZY945
Copy link
Member Author

ZY945 commented Dec 3, 2024

I found that pltConnectivity close() takes a long time, mostly 2000ms, and may need to be optimized by reusing connections or asynchronously closing connections

@pwallk
Copy link
Contributor

pwallk commented Dec 3, 2024

hi, since I often use Modbus and other related communication protocols in my work, I am very interested in this PR. I pulled the code and it took me a while to figure out how to use it and successfully read the data, right.In this regard, I have some questions or suggestions:
1.Modbus data is converted into actual data, for example: the read data is of type Double, occupies four registers, the byte sequence is CDAB, and the read address is 1[4]. The program should support the conversion of the values of four registers into actual data, after all, the monitoring needs to alarm the actual values
PixPin_2024-12-03_15-41-56
2.the PlcProtocol and PlcCollectImpl classes are coupled to Modbus TCP,it is difficult to develop other communication protocols in the future,is there any way to decouple them? Such as

@Slf4j
public abstract class AbstractPlcCollectImpl extends AbstractCollect {

    private static final PlcConnectionManager CONNECTION_MANAGER;

    static {
        CONNECTION_MANAGER = PlcDriverManager.getDefault().getConnectionManager();
    }

    @Override
    public void collect(CollectRep.MetricsData.Builder builder, long monitorId, String app, Metrics metrics) {
        // do something....
        String connectionString =getConnectionString(metrics);
        PlcConnection plcConnection = CONNECTION_MANAGER.getConnection(connectionString);
        PlcReadRequest readRequest = buildRequest(metrics, plcConnection);
        // do something....

    }

    protected abstract String getConnectionString(Metrics metrics);
    
    protected abstract PlcReadRequest buildRequest(Metrics metrics, PlcConnection connection);
}

public class ModbusCollectImpl extends AbstractPlcCollectImpl{
    @Override
    protected String getConnectionString(Metrics metrics) {
        ModbusProtocol protocol = metrics.getModbusProtocol();
        // do something...
    }

    @Override
    protected PlcReadRequest buildRequest(Metrics metrics, PlcConnection connection) {
        // do something...
    }

    @Override
    public void preCheck(Metrics metrics) throws IllegalArgumentException {
        // do something...
    }

    @Override
    public String supportProtocol() {
        return "MODBUS";
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Improvements or additions to documentation license
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Suggest adding support for common protocols such as Modbus and PLC
2 participants