Thread Tools  
JennyRead
Junior Member
 
Join Date: Dec 2007
Location: Newcastle, UK
JennyRead is on a distinguished road Posts: 3
using RB-530 with Matlab, Posted January 2nd, 2008 #1
Hi,

can anyone give me a code fragment showing how to read key presses on the RB-530 response box into Matlab?

Many thanks for any help,

Jenny
Reply With Quote
Hisham
Founder
 
Join Date: Aug 2006
Location: San Pedro, CA
Hisham is on a distinguished road Posts: 1,124
Posted February 6th, 2008 #2
Cedrus doesn't currently provide code fragment showing how to read key presses from our response pads. If someone is reading this who does have such code fragment, we'd be happy to post it on our web site and give you full credit for it.

If there is enough interest, we'd be happy to create a sub-forum for Matlab users who want to interface with Cedrus' hardware products.
Reply With Quote
Steve
Junior Member
 
Join Date: Nov 2006
Steve is on a distinguished road Posts: 6
Dear Jenny

Here's some hacked-together code for a cedrusxid.m function file we wrote today for you.

function [button time] = cedrusxid

s1 = serial('COM2', 'BaudRate', 115200,'DataBits', 8, 'StopBits', 1, 'FlowControl', 'none', 'Parity', 'none', 'Terminator', 'CR', 'Timeout', 400, 'InputBufferSize', 16000);

fopen(s1);

% % Sets the device protocol to XID mode
% % Note: char(13) sends the Carriage Return terminator
%
% fprintf(s1,['c10',char(13)]);
%
% % Debug information from http://www.cedrus.com/xid/properties.htm
% %
% % Note: 0 is ASCII value 48, 1 is ASCII value 49, and so forth.
%
% fprintf(s1,['_d3',char(13)]);
% fread(s1,1)
% fprintf(s1,['_d1',char(13)]);
% fscanf(s1)

% Sets the device protocol to XID mode
% Note: char(13) sends the Carriage Return terminator

fprintf(s1,['c10',char(13)]);

% XID devices send six bytes of information in the following format:
% <k><key info><RT>:
%
% The first parameter is simply the letter k, lower case
%
% The second parameter consists of one byte, divided into the following
% bits
%
% Bits 0-3 store the port number. For Lumina LP-400, the push buttons and
% scanner trigger are on port 0; the RJ45 I/O lines are on port 1.
% For SV?1, voice key is on port 2 and the RJ45 is on port 1 there is
% no port 0. For the RB-x30 response pads, the push buttons are on port 0
% and the RJ45 port is on port 1.
%
% Bit 4 stores an action flag. If set, the button has been pressed. If
% cleared, the button has been released.
%
% Bits 5-7 indicate which push button was pressed.
%
% The reaction time consists of four bytes and is the time elapsed since
% the Reaction Time timer was last reset. See description of command "e5".
%
% Information taken from http://www.cedrus.com/xid/protocols.htm

response = fread(s1,6);

% Extracts byte 2 to determine which button was pushed

button = (response(2));

% Extracts bytes 3-6 and is the time elapsed in milliseconds since the
% Reaction Time timer was last reset
%
% For more information about the use of XID timers refer to
% http://www.cedrus.com/xid/timing.htm

time = (response(3)+(response(4)*256)+(response(5)*65536) +(response(6)*(65536*256)));

fclose(s1);



Hope this helps.

Steve Elliott
--
Cambridge Research Systems Ltd.
www.crsltd.com
Attached Files
File Type: zip cedrusxid.zip (1.0 KB, 54 views)
Reply With Quote
Steve
Junior Member
 
Join Date: Nov 2006
Steve is on a distinguished road Posts: 6
Using Cedrus RB x30 devices in MATLAB, Posted March 28th, 2008 #4
Jenny Read has created this web page to describes how she got the RB-530 working in MATLAB under Windows XP.
Reply With Quote
JennyRead
Junior Member
 
Join Date: Dec 2007
Location: Newcastle, UK
JennyRead is on a distinguished road Posts: 3
Posted April 1st, 2008 #5
Thanks Steve! I'll be happy to hear anyone else's experiences with either this code or their own.... Best wishes, Jenny
Reply With Quote
jasnam
Junior Member
 
Join Date: May 2008
Location: uni of liverpool
jasnam is on a distinguished road Posts: 3
Posted May 13th, 2008 #6
jenny, thanks for setting up the website with tips on how to use the cedrus buttonbox.

I've recently acquired RB530. on installing it, I also experienced that after installing the usb device drivers, I also had an unknown device (serial port) detected and had to install drivers for that - afterwards i could see com3 assigned to the RB530.

I downloaded the matlab scripts and am trying to use them now. However, when I try to use the cedrusresponsebox.m script, on trying to open the communication with it by
mybox = CedrusResponseBox('Open', 'COM3') i get the following error:
??? Error using ==> CedrusResponseBox
Too many output arguments.

Error in ==> main_Scone_control at 35
mybox = CedrusResponseBox('Open', 'COM3');

i think there must be some kind of error in the way the script runs on my version of matlab (i've got 7.3.0). Any tips?
Reply With Quote
jasnam
Junior Member
 
Join Date: May 2008
Location: uni of liverpool
jasnam is on a distinguished road Posts: 3
Posted May 13th, 2008 #7
I've had a closer look and identified the problem -

the try catch loop under the 'open' command is failing and this is causing the output argument to not get assigned - this is probably occuring due to the com port being perpetually busy. No amount of windows/matlab restarting is sufficient in freeing it up. Any tips on how to fix this problem?
Reply With Quote
Hisham
Founder
 
Join Date: Aug 2006
Location: San Pedro, CA
Hisham is on a distinguished road Posts: 1,124
Posted May 13th, 2008 #8
Quote:
this is probably occuring due to the com port being perpetually busy
I can't really help with Matlab-specific issues; but if the COM port is busy, this usually means one of two things: either it's being used by another application, or you have the wrong COM port number.

To determine for sure which COM port the USB driver has assigned to your response pad, use Windows' Device Manager. See this web page on Determining or Changing the USB Driver's COM Port Setting.

Also, are all the DIP switches down?
Reply With Quote
jasnam
Junior Member
 
Join Date: May 2008
Location: uni of liverpool
jasnam is on a distinguished road Posts: 3
Posted May 13th, 2008 #9
Hisham, thanks for your quick reply.

I had determined the port using device manager, as suggested on the website.

Concerning the dip switches, they were set to 1,2up 3,4 down, as recommended on the Jenny Reid webiste ('RB series' mode). Is this accurate?
Reply With Quote
Hisham
Founder
 
Join Date: Aug 2006
Location: San Pedro, CA
Hisham is on a distinguished road Posts: 1,124
Posted May 13th, 2008 #10
Yes, the DIP switch settings sound right.

If you've modified Jenny's code to reflect the real serial COM port number and it's still not working, I really don't know what else it could be other than another process that has the same COM port open.
Reply With Quote
Thread Tools
Posting Rules
Forum Jump:
Copyright Cedrus Corporation, 1991-2014.
All times are GMT -7. The time now is 05:31 PM.