====中文==========================================================================
你好,导师,我是一名java程序员,我在使用canopen当中遇到一些相关的疑问。如下面的截图所示,我向vcan发送数据,但是Vcan没有打印出任何提示信息。这种问题我需要如何处理,谢谢。


====English========================================================================
Hello, tutor, I'm a java developer,I have some questions about using CANopen. 
As shown in the screenshot below, I sent data to Vcan, but Vcan did not print 
any prompt information. How do I deal with this problem? Thank you.


====code==========================================================================
    <dependencies>
        <!-- 
https://mvnrepository.com/artifact/org.apache.plc4x/plc4j-driver-canopen -->
        <dependency>
            <groupId>org.apache.plc4x</groupId>
            <artifactId>plc4j-driver-canopen</artifactId>
            <version>0.8.0</version>
        </dependency>
    </dependencies>
===================================================================================
package com;


import org.apache.plc4x.java.api.exceptions.PlcConnectionException;
import org.apache.plc4x.java.api.messages.PlcWriteRequest;
import org.apache.plc4x.java.api.messages.PlcWriteResponse;
import org.apache.plc4x.java.canopen.CANOpenPlcDriver;
import org.apache.plc4x.java.spi.connection.DefaultNettyPlcConnection;


import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;


public class CANOpenVcanDemo {
    public static void main(String[] args)
            throws PlcConnectionException, ExecutionException, 
InterruptedException {
        String canInterface = "vcan1";
        String connectionString =
                String.format("canopen:socketcan://%s?nodeId=11", canInterface);
        DefaultNettyPlcConnection plcConnection =
                (DefaultNettyPlcConnection) new 
CANOpenPlcDriver().getConnection(connectionString);
        plcConnection.connect();
        if (plcConnection.isConnected()){
            System.out.println("Connected");
        }else {
            System.out.println("not Connected");
            return;
        }
        if (plcConnection.getMetadata().canWrite()) {
            PlcWriteRequest.Builder builder = 
plcConnection.writeRequestBuilder();
            //String address = "SDO:11:0x1600/0x01:INTEGER64";
            String address = "RECEIVE_PDO_1:11:INTEGER64";
            //CANOpenDataType
            builder.addItem("rpdo_0x200", address,123);
            PlcWriteRequest plcWriteRequest = builder.build();
            CompletableFuture<PlcWriteResponse> completableFuture =
                    (CompletableFuture<PlcWriteResponse>) 
plcWriteRequest.execute();
            System.out.println("===========>flag");
            PlcWriteResponse plcWriteResponse = completableFuture.get();
            System.out.println(plcWriteResponse.getResponseCode("rpdo_0x200"));
        }
    }
}







Reply via email to