Code covered by the BSD License  

Highlights from
CO2gui - lab control and automation

CO2gui - lab control and automation

by

 

06 Jan 2010 (Updated )

Software used for controlling and data logging lab equipment.

JascoCommands.m
instrfind % this displays all the currently setup comm ports
tmtool % useful tool, shows what matlab currently has setup as serial objects (but takes a while to load)

% example bpr
% =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
% setting up com port correctly
s1 = serial('COM5' ,'BaudRate', 9600, 'DataBits', 8, 'Parity', 'none', 'StopBits', 2, 'Flowcontrol', 'hardware', 'Terminator', 'CR');

fopen(s1) % open the com port

fprintf(s1, '#1') % connect to the BPR - RC should be displayed on the unit
fprintf(s1, '#2') % disconnect the BPR

% so some strange reason you can send commands to the BPR even when it not
% in the RC mode, however it is not possible to recieve anything from the
% BPR

fclose(s1) % close the port
delete(s1) % delete and clear everything
clear

fprintf(s1, '#0x44 XXXX') % changed the set pressure to XXXX where XXXX is a hexadecimal value of the pressure in MPa * 100 
% this is the same as 10 * the pressure in bar e.g. P = dec2hex (52 * 10) to give the XXXX which should be used to set 52 bar

a = input('Pressure in bar?'); % example of asking pressure and sending command
Ps = dec2hex(a * 10); 
text = ['#0x44 ', Ps]; 
fprintf(BPR, text)
out = fscanf(BPR);

fprintf(s1, '#0x45 XXXX') % change the set temp to XXXX where XXXX is a hexadecimal value of the pressure in C * 100 
% e.g. T = dec2hex(50 * 100) gives XXXX which should be used to set to 50 C

T = dec2hex(32 * 100); % 32 C just example could be calc thus gives way to automate
text = ['#0x45 ', T]; % example of how to generate auto values
fprintf(s1,text)
out = fscanf(s1); % have to run this after every input as BPR sends OK commands to matlab and get confussed if not read before sending another command

% commands to read data from BPR; fprintf(s1, '#0x1000 XXXX') where XXXX is
% the data requested.  e.g. 0x12 is press and temp again in the hexadecimal
% values as explained above
fprintf(s1, '#0x1000 0x12') % asks for press and temp - this command is relatively quick to run
out = fscanf(s1); % gives reply from BPR #0 0 PPPP TTTT (#0 0 means the type of command and that it has been sent OK) 
value = textscan(out, '%s%s%s%s'); % convert output into cells
temp = (hex2dec(value{4})) / 100; % convert string value into decimal reading and then divide to give current temp

% BPR pressure response can not handle the incorrect negative pressure reading (which
% jasco stuff sometimes gives) and returns instead a very high (several
% million) reading.

fprintf(BPR, '#0x1000 0x85'); % ask for set temp - this is slower than getting the current press and temp
out = fscanf(BPR); % return set temp
value = textscan(out, '%s%s%s'); % convert char to separate strings
ctemp = (hex2dec(value{3})) / 100; % get set temp from string

fprintf(BPR, '#0x1000 0x84'); % ask for set pressure - as slow as asking for the set temp
out = fscanf(BPR); % return set pressure
value = textscan(out, '%s%s%s'); % convert char to separate strings
cpress = (hex2dec(value{3})) / 10; % get set P from string

% mystifyingly, asking for the current maximum pressure is much quicker
% than asking for the set pressure or temperature (about 5 times as fast!?)


% commands for program
% sequence; open prog, prog steps, close prog, start prog, stop prog

fprintf(BPR, '#0x13') % open program
out = fscanf(BPR); % need this after every command to check

fprintf(BPR, '#0x15 10 1 0 2BC') % program steps, #0x15 is command ID followed by TTTT P EEEE VVVV
% TTTT is the time in seconds in hex
% P is parameter value (1 == pressure, I think 2 is temp)
% EEEE is event ID this has something to do with data start/stop and monitoring as the BPR reaches each part of the program, I don't think matlab can handle this anyway
% may be good for a constant serial port montior
% VVVV is the value set for the parameter in hex (remember that it is bar * 10 and C * 100)
out = fscanf(BPR);
% send the program event command (#0x15) for every step (follow it with the fscanf command after each send otherwise it does not work)

fprintf(BPR, '#0x14') % close prog
out = fscanf(BPR); % check command

fprintf(BPR, '#0x16') % start prog
% start and stop commands have three lines of output
out = fscanf(BPR); % event output (not sure which yet)
out = fscanf(BPR); % event output (not sure which yet)
out = fscanf(BPR); % check command


fprintf(BPR, '#0x17') % stop the program, goes back to what ever the BPR was set to before the program was started
% start and stop commands have three lines of output
out = fscanf(BPR); % event output (not sure which yet)
out = fscanf(BPR); % event output (not sure which yet)
out = fscanf(BPR); % check command

%tbe program is the same as done manually i.e. if no stop prog command is sent then it just maintains what ever was set with the last step 


% example pump
% =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

% all the jasco pumps are the same setup
Org1 = serial('COM19', 'BaudRate', 4800, 'DataBits', 8, 'Parity', 'none', 'StopBits', 2, 'Flowcontrol', 'hardware', 'Terminator', 'CR'); % set the serial object
fopen(Org1) % open the serial port


% unlike the BPR there is no hex involved
% general command format; fprintf(Org1, 'value command set') value is the numeric value for the parameter set by command, where command is the parameter to be set (see examples below)
% the reading command format is slightly different ; fprintf(Org1, 'command load p')


%settings
fprintf(Org1, '215 pmax set') % this sets max P to 215 bar 

fprintf(Org1, '0.200 flowrate set') % this sets the flowrate to 0.2 ml/min

fprintf(Org1, '0 cfcp set') % this sets the constant pressure of constant flow mode, 0=constant flow and 1 = constant pressure

fprintf(Org1, '17.0 offtimer set') % this sets the pump off timer to 17.0 hours

fprintf(Org1, '23.4 ontimer set') % this sets the pump on timer to 23.4 hours

fprintf(Org1, '235 press set') % this sets the pressure to 235 bar (when in CP mode)

% program editing

% before changing program file the file must be opened and before running it
% must be closed and then selected - if not editing a program just select it
fprintf(Org1, '0 openfile') % open file zero (range 0 to 9)

% program steps have stadard format; fprintf(Org1, 'time value function set')
% where time is in mins (to 0.01 of a min i.e. 0.6 s)
% where value is the value that the function is set to
% function is the function to set e.g. flow or composition etc
% examples below
fprintf(Org1, '0.10 0.1 flow set') % at time 0.10 mins set flow rate to 0.1 mLmin-1
fprintf(Org1, '0.50 1.0 flow set') % at time 0.50 mins set flow rate to 0.5 mLmin-1
fprintf(Org1, '1.50 100 pmax set') % at time 1.50 mins set pmax to 100 bar
fprintf(Org1, '1.60 50 pmin set') % at time 1.60 mins set pmin to 50 bar
fprintf(Org1, 'closefile') % close file after input of steps

fprintf(Org1, '0 fileno set') % set the program to run (range 0 to 9) this command must be sent before running a program to tell the pump which program to run

% running the pump

% commands for telling the pump to pump are of the format; value pump set
% where value determines what you want the pump to do (0 to 3 and 6 to 8 - don't know what the other numbers do)
% if using a time program, the command for setting the which time program to
% use must be sent first (shown above)

fprintf(Org1, '0 pump set') % start pumping
fprintf(Org1, '1 pump set') % stop pumping
fprintf(Org1, '2 pump set') % pump hold - the time advance in the program is halted (paused) and the current conditions (i.e. flow rate) are maintained until hold is released
fprintf(Org1, '3 pump set') % hold is released 
fprintf(Org1, '6 pump set') % initial conditions (i.e. whatever is set and the time in the time program is not advancing - but now can't change settings - same as pressing Program run once on the pump
fprintf(Org1, '7 pump set') % run the time program
fprintf(Org1, '8 pump set') % rerun the program, go back to initial conditions and then start the program

% example command sequence
fprintf(Org1, '0.200 flowrate set') % set the initial flow
fprintf(Org1, '0 fileno set') % set the program to run (range 0 to 9), assuming it has already been set (see above)
fprintf(Org1, '6 pump set') % start pumping at the initial conditions    
pause(5) % wait 5 seconds (or however long)
fprintf(Org1, '7 pump set') % start the time program  
pause(3000) % wait for end of prog (prob best to do this with timer instead of pause)
fprintf(Org1, '1 pump set') % stop pumping

% readings
fprintf(Org1, 'a_flow load p') % ask for flow rate
var1 = fscanf(Org1); % this reaturns the flow rate in ml/min

fprintf(Org1, 'a_press load p') % ask for the current pressure
var2 = fscanf(Org1); % this returns the pressure in bar (can handle the incorrect negative readings jasco stuff sometimes gives)

fprintf(Org1, 'press load p') % asks for the set pressure in constant pressure mode
out = fscanf(Org1); % returns the set pressure in bar as a string

fprintf(Org1, 'cfcp load p') % asks if it is constant flow (returns 0) or constant pressure (returns 1)
out = fscanf(Org1);

fprintf(Org1, 'a_pmax load p') % ask for current max pressure setting
out = fscanf(Org1);  %returns max pressure setting in bar

fprintf(Org1, 'a_pmin load p') % ask for current min pressure setting
out = fscanf(Org1); % returns min pressure setting in bar

fprintf(Org1, 'current_time load p') % ask for current time in the program
out = fscanf(Org1); % returns current time in seconds

% if there is an error such as overpressure then the pump outputs it
% directly into the buffer even if not asking for it, thus when run
% fprint(pump, 'a_press load p') and fscanf(pump) the response is a error
% message such as '%%[TROUBLE OVER PRESS]%%' and the pressure response if
% but in the buffer so running fscanf again will pull it out.

fprintf(CO2, 'trouble load p') % this is how to ask the pump what is going wrong
trouble = fscanf(CO2); % get the trouble sitution
% the response is a number which identifies the sitution
% 0 == no trouble
% 1 == under pressure
% 4 == external stop (i.e. if this was controlled by the proper HPLC system
% this could be the control from the main pump to a slave pump)
% 8 == pump timer off (if the pump on timer has not been reached yet or if
% the pump off timer has been reached)
% don't know  what fills in the gaps or if there is anything above 8

fprintf(CO2, '0 trouble set') % this rests the trouble situation
% like manually pressing clear on the pump, although unlike the manual
% situation you can still send commands such as start pumping when the
% trouble status has not been cleared -- generally ok becuase if its an
% overpressure it will just occur again and stop the pumping

Contact us