M
M
Maxim Skladchikov2020-04-21 22:54:34
C++ / C#
Maxim Skladchikov, 2020-04-21 22:54:34

How to transfer data from a program written in C# (SerialPort) to Matlab?

Good evening! I ask for your help. It's worth saying in advance that I'm new to this business. I have the task of transferring data from a program written in C# to Matlab. In a C# program, I form an infinite loop that passes data. And in Matlab I created a Simulink model. I checked the performance of each program separately (I just put a jumper between the RX TX ports). For each program I have a separate UART. When I run the program to transfer data, the LEDs on each of the UARTs are lit during data transfer (I think this is a sign of data on the Rx / Tx ports). However, in Matlab I can't display anything.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;
 
namespace WindowsFormsApp5
{
    public partial class Form1 : Form
    {
        SerialPort port = new SerialPort("COM7", 115200, Parity.None, 8, StopBits.One);    
        public Form1()
        {
            InitializeComponent();
            if (port != null)
            {                               
                port.Open();             
                byte number = 15;
                while(1<2)
                {
                    port.Write(new byte[] { number }, 0, 1);
                }
            }
            
        }
    }
 
}

As a result of running the model in Matlab, I get nothing. I ask you for help. Below is the model with block parameters.
5e9f4e8c8a31e700764646.jpeg

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question