Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unable to connect to Analog Input Module?
#1
Hi,

I have been having a problem using the analog input module. When I call the 'BpodAnalogin' function in MATLAB, there is an error message:

Code:
>> A = BpodAnalogIn("/dev/cu.usbmodem71558201")
Error in function OpenSerialPort: Incorrect argument type supplied
Discrepancy between a specified and supplied argument:
Specified Argument Description:
direction: Input
position: 1
presence:
formats allowed:
char
minimum M: 0
maximum M: unbounded
minimum N: 0
maximum N: unbounded
minimum P: 0
maximum P: 1
Provided Argument Description:
direction: Input
position: 1
presence: present
format:unclassified
number of dimensions: 2
M: 1
N: 1
P: 1
Error in function Close: Missing argument
Discrepancy between a specified and supplied argument:
Specified Argument Description:
direction: Input
position: 1
presence:
formats allowed:
double
minimum M: 1
maximum M: 1
minimum N: 1
maximum N: 1
minimum P: 1
maximum P: 1
Provided Argument Description:
direction: Input
position: 1
presence: absent
Error using BpodAnalogIn (line 74)
Error: unable to connect to Bpod Analog Input module.

However, I can see from BpodSystem.modules that the analog input module is connected and I have specified the correct port name in the function:

Code:
>> BpodSystem.Modules

ans =

 struct with fields:

             nModules: 5
          RelayActive: [0 0 0 0 0]
            Connected: [1 0 0 0 0]
                 Name: {'AnalogIn1'  'Serial2'  'Serial3'  'Serial4'  'Serial5'}
   Module2SM_BaudRate: [1312500 1312500 1312500 1312500 1312500]
      FirmwareVersion: [2 0 0 0 0]
        nSerialEvents: [15 15 15 15 15]
           EventNames: {[]  []  []  []  []}
              USBport: {'/dev/cu.usbmodem71558201'  []  []  []  []}

One thing I have noticed is that the baud rate of the port from BpodSystem.modules is 1312500. However, when I look into the MATLAB script of the 'BpodAnalogIn' function and the associated 'ArCOMObject_Ain' function, it seems like they assume the baud rate to be 115200. Therefore, I tried to change the baud rate on these 2 scripts to 1312500 and call the function again. Unfortunately, the error still occurs.

How can I get the analog input module working? FYI, I am using a Mac.

Many thanks,
Tin
Reply
#2
Hi Tin,

I suspect your issue is that you're using the wrong kind of MATLAB character array to specify your serial port name.
Double quotes create a string object. Single quotes create a character array.
If you try with single quotes, does it work?

Code:
A = BpodAnalogIn('/dev/cu.usbmodem71558201')

The BpodAnalogIn object uses the USB interface between the PC and the analog module.
Separately, the analog module communicates with the state machine via the Ethernet cable - and it returns a self description to the state machine over that channel when you run Bpod - so even if you haven't initialized the analog module's USB connection to the PC, the state machine can still detect it.
Regarding baud rates, 32-bit Arduino and Teensy boards use native USB connections, which communicate at their maximum speed regardless of what baud rate arguments you provide when initializing a serial object.
-Josh
Reply
#3
Hi Josh, 

Thank you very much for the detailed explanation! 

I have previously also tried with the single quotes. There was also an error unfortunately but it's different from the one with the double quotes:


Code:
>> A= BpodAnalogIn('/dev/cu.usbmodem71558201')
Error in function Close: Usage error
Invalid port handle -1 provided. No such port open. Maybe you closed it beforehand?
Error in function Close: Usage error
Invalid port handle -1 provided. No such port open. Maybe you closed it beforehand?
Error using BpodAnalogIn (line 74)
Error: unable to connect to Bpod Analog Input module.
 
For the past few days, I have switched to use Bpod in a Windows PC and there have been no issues at all. Maybe some additional software has to be installed to use the analog input module on Mac?

Best,
Tin
Reply
#4
Hi Tin,

From the error it looks like the PsychToolbox serial interface (IOPort) is having trouble opening the port.
On Mac, you may have better luck with MATLAB's Java serial interface.
You'll have to change one line of code - line 72 of BpodAnalogIn.m from:


Code:
obj.Port = ArCOMObject_Ain(portString, 115200);

to:
Code:
obj.Port = ArCOMObject_Ain(portString, 115200, 'Java');

Please let me know if this fixes the issue.
Also, what version of OSX are you using?
Thanks,
-Josh
Reply
#5
Hi Josh,

Thanks, this indeed fixed the issue.

FYI, I am using Catalina 10.15.6.

Best,
Tin
Reply
#6
Thanks! Now I know how to fix this issue! It's not hard at all as it seems.
Reply


Forum Jump: