0

シリアルポートをスローする組み込みデバイスにファイルをアップロードする方法はありますか? RXTX を使用していますが、このファイルをアップロードするのではなく、ファイルからデータを送信しただけです。アドバイスをありがとう。

public static void main(String[] args) throws PortInUseException, UnsupportedCommOperationException
{
    java.util.Enumeration<CommPortIdentifier> portEnum = CommPortIdentifier.getPortIdentifiers();
    while (portEnum.hasMoreElements())
    {
        CommPortIdentifier portIdentifier = portEnum.nextElement();
        if (portIdentifier.getPortType() == CommPortIdentifier.PORT_SERIAL)
        {
            if (portIdentifier.isCurrentlyOwned())
            {
                System.out.println("Port is curently used");
                System.exit(0);
            }
            else
            {
                CommPort commPort = portIdentifier.open("Zkouska", 2000);
                if (commPort instanceof SerialPort)
                {
                    SerialPort serialPort = (SerialPort) commPort;
                    serialPort.setSerialPortParams(57600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
                    try
                    {
                        OutputStream out = serialPort.getOutputStream();
                        File file = new File("C:/data/java/RXTX/01_Hello/SerialUploader/uploaddemo.dat");
                        byte[] content = new byte[(int)file.length()];
                        FileInputStream fin = new FileInputStream(file);
                        fin.read(content);
                        out.write(content);
                        out.flush();
                        out.close();
                        commPort.close();
                        System.out.println("Tady");
                    }
                    catch (IOException e)
                    {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}
4

1 に答える 1

2

おそらく、次のようなファイル転送プロトコルでアップロードする必要があります

Java のスターターについては、こちらをご覧ください: Javaでの X-modem プロトコルの実装

于 2011-08-23T11:38:22.773 に答える