Error in sending data from arduino to matlab - matlab

I want to run simple example in arduino and send data from arduino to matlab for drawing plot,
my arduino code is following:
#include <SoftwareSerial.h>
int i=0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.println(i);
i++;
}
and my matlab code is following:
arduino=serial('COM4','BaudRate',9600);
fopen(arduino)
x=linspace(1,100);
for i=1:length(x)
y(i)=instrfind(arduino);
y(i)=fscanf(arduino,'%d');
end
fclose(arduino);
disp('making plot..')
plot(x,y);
But I've faced with error! The following is matlab error:
Error using serial/fopen (line 72)
Open failed: Port: COM4 is not available. No ports
are available.
Use INSTRFIND to determine if other instrument
objects are connected to the requested device.
Error in kh (line 2)
fopen(Arduino)
and here is arduino error:
avrdude: ser_open(): can't open device "\\.\COM4": Access is denied.
My arduino uno (COM4) driver in device manager are installed.
I use matlab 2013a and َArduino 1.8.1 Genuino
How can I fix this error?

If you are using RS-232 for Arduino IDE/Monitor to communicate with your Arduino on COM4.
Since RS-232 is a point to point methodology, you can only have one program/device on each end unless you add a bunch of hijinks.
When you have the Arduino IDE/Monitor open it uses the com port and other programs are denied access.
I think you need to close the Arduino monitor program to release Com port 4 and then the Matlab program should be able to open the port.
PS : Test this using a terminal. Obviously the port needs to be open for the terminal to receive the arduino's prints. The terminal DOES open when you have the arduino ide open, but it DOES NOT open when the arduino's COM terminal is open. So theoretically, MATLAB shouldn't be having a problem when just the IDE is open.

This is how I solved the problem.
In device manager you will find the Arduino COM port.
Go to the Advance properties of the port
Set the COM port number to COM4
Then replug the USB.

Related

Why might `i2c_smbus_write_byte_data` be returning "Operation not permitted" on uClinux 2.4?

I am writing a C program with the aim of configuring a peripheral device (the CS5368 ADC) via the I2C interface of a Dante Brooklyn II, a board based on a Microblaze soft-core processor running uClinux 2.4.
I have implemented the configuration following the Dante OEM docs for guidance, however when running my program I am encountering an "Operation not permitted" (EPERM) error when attempting to write data to I2C using i2c_smbus_write_byte_data.
Here is the section of code containing the culprit call to i2c_smbus_write_byte_data:
// Set ADC I2S to "Slave mode all speeds".
printf("Set the CS5368 I2S mode to slave\n");
unsigned char adc_dif = 0x01; // I2S mode
unsigned char adc_mode = 0x03; // Slave mode all speeds
unsigned char data = 0x90 | (adc_dif << 2) | adc_mode;
result = i2c_smbus_write_byte_data(i2c_fd, CS5368_GCTL_MDE, data);
if (result < 0) {
perror("Failed to write to the 'Global Mode Control' register");
return -1;
}
Here is the code within context of the full source of the small program. The program begins by resetting the CS5368 via a GPIO pin before doing the configuration via I2C.
EPERM is returned whether or not I have the CS5368 wired up. I've been able to successfully configure the CS5368 using the I2C interface of an Arduino Uno, so the issue does not appear to be related to the CS5368.
To run the program I login to the board via telnet as root, so I doubt the error has anything to do with user permissions.
The OEM docs state:
The Brooklyn II module can operate as an I2C controller running at
100Khz and using 7 bit addressing mode. It supports multi-master
operation. I2C devices can be accessed from user application running
on the Brooklyn II module. The interface supports the SMBus (System
Management Bus) protocol, which is a subset from the I2C protocol.
It goes on to list the supported i2c_smbus_* functions including i2c_smbus_write_byte_data, so the issue does not appear to be related to lack of support for SMBus or I2C.
I came across a related issue where a user was getting an EPERM error code when attempting to use the I2C write API, however the solution appears to have been to use the i2c_smbus_* API instead which I am already doing.
Any advice on what could be causing this error code to be returned or how to debug the issue further would be greatly appreciated!
Edit: In case it helps, here is the full output, starting from logging onto the board via telnet after having moved the exe to /tmp via ftp:
$ telnet 169.254.72.245
Trying 169.254.72.245...
Connected to 169.254.72.245.
Escape character is '^]'.
login: root
Password:
BusyBox v1.23.2 (2018-05-31 11:33:18 AEST) hush - the humble shell
/ # cd /tmp
/var/tmp # ./cs5368-i2c-config
Open GPIO device
Set GPIO tristate outputs
Set GPIO pins low
Sleep for 10 secs
Set GPIO pins high
Close GPIO file descriptor
Searching for I2C device
Opening /dev/i2c-0
Setting I2C_SLAVE 4c...
I2C Interface found: /dev/i2c-0
Set the CS5368 as the slave
Set the CS5368 I2S mode to slave
Failed to write to the 'Global Mode Control' register: Operation not permitted

bladeRF simulink no device available error

I am connecting the bladeRF x115 to simulink with Matlab 2016a on a windows 10 PC.
I have followed the getting started guide on github:
www.nuand.com/bladeRF-doc/guides/bladeRF_windows_installer
Then I made a simple code as in the picture shown below:
I can simulate it only one time because when I tried to simulate it again I got the following error:
MATLAB System block 'testlinking/MATLAB System' error occurred when invoking 'setupImpl' method of 'bladeRF_Simulink'. The error was thrown from '
'C:\Program Files\bladeRF\matlab\bladeRF.m' at line 116
'C:\Program Files\bladeRF\matlab\bladeRF.m' at line 398
'C:\Program Files\bladeRF\matlab\bladeRF_Simulink.m' at line 364'.
Caused by:
libbladeRF error (-7) in bladeRF_open(): No devices available
Component:Simulink | Category:Block error
The reason for this error is because the led 2 is still blinking(device is in use). But it continues blinking even though I have closed matlab and simulink, and I don't know why?
Have a look at:
https://www.mathworks.com/matlabcentral/fileexchange/74591-communications-toolbox-support-package-for-bladerf-2-0?s_tid=mwa_osa_a
„Communications Toolbox Support Package for BladeRF 2.0“
Download the zip-file and navigate matlab to the directory bladerf.
This worked for me. The simulink block releases the bladerf-board so the Simulinkmodel can be stopped and restarted without problems/errors.
Your device is available with bladeRF cli?
Check:
bladeRF> info
Board: Nuand bladeRF 2.0 (bladerf2)
Serial #: 20f99xxxx
VCTCXO DAC calibration: 0x1de9
FPGA size: 301 KLE
FPGA loaded: yes
Flash size: 128 Mbit
USB bus: 2
USB address: 3
USB speed: SuperSpeed
Backend: libusb
Instance: 0
If is available close the bladerf cli and MATLAB. Open only MATLAB and check again.

How to use cam with matlab under Ubuntu16.04

My os is Ubuntu16.04, and Matlab vision is 2015b, I installed OS Generic Video Interface and USB Webcams,and I got this after run imaqhwinfo:
InstalledAdaptors: {'dcam' 'gentl' 'gige' 'linuxvideo'}
MATLABVersion: '8.6 (R2015b)'
ToolboxName: 'Image Acquisition Toolbox'
ToolboxVersion: '4.10 (R2015b)'
but while I run obj = videoinput('linuxvideo',1);preview(obj);I got this:
Error using videoinput (line 233) There are no devices installed for the specified ADAPTORNAME. See IMAQHWINFO.
and I also cannot run webcam:
No webcams have been detected. Please ensure the webcam is connected to the system.
how to solve this ? thanks for your help!

Error while Messaging with Huawei E3531 using matlab

I am using Huawei E3531 model for sending message by interfacing it with matlab. But it always shows an error. Do I need to unlock my Huawei dongle?
If not, what is the actual problem? I am using the following code:
clc;
clear all;
global BytesAvail;
global A;
global B;
tx ='ATI';
tx1=char(13);
tx2=char(26);
tx3='AT+CMGS="+919526018418"';
tx4= ' This is a test msg ';
tx5='AT+CMGF=1';
s = serial('COM5');
s.baudrate=9600;
fopen(s);
s.Terminator = 'CR';
fprintf(s,'%s', tx);
fprintf(s,'%s', tx1);
BytesAvail=s.BytesAvailable;
if(BytesAvail > 0), A=fread(s,BytesAvail,'char'); end
A;
sprintf('%c', A)
%%%%%%%%%%%%%%%Send SMS%%%%%%%%%%%%
fprintf(s,'%s', tx5);
fprintf(s,'%s', tx1);
fprintf(s,'%s', tx3);
fprintf(s,'%s', tx1);
fprintf(s,'%s', tx4);
fprintf(s,'%s', tx2);
BytesAvail=s.BytesAvailable;
if(BytesAvail > 0), B=fread(s,BytesAvail,'char'); end
B;
fclose(s)
The error is this
??? Error using ==> serial.fprintf at 144
An error occurred during writing.
Error in ==> message at 20
fprintf(s,'%s', tx);
>>
This error is caused by some virtual serial port drivers not supporting functionality equivalent to a physical serial port, and the way Matlab handles communication with the virtual serial port.
A possible solution would be to upgrade to the latest drivers (provided by the vendor of the serial port adapter).
If the error persists even with the latest drivers for the virtual serial port adapter, there is the possibility to use an alternate means of communication with serial COM ports through the VISA interface available through the Instrument Control Toolbox.
The VISA software libraries provided by Agilent/Keysight (Agilent IO Libraries) handle serial COM port communication separately from the Matlab serial port interface.
The Agilent IO Libraries can be downloaded at the following URL.
To add the virtual serial port as a VISA resource name (also refer to screenshots):
Open Agilent Connection Expert
Right click on on the desired serial port item ('COMxx') located in the 'Instrument I/O on ths PC' column, and select "Add Instrument" from the pop-up context menu.
In the following dialog box, uncheck "Auto-identify this instrument" and click OK.
Verify that the virtual serial port has been assigned a VISA resource name (for example ASRL4::INSTR)
Open MATLAB and run the following commands in the command window to show the VISA object constructor name corresponding to the VISA resource name:
visaInfo = instrhwinfo('visa', 'agilent');
visaInfo.ObjectConstructorName;
An example code for virtual serial port communication with MATLAB Instrument Control Toolbox and the VISA interface:
% --- Open and write
v = visa('agilent', 'ASRL4::INSTR');
fopen(v);
fprintf(v, 'abc');
fwrite(v, [97 98 99]);
fclose(v);
% --- Clean up
delete(v);
clear v;
Hope this helps,

"setsockopt SO_SNDBUF failed in tcp_connect()"

I have a problem in my C client, where I implemented a client gsoap program to invoke a web service.
Everything works fine on a Windows PC, but when I publish my code on a linux-based POS device, I receive the following error:
"setsockopt SO_SNDBUF failed in tcp_connect()"
Where should I start to debug this error, what could be the cause?
the errornum returned is 2
The code section that generates the error : (in stdsoap2.c)
if (setsockopt(sk, SOL_SOCKET, SO_SNDBUF, (char*)&len, sizeof(int))){
soap->errnum = soap_socket_errno(sk);
soap_set_sender_error(soap,
tcp_error(soap),
"setsockopt SO_SNDBUF failed in tcp_connect()",
SOAP_TCP_ERROR);
soap->fclosesocket(soap, sk);
#ifdef WITH_IPV6
freeaddrinfo(ressave);
#endif
return SOAP_INVALID_SOCKET;
}
How big is the len argument? It's possible that the value works on Windows, but is rejected by linux for some reason. Take a look at the actual values being submitted and see if they look reasonable.
You can also try reducing this down to a very small program that just sets up a socket and tries to replicate the call to setsockopt() and see if it still fails with the SO_SNDBUF size the main program is trying to use.
well it turned out to be very simple one!!
i just had to build the c/c++ files using the binaries dedicated for linux....
gsoap(wsdl2h,soapcpp2)
windows build uses winsock and linux build uses standard sockets
and the sockets on the 2 systems are differentes!
thats why i was receiving the socket error.
hope this help others, getting this socket error msg..