---
+ Post New Thread
Results 1 to 14 of 14
  1. #1
    Full Member level 2
    Points: 2,449, Level: 11

    Join Date
    Apr 2004
    Posts
    122
    Helped
    2 / 2
    Points
    2,449
    Level
    11

    matlab serial communication

    Hello!

    I have to send command a modem via serial port and want to use Matlab Serial Communication tool.

    I used instrfind and matlab recognized the modem, anyway when I try to send AT commands I have no reply from the modem itself!

    Also the follwoing message appears:
    "Warning: A timeout occurred before the Terminator was reached."

    Here follows the code I used:

    porta_ser = serial('COM8');
    porta_ser.BaudRate = 4800;
    porta_ser.DataBits = 8;
    porta_ser.Parity = 'none';
    porta_ser.StopBits = 1;
    porta_ser.FlowControl = 'none';
    porta_ser.Terminator ='CR';
    fopen(porta_ser);

    fprintf(porta_ser,'ATI3')
    pause(.1);
    fscanf(porta_ser)

    fclose(porta_ser);
    delete(porta_ser);


    Could anybody help please?
    Thanks in advance

  2. #2
    Member level 2
    Points: 1,154, Level: 7
    akss_here's Avatar
    Join Date
    Feb 2009
    Location
    Bangalore
    Posts
    51
    Helped
    4 / 4
    Points
    1,154
    Level
    7

    serial communication matlab

    program seems to be correct.. so no issues.. try with some other buadrate...
    or check if port connection is perfect or not... timed out results due data unocurred event during reading cycle...


    2 members found this post helpful.

  3. #3
    Member level 1
    Points: 1,288, Level: 8

    Join Date
    May 2007
    Posts
    40
    Helped
    0 / 0
    Points
    1,288
    Level
    8

    matlab serial port communication

    hi, we do some work with matlab serial comm. with mobile serialport. after scan we wait for 2 or 3 sec .and then we proceed. so wait 2 or 3 sec after scanf and before closing the connection



    •   Alt17th July 2009, 06:57

      advertising

        
       

  4. #4
    Full Member level 2
    Points: 2,449, Level: 11

    Join Date
    Apr 2004
    Posts
    122
    Helped
    2 / 2
    Points
    2,449
    Level
    11

    serial communication in matlab

    HI!

    I forgot to mention that everything is fine if I send the AT command using HyperTerm.

    I put the "waits" into my code but nothing changes...

    Any other idea, please?

    Thanks
    CIAO



  5. #5
    Member level 2
    Points: 1,154, Level: 7
    akss_here's Avatar
    Join Date
    Feb 2009
    Location
    Bangalore
    Posts
    51
    Helped
    4 / 4
    Points
    1,154
    Level
    7

    matlab serial

    Do little bit more for you...

    Type command window

    >>tmtool

    you will get test and measurement window...
    next thing go for scan for instrument hardware

    you will get options for serial communication..
    open device communication status it will generate session log
    matlab code required for the program...

    you can read or write also to check your instrument...

    based on idea you can modify your program little bit.. and implement that...
    wait will not work in mine idea...some solution is always.. there..
    it is not much difficult....

    or try attached file.. i am sure this will definately work.. yepee


    HAPPY :D:D



    •   Alt17th July 2009, 12:20

      advertising

        
       

  6. #6
    Full Member level 2
    Points: 2,449, Level: 11

    Join Date
    Apr 2004
    Posts
    122
    Helped
    2 / 2
    Points
    2,449
    Level
    11

    matlab serial communication codes

    Hi mate!
    unfortunately your code doesn't work :( attached you see what matlab "tells" me.

    I used TMTOOL as well with same results :(((

    Thanks for any further help.
    Hello



    •   Alt20th July 2009, 10:28

      advertising

        
       

  7. #7
    Member level 2
    Points: 1,154, Level: 7
    akss_here's Avatar
    Join Date
    Feb 2009
    Location
    Bangalore
    Posts
    51
    Helped
    4 / 4
    Points
    1,154
    Level
    7

    matlab serial port ,test

    sir,

    the file you have attached shows nothing wrong...

    i.e will definately work..

    the case you not feeding any data.. so seesion is timed out...
    code i have checked properly...
    if u r able to read data by hyperterminal then here also it has to display...

    check...

    HAPPY :D :D



  8. #8
    Full Member level 2
    Points: 2,449, Level: 11

    Join Date
    Apr 2004
    Posts
    122
    Helped
    2 / 2
    Points
    2,449
    Level
    11

    matlab serial terminator

    First of all I want to thank you for your help.

    I try to explain what I need to have: I have to send AT commands to a modem and check how long it takes to perform some actions.

    If I send "ATI3", for example, like I do using HyperT I expect to see a reply with some infos.
    Using that piece of code I have no reply.

    I don't have to feed data... I just send a command and wait for the modem to reply with a message.

    It seems that it is waiting the terminator character... maybe, if I could send the termination it will reply with the info I need.

    Still trying to understand... I'm not a professional programmer

    Thanks



  9. #9
    Member level 2
    Points: 1,154, Level: 7
    akss_here's Avatar
    Join Date
    Feb 2009
    Location
    Bangalore
    Posts
    51
    Helped
    4 / 4
    Points
    1,154
    Level
    7

    serial fscanf matlab

    thanks for ur patience...

    for that case also tmtool, i.e test and measurement tool... will work...

    r u using any specific class for communication.. i won't think so....

    might be some other cases...
    see the paper for AT in matlab simulink for better idea...

    HAPPY :D:D



  10. #10
    Newbie level 1
    Points: 336, Level: 3

    Join Date
    Feb 2011
    Posts
    1
    Helped
    0 / 0
    Points
    336
    Level
    3

    Re: Serial Communication & Matlab

    Assuming that u hit enter in HyperTerminal while communicating, try replacing fwrite(porta_ser, ['ATI3' 13 10]), instead of fprintf(porta_ser,'ATI3) in ur matlab code



  11. #11
    Newbie level 3
    Points: 314, Level: 3

    Join Date
    Apr 2011
    Posts
    3
    Helped
    0 / 0
    Points
    314
    Level
    3

    Re: Serial Communication & Matlab

    Hi,
    I have a cooler and a pressure gauge which I need to operate from Matlab. Both devices are connected to the computer via a serial port. I've been using the Matlab Instument Toolbox Test & Measurement tool to try and communicate with these machines. The problem is that I don't get any data from them, and as far as I know, can't send them any data either.
    The manual for the cooler can be found here, and a description of the RS-232 interface in part 4 of that document. I've set up the baud speed, number of data bits and stop bits, parity and terminator as specified. But if I try to send any commands to the device, I get no reply before the timeout.
    I've sent the data in ASCII format and I've tried the different data formats, but I get no response. Can you tell me what is it that I'm doing wrong?



  12. #12
    Member level 2
    Points: 1,154, Level: 7
    akss_here's Avatar
    Join Date
    Feb 2009
    Location
    Bangalore
    Posts
    51
    Helped
    4 / 4
    Points
    1,154
    Level
    7

    Re: Serial Communication & Matlab

    there r two methods which i know for serial interfacing with matlab.

    1. you can write simple S Function program, which already given with the software, just you have to modify some statements.
    2. using tmtool in CP, you can creat drive for serial communication in matlab.


    both will work, first one will easy to develop

    HAPPY : )

    Quote Originally Posted by alma111 View Post
    Hi,
    I have a cooler and a pressure gauge which I need to operate from Matlab. Both devices are connected to the computer via a serial port. I've been using the Matlab Instument Toolbox Test & Measurement tool to try and communicate with these machines. The problem is that I don't get any data from them, and as far as I know, can't send them any data either.
    The manual for the cooler can be found here, and a description of the RS-232 interface in part 4 of that document. I've set up the baud speed, number of data bits and stop bits, parity and terminator as specified. But if I try to send any commands to the device, I get no reply before the timeout.
    I've sent the data in ASCII format and I've tried the different data formats, but I get no response. Can you tell me what is it that I'm doing wrong?



  13. #13
    Junior Member level 1
    Points: 548, Level: 4

    Join Date
    Mar 2010
    Location
    india
    Posts
    16
    Helped
    0 / 0
    Points
    548
    Level
    4

    Re: matlab serial communication

    In case ur problem is still not solved.....try using fread command instead of fscan to recieve data and fwrite to send data.......I faced the same problem and now it works :)

    Quote Originally Posted by scoppulal View Post
    Hello!

    I have to send command a modem via serial port and want to use Matlab Serial Communication tool.

    I used instrfind and matlab recognized the modem, anyway when I try to send AT commands I have no reply from the modem itself!

    Also the follwoing message appears:
    "Warning: A timeout occurred before the Terminator was reached."

    Here follows the code I used:

    porta_ser = serial('COM8');
    porta_ser.BaudRate = 4800;
    porta_ser.DataBits = 8;
    porta_ser.Parity = 'none';
    porta_ser.StopBits = 1;
    porta_ser.FlowControl = 'none';
    porta_ser.Terminator ='CR';
    fopen(porta_ser);

    fprintf(porta_ser,'ATI3')
    pause(.1);
    fscanf(porta_ser)

    fclose(porta_ser);
    delete(porta_ser);


    Could anybody help please?
    Thanks in advance



  14. #14
    Newbie level 1
    Points: 141, Level: 1

    Join Date
    Mar 2012
    Posts
    1
    Helped
    0 / 0
    Points
    141
    Level
    1

    Re: matlab serial communication

    Hi, I reply also for many users having the same problem (google often forward to this topic), don't forget about the sign of end the line"

    for example if you set:
    Code:
    porta_ser.Terminator ='CR';
    You have to send something like this after the message from your uC:
    Code:
    Serial.print("\r");
    and for 'LF' it is '\n' :)



+ Post New Thread
Please login