Shop OBEX P1 Docs P2 Docs Learn Events
communication with matlab.. — Parallax Forums

communication with matlab..

panagiotispanagiotis Posts: 14
edited 2006-02-06 01:02 in BASIC Stamp
Hello to everyone. The last two days i try to communicate the Bs/2 with matlab via the serial port ( asychronous communication, with the command serin right;[noparse];)[/noparse]. So, my problem is that neither of the two works..If i run first the Bs/2 program, then matlab sais it cannot communicate with the serial port due its use from Bs/2 probably ,and vice versa.. Can anyone figure out something to help me; thanks

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-02-04 17:43
    It would be helpful for you to post your code. The only thing that comes to mind is that if you leave the DEBUG window open that port is in use and MatLab won't be able to open it for its own use.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • panagiotispanagiotis Posts: 14
    edited 2006-02-04 19:43
    that is the code i write in BS/2

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    s VAR Byte(10)

    SERIN 5, 9600 ,[noparse][[/noparse]STR s\9]
    DEBUG STR s

    i download it and that's the code i use on matlab

    >> s = serial('COM2','BaudRate',9600,'DataBits',8)

    ·· Serial Port Object : Serial-COM2

    ·· Communication Settings
    ····· Port:·············· COM2
    ····· BaudRate:·········· 9600
    ····· Terminator:········ 'LF'

    ·· Communication State
    ····· Status:············ closed
    ····· RecordStatus:······ off

    ·· Read/Write State·
    ····· TransferStatus:···· idle
    ····· BytesAvailable:···· 0
    ····· ValuesReceived:···· 0
    ····· ValuesSent:········ 0

    >> fopen(s)···· 'when i try to open the s object the following message appears..(COM2 is the port of BS/2)
    ??? Error using ==> serial.fopen
    Port: COM2 is not available. Available ports: COM1.
    Use INSTRFIND to determine if other instrument objects are connected to the requested device.

    If i do run first the matlab code and then BS/2 then matlab runs ok but at the window of downloading process of the BS/2 there is a message that sais port2 is in use..
  • Paul BakerPaul Baker Posts: 6,351
    edited 2006-02-04 22:01
    The problem seems to be you are trying to use the same serial cable for two different purposes, the first to receive data from matlab, the second to send data to the debug terminal. You can't use it for both, you either have to provide some other means for indicating the data recieved (No debug terminal) or connect a second serial cable up. The may be other issues at play, but that must be addressed first.

    Its likely the reason COM1 is not availible, is it's already in use. Id first disable the debug terminal and try it, switching on an LED if a predetermined pattern is received, blinking it if something was received but not what was expected.

    Jon can instruct you on disabling the debug terminal (I know it can be done, but don't know how).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10

    Post Edited (Paul Baker) : 2/4/2006 10:06:15 PM GMT
  • panagiotispanagiotis Posts: 14
    edited 2006-02-05 12:21
    paul what do you mean by saying 'disable the debug terminal' isn't it the same if i just don;t include in my code the command DEBUG STR s; (from the code above)
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-02-05 14:59
    If you're wanting MatLab to see the data you're sending with DEBUG, you need to close the Debug terminal as this holds that port open and prevents MatLab from using it.· If you don't want to deal with the Debug Terminal every time you run the program you can convert DEBUG to SEROUT on pin 16 (the programming port) at 9600 baud, inverted.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • panagiotispanagiotis Posts: 14
    edited 2006-02-06 00:29
    ok.but my problem is that i just want the BS/2 to see the data i send from matlab, and i cannot achieve that.even though i take out the debug command from BS/2's code, when i download the matlab code the BS/2 cannot communicate..
    thanks for your time..
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-02-06 01:02
    What is coming from MatLab? If you know what's coming (and how it's formatted), you should be able to setup a SERIN to work with it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
Sign In or Register to comment.