Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要构造一条消息以发送到 1024 个 ASCII 字符的串行设备。如果我以常规字符串数据类型构造此消息,这会起作用吗?我认为数据会出错,因为字符串是 Unicode 格式的。我怎么能去做这样的事情?
首先,字符串不是为处理二进制数据而设计的,因此当您需要访问行二进制数据时不应该使用它。
最合适的候选者是字节数组。它将确保数据完全存储在您想要的位置。
对于写入串行端口,您应该使用二进制流。它将采用二进制数组,并且可以放在任何可写设备上。