1

I'm trying to send and receive data through a serial port using simulink (matlab 7.1) and d-space. The values I want to send and receive are doubles. Unfortunately for me the send and receive blocks use uint8 values. My question is how can I convert doubles into an array of uint8 values and vice versa? Are there simulink blocks for this or should I use embedded matlab functions?

4

2 回答 2

3

使用恰当命名的数据类型转换块,它就是这样做的。

在评论中的讨论后编辑

关于缩放,这是我很久以前做过的事情的快照。它使用的是CAN而不是串口,但原理是一样的。在这里,信号总是正的,所以稍微容易一些,所以我不必担心缩放负数。65535 是 a 的最大值uint16,我会在接收端进行反向缩放。转换为uint16(或uint8在您的情况下,它会自动舍入该值,您可以在块掩码中指定该行为)。

在此处输入图像描述

于 2013-10-25T15:13:48.287 回答
0

simulink中有pack和unpack blocks,在simulink库浏览器中搜索即可。你可能需要一些额外的产品,不确定是哪个。

于 2013-10-28T20:09:50.530 回答