Saarland University
Lehrstuhl für Automatisierungstechnik

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Real-Time embedded Hardware simulation
PredKirK
post Oct 4 2012, 07:55 PM
Post #1


Newbie
*

Group: Members
Posts: 5
Joined: 18-September 12
Member No.: 625,864



ok i thought maybe someone could help me.... so after some more weeks I did it myself so maybe someone can need it.

Read a parameter value out of a file.... external c Code not working perfekt... always gets a warning maybe someone can help^^:
CODE

/* created by PredKirK, September 2012 */

#ifndef READSTATUS_C
#define READSTATUS_C

#  include <stdio.h>
#  include <stdlib.h>
#  include <errno.h>
#  include <string.h>

volatile int readstatus(const char* datei, const char* needle)
{
      
    FILE* fp;
    char zeile[30];
    char *ID;
    char zerlegung[30];
    char delimiter[] = "= ";
    char tempdata[30];
    int zeilenanzahl;
    int data;
    zeilenanzahl = 1;
    fp = fopen(datei, "r");
    while(!feof(fp))
    {
        fgets(zeile, 30, fp);
            if(strstr(zeile, needle)) {
               strcpy(zerlegung, zeile);
               ID = strtok(zerlegung,delimiter);
              
               while(ID != NULL) {
                        strcpy(tempdata, ID);
                         ID = strtok(NULL, delimiter);
                         }
               data = atoi(tempdata);
               }
        zeilenanzahl++;
    }
    fclose(fp);
        
    return data;
}
#endif


And the easyway to start a batch file "c://somewhere//test.bat" given as the string datei:
CODE

void startbatch(const char* datei) {
    system(datei);
    
}


To write in a txt-file I used the implemented fuction print()^^.

greetings PredKirK







--------------------
Dymola 7.1 , trying OpenModelica -> Hardware in the Loop, Real Time simulation
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
PredKirK
post Sep 18 2012, 08:41 AM
Post #2


Newbie
*

Group: Members
Posts: 5
Joined: 18-September 12
Member No.: 625,864



Hello,

These are my first written words in this forum so I hope that I didn't missed anything^^.

Right now I am working at my Bachelorthesis and wants to simulate a "thermal solar system" as a hardware-in-the-Loop application. Therefore I use a solar-controler(hardware) which needs temperatur information and offers pumpsignals and valvepositions in return.
To get a connection between the hardware and my computer I wrote a batch file on Putty-basis to export and import the actual status as .txt files.
Modelica is used to get the pump signals/valvepositions and computs the new temperatures in real-time.
I hope you understand the loop-process, but now I need some help in importing real-time information and exporting actual values to write the "temperature.txt":

- how can I continously read actual values out of a file? I used the readRealParameter-function(), but that works just one time. I tried it within an endless-loop-algorithm, but had no success at all.

- to update the information for Modelica/Dymola I have to run my batchfile ("export.bat") in a defined time-loop, do you know a way to run a batch file?

- in the end I have to write my temperature.txt file, I want to combine all of these 3. Steps in one Loop, that there is no fileconflict during writing and reading.

I hope I you understand my questions and help me solving it. I would like to do it in Dymola but I just found out that OpenModelica offers more visible file-transfer-functions ... if you say that OpenModelica is more helpful I would try to change my working program.

greeting
PredKirK


--------------------
Dymola 7.1 , trying OpenModelica -> Hardware in the Loop, Real Time simulation
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



Lo-Fi Version Time is now: 26th June 2019 - 02:43 AM