function comconfig() // Just try it and customize it to your application // How to use it // comconfig() // -> open Comm port // receive data by "readbincom(ghcom, ...." // transmit data by e.g. "writebincom(ghcom, ...." global comfig ghcom ghcom = -1; [dll_link,linknr] = c_link('serial'); if dll_link==%F, addinter('serial.dll','serial',[ 'opencom';'closecom'; 'writecom'; 'writebincom'; 'readbincom'; 'resetcom'; 'getcomhandle' ]); end; // close all open comm closecom(getcomhandle()); comfig=figure(); set(comfig,'position',[10 10 220 240 ]); set(comfig,'tag','tCOMM'); figpos = 200:-20:20; // COM Einstellungen hx = uicontrol(comfig,'style','text','fontsize',14,'position',[10 figpos(1) 200 19],'string','Comm Settings'); // Port hx = uicontrol(comfig,'style','text','fontsize',12,'position',[10 figpos(3) 80 19],'string','Port'); hport = uicontrol(comfig,'style','popupmenu','fontsize',12,'position',[100 figpos(3) 75 19], ... 'BackgroundColor',[1 1 1],'tag','tport'); set(hport,'string',['1|2|3|4']); set(hport,'value','0'); // Baudrate hx = uicontrol(comfig,'style','text','fontsize',12,'position',[10 figpos(4) 80 19],'string','Baudrate'); hbaud = uicontrol(comfig,'style','popupmenu','fontsize',12,'position',[100 figpos(4) 75 19],... 'BackgroundColor',[1 1 1],'tag','tbaud'); set(hbaud,'string',['1200|2400|4800|9600|19200|38400|57600|115200']); set(hbaud,'value','3'); // NBits hx = uicontrol(comfig,'style','text','fontsize',12,'position',[10 figpos(5) 80 19],'string','NBits'); hnbit = uicontrol(comfig,'style','popupmenu','fontsize',12,'position',[100 figpos(5) 75 19],'string','7|8',... 'BackgroundColor',[1 1 1],'tag','tnbit'); set(hnbit,'value','1'); // Parity hx = uicontrol(comfig,'style','text','fontsize',12,'position',[10 figpos(6) 80 19],'string','Parity'); hpari = uicontrol(comfig,'style','popupmenu','fontsize',12,'position',[100 figpos(6) 75 19],'string','-|odd|even|mark|space',... 'BackgroundColor',[1 1 1],'tag','tpari'); set(hpari,'value','0'); // Stoppbits hx = uicontrol(comfig,'style','text','fontsize',12,'position',[10 figpos(7) 80 19],'string','Stopbits'); hstop = uicontrol(comfig,'style','popupmenu','fontsize',12,'position',[100 figpos(7) 75 19],'string','1|2',... 'BackgroundColor',[1 1 1],'tag','tstop'); set(hstop,'value','0'); // Protocol hx = uicontrol(comfig,'style','text','fontsize',12,'position',[10 figpos(7) 80 19],'string','Protocol'); hprot = uicontrol(comfig,'style','popupmenu','fontsize',12,'position',[100 figpos(7) 75 19],'string','-|RTS/CTS|XON/XOFF',... 'BackgroundColor',[1 1 1],'tag','tprot'); set(hprot,'value','0'); // Timeout hx = uicontrol(comfig,'style','text','fontsize',12,'position',[10 figpos(8) 80 19],'string','Read Timeout'); htime = uicontrol(comfig,'style','popupmenu','fontsize',12,'position',[100 figpos(8) 75 19],'string','10|100|1000',... 'BackgroundColor',[1 1 1],'tag','ttime'); set(htime,'value','0'); hx = uicontrol(comfig,'style','text','fontsize',12,'position',[180 figpos(8) 20 19],'string','ms'); hopen = uicontrol(comfig,'style','pushbutton','fontsize',12,'position',[50 figpos(10) 120 20],... 'string','open','tag','SWCom','backgroundcolor',[1,0,0]), set(hopen,'callback','openclose()'); function openclose() global comfig ghcom figure(comfig); if ghcom == -1, han = findobj('tag','tport'); wert = evstr(get(han,'value')) + 1; dummy = [1 2 3 4 ]; port = dummy(wert); han = findobj('tag','tbaud'); wert = evstr(get(han,'value')) + 1; dummy = [1200 2400 4800 9600 19200 38400 57600 115200]; baud = dummy(wert); han = findobj('tag','tnbit'); wert = evstr(get(han,'value')) + 1; dummy = [7 8]; nbit = dummy(wert); han = findobj('tag','tpari'); pari = evstr(get(han,'value')); // - odd even mark space han = findobj('tag','tstop'); wert = evstr(get(han,'value')) + 1; dummy = [0 2]; stop = dummy(wert); han = findobj('tag','tprot'); wert = evstr(get(han,'value')) + 1; dummy = [0 2]; prot = dummy(wert); han = findobj('tag','ttime'); wert = evstr(get(han,'value')) + 1; dummy = [10 100 1000]; timeout = dummy(wert); disp(port) ghcom = opencom(port,baud,nbit,pari,stop,prot,timeout); if ghcom > 0, han = findobj('tag','SWCom'); set(han,'backgroundcolor',[0,1,0]) set(han,'string','close') end; else closecom(ghcom); ghcom = -1; han = findobj('tag','SWCom'); set(han,'backgroundcolor',[1,0,0]) set(han,'string','open') end; return