How to do MATLAB for serial port

Hi,
I want to interface MATLAB with PIC, to do SCADA. MATLAB communicate with USB port, then I have USB-to-UART converter to connect to PIC.
Does anybody have source to do this? It's is doing in GUI or m file?

Replies

  • Ashraf HZ
    Ashraf HZ
    Hey shahrul,

    I'm assuming the USB-UART converter is a serial port emulator. In Matlab, you just need to create a serial port object, open it, then read the data. At the most simple, the code will be:

    s = serial('COM1'); % Create serial port object s
    set(s,'BaudRate',9600)
    fopen(s); %open port
    x = fscanf(s); % read data into variable x
    fclose(s) % close port
    delete(s)
    clear s
    The above code assumes you are using COM1 port for the USB serial emulator. You should change accordingly. Also, 8N1 parameter is used as default. Of course, you may need to code more according to your project, refer to the Matlab reference below:

    #-Link-Snipped-#
  • shahrul
    shahrul
    Thanks, I will try.

You are reading an archived discussion.

Related Posts

Hello everyone.........I want to store some of my files and folders on cloud. How can I do it? Is there any software for that?
Hello my friends, i want to design a system that lifts 30kg to 80cm vertically up and down. i want to drive it with a DC motor. what is your...
Hi All! Question, for those who use Photomultipliers. I have the photomultiplier. Advise please, the device which would contain amplifier, discriminator and a counter, all in one. Device can be...
So, have you thought of this? Hindu Temples have too many systems working in perfect harmony - and a software to manage it could very well be your final or...
In case you were wondering what does Sony's "BRAVIA" stand for - here's the answer. The full form of BRAVIA is - Best Resolution Audio Visual Integrated Architecture (PS: Might...