This repository has been archived on 2025-04-28. You can view files and clone it, but cannot push or open issues or pull requests.
EMS/3.Document/青海能高储能EMS工程/上位机工程/quxian/main.c

96 lines
2.2 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <math.h>
#include "script.h"
int readFile() {
char s[] = "/home/ctstor/ctfiles/maxvarindex";
//只读打开文件
int fd = open(s, O_RDONLY);
if(fd == -1) {
printf("error is %s\n", strerror(errno));
return;
}
printf("sucess fd = %d\n", fd);
char buf[100];
memset(buf, 0, sizeof(buf));
int a=3999;
//read返回0表示文件读取完毕
while(read(fd, buf, sizeof(buf) - 1) > 0) {
printf("%s\n", buf);
char * str=buf;
printf("%s-----\n", str);
sscanf(str,"%d",&a);
memset(buf, 0, sizeof(buf));
}
printf("%d---===--\n", a);
//别忘记关闭
close(fd);
return a;
}
int main()
{
//初始化
int nMaxIndex= readFile();
if (CreateRam(0,nMaxIndex)<1)
return;
int i,Number;
int StationNumber;
static int station[2] = {0,285};//0是电表的第一个变量285是综保的第一个变量没有综保不管
static temp1_index =8000; //中间变量
while(1){
Number=(int)GetSysItem(142)-1;
StationNumber=(int)GetSysItem(143)-1;
if(StationNumber==0)
{
for (i=0;i<=31;i++)//电表共有31个量
{
SetItemValue(0,temp1_index+i,GetItemValue(0,Number*31+i+station[StationNumber]));
}
//实时曲线
SetSysItem( 78 , Number*31+9+station[StationNumber]);//Pa
SetSysItem( 79 , Number*31+10+station[StationNumber]);//Pb
SetSysItem( 80 , Number*31+11+station[StationNumber]);//Pc
SetSysItem( 81 , Number*31+12+station[StationNumber]);//P
//历史曲线
SetSysItem( 94 , Number*31+9+station[StationNumber]);//Pa
SetSysItem( 95 , Number*31+10+station[StationNumber]);//Pb
SetSysItem( 96 , Number*31+11+station[StationNumber]);//Pc
SetSysItem( 97 , Number*31+12+station[StationNumber]);//P
}
else if(StationNumber==1)
{
for (i=0;i<116;i++)//综保共有116个量
{
SetItemValue(0,temp1_index+i,GetItemValue(0,Number*116+i+station[StationNumber]));
}
}
waitForMillisec(2000);
}
return 0;
}