Forum General

MVVM for Serial I/O

DR_BartDR_Bart Member ✭✭
edited October 2018 in General


I'm trying to understand MVVM when using I/O, specifically a serial port.

I've implemented my MVVM Model as follows:


public class SerialPortModel
    private SerialPort Port;

    public SerialPortModel()
        Port = new SerialPort
            Handshake = Handshake.None,
            BaudRate = 9600,
            ReadTimeout = 400,
            DiscardNull = false,
            ReceivedBytesThreshold = 1,
            WriteTimeout = 100

My question is: Should I implement methods such as getting port names, open and close port, etc in the Model or in the ViewModel?

I've read that the Model should just contain data, and not methods? Or is it OK for the Model to run methods such as opening the COM port?

Sign In or Register to comment.