- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » Problem while reading data from arduino
Page Start Prev 1 Next End
Problem while reading data from arduino
Problem while reading data from arduino
May-02-16 14:30:54
Hi,
I am trying to communicate with arduino through Serial port using Modelica_DeviceDrivers package. I'm successfully sending the data (sample code below).
Code:
model arduino
parameter String Device_name = "COM5";
import Modelica_DeviceDrivers.Communication.SerialPort;
import Modelica_DeviceDrivers.Utilities.Types.SerialBaudRate;
import Modelica_DeviceDrivers.Utilities.Types.ByteOrder;
import Modelica_DeviceDrivers.Communication.SerialPort_;
import Modelica_DeviceDrivers.Packaging.SerialPackager;
import Modelica_DeviceDrivers.Packaging.SerialPackager_;
parameter SerialBaudRate baud = SerialBaudRate.B9600;
parameter ByteOrder byteorder = ByteOrder.BE;
SerialPort OpenPort = SerialPort.constructor(Device_name, 16 * 1024, 0, 0, baud);
SerialPackager pkg = SerialPackager.constructor(4608);
parameter Integer S1[1] = {50};
algorithm
SerialPackager_.setPos(pkg, 0);
SerialPackager_.addInteger(pkg, S1, byteorder);
SerialPort_.sendTo(OpenPort, pkg, 4608);
end arduino;
But I'm not able to receive data from arduino. (See the code below).
Code:
model arduinoread
parameter String Device_name = "COM5";
import Modelica_DeviceDrivers.Communication.SerialPort;
import Modelica_DeviceDrivers.Utilities.Types.SerialBaudRate;
import Modelica_DeviceDrivers.Utilities.Types.ByteOrder;
import Modelica_DeviceDrivers.Communication.SerialPort_;
import Modelica_DeviceDrivers.Packaging.SerialPackager;
import Modelica_DeviceDrivers.Packaging.SerialPackager_;
parameter SerialBaudRate baud = SerialBaudRate.B9600;
parameter ByteOrder byteorder = ByteOrder.LE;
SerialPort readPort = SerialPort.constructor(Device_name, 16 * 1024, 0, 1, baud);
SerialPackager pkg = SerialPackager.constructor(4608);
//SerialPackager pkg1 = SerialPackager.constructor(4608);
//parameter Integer S1[1] = {50};
//Real n;
Integer I[16];
algorithm
SerialPackager_.setPos(pkg, 0);
SerialPort_.read(readPort,pkg);
//n=SerialPort_.getReceivedBytes(readPort);
I:=SerialPackager_.getInteger(pkg,16,byteorder);
end arduinoread;
Can anyone help me regarding this?
- swaroop.katta
- 23 Posts
Page Start Prev 1 Next End
- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » Problem while reading data from arduino
There are 0 guests and 0 other users also viewing this topic