문제

When monitoring data sent to device i get this: https://i.stack.imgur.com/u0kIT.png

but i expect one character: F0 ð

 public void WritingDataToPort() {
        SerialPort port = new SerialPort("COM26");
        try {
            System.out.println(port.openPort());
            port.setParams(9600, 8, 1, 0);
            port.writeString((char)240+""));
            port.closePort();
        } catch (SerialPortException ex) {
            System.out.println(ex);
        }
 }

I completly don't know how to send this "ð" characater. Tried all ascii codes.

도움이 되었습니까?

해결책

You can't just send the char (or UTF8) through the serial port. You have to convert it. First get the length of the char in UTF-8, then get the bytes and send the bytes.

Getting the size of UTF-8: Getting the actual length of a UTF-8 encoded std::string?

Then send it one by one. On the other side you need something to assemble them back.

You could also consider using a better alternative to writing bytes directly to the port, such as http://code.google.com/p/java-simple-serial-connector/

다른 팁

You could try unicode. UTF-8 code.

http://www.fileformat.info/info/unicode/char/f0/index.htm

C/C++/Java source code  "\u00F0"
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top