You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
Communication with Standford Research Syteme DG535 Digital Delay/Pulse Generator
    18 views (last 30 days)
  
       Show older comments
    
Dear All,
Has anyone ever controlled a Stanford Research Systems Model DG535 via Matlab? I'am in desperate need to remotely control the DG535 with Matlab but I have no chance to build a connection between them. In the manual it seems easy, but somehow the connection with the GPIB and Matlab does not work properly.
Maybe there is someone in the community who has already connected a DG535 with Matlab? Any help would be much appreciated.
Thanks
10 Comments
  ProblemSolver
      
 on 29 Jun 2023
				Could you share so far what you have done. So that we can see where you are facing the problem. 
  René Lampert
 on 29 Jun 2023
				I have done what I always do when I want to control a device with Matlab. I have written a class in which the serial communication is established in the constructor - see code below
I use exactly the same code for several devices like oscillosopes, spectra analyzer etc. and it works perfectly. I always us the serial object (which forever reason is not recommended from Matlab). For GPIB there is "visadev" but it is poorly explained how it works .
Like:
classdef ModelDG535 < handle
    properties
        comPort         % COM port (string), e.g. 'COM11'
        baudRate        % BaudRate, e.g. 19200
        terminator      % Terminator (string), e.g. 'CR/LF'
        parity          % Parity (string),e.g. 'none'
        dataBits        % dataBits, e.g. 8
        stopBits        % stopBits, e.g. 0
        InputBufferSize % inputbuffersize, e.g. 8*20001
        Timeout         % in seconds
        ls              % serial object
    end
    methods
        %Mit dieser Funktion wird das Objekt erstellt.
        function this = ModelDG535(comPort)
            this.comPort    = comPort;
            this.baudRate   = 9600;
            this.terminator = 'CR/LF';
            this.parity     = 'even';
            this.dataBits   = 8;
            this.stopBits   = 1;
            this.InputBufferSize = 10*20001;
            this.Timeout    = 7 ;
            %OSA=serial(comStr,'Terminator', 'CR/LF','InputBufferSize', 10*20001,...
            %'timeout',5);
            this.ls = serial(comPort)       % make connection serial
            set(this.ls,'BaudRate',this.baudRate);
            set(this.ls,'Terminator',this.terminator);
            set(this.ls,'Parity',this.parity);
            set(this.ls,'DataBits',this.dataBits);
            set(this.ls,'StopBits',this.stopBits);
            set(this.ls,'InputBufferSize',this.InputBufferSize);
            set(this.ls,'Timeout',this.Timeout);
            fopen(this.ls);
            fprintf(this.ls, '++addr 15');        % GPIB address 15
            fprintf(this.ls, '++mode 1');         % Configure as Controller (++mode 1)             fprintf(this.ls, '++addr 15');         % GPIB Address 15
            query(this.ls,'*IDN?')
            flushinput(this.ls);
        end
    end
end
  ProblemSolver
      
 on 29 Jun 2023
				
      Edited: ProblemSolver
      
 on 29 Jun 2023
  
			@René Lampert: If you are already providing the serial port = COM11 in your code, then why are you sending the command again
fprintf(this.ls, '++addr 15');
I don't have access to the instrument with me currently , so I am not able to try and help you accurately, but I would comment this line, and see if it works?
Also I see that you haven't a destructor function for the object that you opened. That is also necessary as if you rerun the program you might still have previous connection active, therefore add something in the end like this:
fclose(this.ls);
I hope this helps!
  René Lampert
 on 29 Jun 2023
				I already did this and it does not help unfortunately. Serial communication in Matlab is a mess...
Do you have the same instrument ?
  ProblemSolver
      
 on 29 Jun 2023
				
      Edited: ProblemSolver
      
 on 29 Jun 2023
  
			Not the same, I use DG645 - Low jitter delay generator, but I had it connected with NI LabVIEW. and I alternate between RS232 and Ethernet, when it provides me with troubles.
I thing I forgot to mention is that you have you have activate the configuration. What I have to do when I am using DG645, for RS232 I have to press SHIFT and RS232 to activate the mode. So you should also check that.
The other way you can try is. just try to operate directly from Command Window. Using VISA something like this:
>> DG535object = visa('name of the device', GPIBaddress);
%then open the connect using fopen
>> fopen(DG535object);
% then just send one of the commands
>> fprintf(this.ls, '++mode 1');
and see if this works?
OR run this to check if you are getting any errors:
DG535object = serial('COM11','BaudRate',19200,'Parity','even', ...
                'DataBits',8,'FlowControl','none');
if isempty(DG535object)  % please simply test this
  errordlg(...)
  return;
end
  René Lampert
 on 29 Jun 2023
				the return command in your last code block is not valid - and what is s_port ?
the visa method was also not succesfsul, i always get the error  "The specified VENDOR adaptor could not be found" . I'm completely confused with this visa method and how this should work, do I need special drivers for the used GPIB module?
  ProblemSolver
      
 on 29 Jun 2023
				That block was invalid because the variable name in the parantheses was suppose to be DG535object. Then it will not give an invalid command.
All you need is Instrument Control ToolBox.
  René Lampert
 on 29 Jun 2023
				I do have the Instrument Control ToolBox, but it is still not valid and says that return is illegal ...
  René Lampert
 on 29 Jun 2023
				I tried it again with the visa method
serialdev = visadev("COM6");
then I used 
writeline(serialdev,'CL')
to test the communication ( "CL" is the command to clear the instrument according to the manual and set the instrument to default settings). The LED on th instrument REM (remote) turns to green but at the dispaly ist says "Bad Command", unfortunately there is no decription in the manual what this actually means. But something has been communicated ....
  René Lampert
 on 3 Jul 2023
				Now it works ! The problem was that the manual was wrong with the commands. For instannce, the command 'CL' had to be written as 'C L', so there must be a space bewteen every character. I am not sure why this is the case and why there is nothing about it in the manual, but at least it works now.
Thanks
Answers (0)
See Also
Categories
				Find more on Instrument Control Toolbox in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)

