How to have StateFlow/Simulink output a frame at a time and not every timestep?
1 次查看(过去 30 天)
显示 更早的评论
I have simple Simulink model that takes a input stream and frames the data that I would like sent to a serial output ONLY when the frame is complete.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/163257/image.png)
What is happening is, the right side of the StateFlow chart (Digital Output, DataFramed etc) is being sent to my serial port (off screen) at every timestep. What I want, is for the right side of the statechart to only be updated (sent to the serial port) when there is a full frame (that is being assembled within the statechart). How can this be done? As you can see by the generated code...the serial port function and the digital out are being called on every call of the statechart. Within the statechart there are only two states. One that assembles the frame and looks for a delimiter and one that copies the frame to the output of the statechart. It then returns to the original framing state.
You will see that:
MW_digitalWrite(Remote_P.DigitalOutput_pinNumber, (uint8_T)Remote_B.FrameSent);
and
Serial_write(Remote_P.SerialTransmit_portNumber,
Remote_B.TmpSignalConversionAtSerialTran, 45U);
Are called on every timestep iteration.
Thanks.
/* Model output function */
void Remote_output(void)
{
uint8_T h1;
uint8_T h2;
int32_T i;
/* Delay: '<Root>/Delay1' */
Remote_B.Delay1 = Remote_DW.Delay1_DSTATE[0];
/* Chart: '<Root>/Framer' */
/* Gateway: Framer */
Remote_DW.sfEvent = Remote_CALL_EVENT;
/* During: Framer */
if (Remote_DW.is_active_c3_Remote == 0U)
{
/* Entry: Framer */
/* Do Stuff in statechart*/
}
else if (Remote_DW.is_c3_Remote == Remote_IN_FormingFrame)
{
/* During 'FormingFrame': '<S3>:1' */
if (Remote_B.Delay1 == 13)
{
/* Do Stuff in statechart*/
}
else
{
/* Do Stuff in statechart*/
}
}
else
{
/* During 'OutputFrame': '<S3>:8' */
/* Do Stuff in statechart*/
}
/* End of Chart: '<Root>/Framer' */
/* S-Function (arduinodigitaloutput_sfcn): '<S2>/Digital Output' incorporates:
* DataTypeConversion: '<S2>/Data Type Conversion'
*/
*MW_digitalWrite(Remote_P.DigitalOutput_pinNumber, (uint8_T)Remote_B.FrameSent);*
/* SignalConversion: '<Root>/ConcatBufferAtVector ConcatenateIn1' incorporates:
* Constant: '<Root>/LCD_Clear'
* Constant: '<Root>/LCD_SpecChar'
*/
Remote_B.VectorConcatenate[0] = Remote_P.LCD_SpecChar_Value;
Remote_B.VectorConcatenate[1] = Remote_P.LCD_Clear_Value;
/* Constant: '<Root>/LCD_SpecChar2' */
Remote_B.LCD_SpecChar2 = Remote_P.LCD_SpecChar2_Value;
/* Constant: '<Root>/LCD_Position1' */
Remote_B.LCD_Position1 = Remote_P.LCD_Position1_Value;
/* Sum: '<Root>/Sum' incorporates:
* Constant: '<Root>/Constant'
*/
Remote_B.Sum = (uint8_T)((uint32_T)Remote_B.FrameNumber +
Remote_P.Constant_Value_c);
/* SignalConversion: '<S6>/TmpSignal ConversionAtSerial TransmitInport1' */
for (i = 0; i < 42; i++)
{
Remote_B.TmpSignalConversionAtSerialTran[i] = Remote_B.VectorConcatenate[i];
}
Remote_B.TmpSignalConversionAtSerialTran[42] = Remote_B.LCD_SpecChar2;
Remote_B.TmpSignalConversionAtSerialTran[43] = Remote_B.LCD_Position1;
Remote_B.TmpSignalConversionAtSerialTran[44] = Remote_B.Sum;
/* End of SignalConversion: '<S6>/TmpSignal ConversionAtSerial TransmitInport1' */
/* S-Function (arduinoserialwrite_sfcn): '<S6>/Serial Transmit' */
Serial_write(Remote_P.SerialTransmit_portNumber,
Remote_B.TmpSignalConversionAtSerialTran, 45U);
}
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Simulink Functions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!