在simulink生成代码时生成有关时间的全局变量

一、代码示例

str2double(datestr(now,'yyyy'))%year
str2double(datestr(now,'mm'))%mouth
str2double(datestr(now,'dd'))%day

str2double(datestr(now,'HH'))%hour
str2double(datestr(now,'MM'))%minute
str2double(datestr(now,'SS'))%second

EE_SAVETime = Simulink.Signal;
EE_SAVETime.CoderInfo.StorageClass = 'Custom';
EE_SAVETime.CoderInfo.Alias = '';
EE_SAVETime.CoderInfo.Alignment = -1;
EE_SAVETime.CoderInfo.CustomStorageClass = 'ExportToFile';
EE_SAVETime.CoderInfo.CustomAttributes.HeaderFile = 'APPVar';
EE_SAVETime.CoderInfo.CustomAttributes.DefinitionFile = 'APPVar';
EE_SAVETime.CoderInfo.CustomAttributes.Owner = 'AISH';
EE_SAVETime.CoderInfo.CustomAttributes.PreserveDimensions = false;
EE_SAVETime.Description = '';
EE_SAVETime.DataType = 'uint32';
EE_SAVETime.Min = [];
EE_SAVETime.Max = [];
EE_SAVETime.DocUnits = '';
EE_SAVETime.Dimensions = 1;
EE_SAVETime.DimensionsMode = 'Fixed';
EE_SAVETime.Complexity = 'real';
EE_SAVETime.SampleTime = -1;
EE_SAVETime.InitialValue = '';

二、建模示例

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

三、生成代码示例

/* Model step function */
void untitledHIUDSH_step(void)
{
  /* Sum: '<Root>/Add' incorporates:
   *  Constant: '<Root>/Constant'
   *  Constant: '<Root>/Constant1'
   *  Constant: '<Root>/Constant2'
   *  DataStoreWrite: '<Root>/Data Store Write'
   *  Gain: '<Root>/Gain'
   *  Gain: '<Root>/Gain1'
   */
  EE_SAVETime = 926997U;
}

四、解析代码示例

/*用matlab语言进行解析*/
bitshift(926997,-16)/*解析小时:14*/
bitshift(bitand(926997, 65280),-8)/*解析分钟:37*/
bitand(926997, 255)/*解析秒:21*/

注:
可以通过读取该变量的值来确定代码生成时间,进而确定当前代码是否集成有问题。

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值