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