kk
#include <stdint.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
#include <string.h>
#include <pthread.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <stdlib.h>
#include <time.h>
#include <linux/gpio.h>
#include "ladder.h"

#define MAX_BUF 64
#define MAX_INPUT 2
#define MAX_OUTPUT 2
#define INPUT_PIN in
#define OUTPUT_PIN out

#define SYSFS_GPIO_DIR "/sys/class/gpio"
int inBufferPinMask[MAX_INPUT]={161,162};
int outBufferPinMask[MAX_OUTPUT]={171,178};

#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))

int digitalRead(int fd)
{
char ch;
lseek(fd,0L,SEEK_SET);
read(fd,&ch,1);
if(ch != '0')
{
return 1;
}
else
{
return 0;
}
}
int digitalWrite(int fd,int value)
{
if(value == 0)
{
write(fd, "0", 2);
}
else
{
write(fd, "1", 2);
}
return 0;
}
/*
void TegraGPIOSetup()
{
int export_fd;
export_fd = open("/sys/class/gpio/export", O_WRONLY);
if(-1 == export_fd)
{
printf(open gpio export file error\r\n");
exit(1);
}
close(export_fd);
char buf[MAX_BUF];

}
*/
int gpio_set_dir(unsigned int gpio, unsigned int out_flag)
{
int fd, len;
char buf[MAX_BUF];

len = snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR"/gpio%d/direction", gpio);

fd = open(buf, O_WRONLY);
if (fd < 0) {
perror("gpio/direction");
return fd;
}

if (out_flag)
write(fd, "out", 4);
else
write(fd, "in", 3);

close(fd);
return 0;
}
/*
void sleep_ms(int milliseconds)
{
struct timespec ts;
ts.tv_sec = milliseconds / 1000;
ts.tv_nsec = (milliseconds % 1000) * 1000000;
nanosleep(&ts, NULL);
}

void *exchangeData(void *arg)
{
sleep_ms(250);//wait exchange data with PLC program
struct timespec timer_start;
clock_gettime(CLOCK_MONOTONIC, &timer_start);
char buf[MAX_BUF];
while(1)
{

printf("=============================================\n");
for(int i=0;i<MAX_INPUT;i++)
{
snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR"/gpio%d/value",inBufferPinMask[i]);
digitalRead(buf);
}
for(int i=0;i<MAX_OUTPUT;i++)
{
snprintf(buf,sizeof(buf),SYSFS_GPIO_DIR"/gpio%d/value",outBufferPinMask[i]);
digitalWrite(buf,*bool_output[i/8][i%8]);
}
//errflag.loopcount ++;
printf("=============================================\n");

sleep_until(&timer_start, uart_cycle_time);

}
}*/
void initializeHardware()
{
//TegraGPIOSetup();
for(int i=0; i<MAX_INPUT;i++)
{
gpio_set_dir(inBufferPinMask[i],INPUT_PIN);
}
for(int i=0; i<MAX_OUTPUT; i++)
{
gpio_set_dir(outBufferPinMask[i],OUTPUT_PIN);
}
pthread_t thread;
int pid_uart = pthread_create(&thread, NULL, exchangeData, NULL);
}
void updateBuffersIn()
{
pthread_mutex_lock(&bufferLock); //lock mutex
char buf[MAX_BUF];
//Digital Input
for (int i = 0; i < MAX_INPUT; i++)
{
if (bool_input[i/8][i%8] != NULL)
{
snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR"/gpio%d/value",inBufferPinMask[i]);
*bool_input[i/8][i%8] = digitalRead(buf);
}
}
pthread_mutex_unlock(&bufferLock);
}
void updateBuffersOut()
{
pthread_mutex_lock(&bufferLock);
for(int i=0; i<MAX_OUTPUT ;i++)
{
if (bool_output[i/8][i%8] != NULL)
{
snprintf(buf,sizeof(buf),SYSFS_GPIO_DIR"/gpio%d/value",outBufferPinMask[i]);
digitalWrite(buf,*bool_output[i/8][i%8]);
}
}
pthread_mutex_unlock(&bufferLock);
}





Quote 0 0
kk
I tried to modify the blank. cpp file
Quote 0 0
kk
The result of compilation is like this:

Optimizing ST program...
Generating C files...
POUS.c
POUS.h
LOCATED_VARIABLES.h
VARIABLES.csv
Config0.c
Config0.h
Res0.c
Moving Files...
Compiling for Windows
Generating object files...
Generating glueVars...
varName: __IX0_0 varType: BOOL
varName: __QX0_0 varType: BOOL
Compiling main program...
In file included from /usr/include/c++/5/cstdint:35:0,
from /usr/local/include/openpal/logging/LogEntry.h:24,
from /usr/local/include/openpal/logging/ILogHandler.h:24,
from /usr/local/include/asiodnp3/DNP3Manager.h:24,
from dnp3.cpp:5:
/usr/include/c++/5/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
#error This file requires compiler and library support \
^
In file included from /usr/local/include/openpal/logging/LogEntry.h:26:0,
from /usr/local/include/openpal/logging/ILogHandler.h:24,
from /usr/local/include/asiodnp3/DNP3Manager.h:24,
from dnp3.cpp:5:
/usr/local/include/openpal/logging/LogFilters.h:40:21: error: expected ‘)’ before ‘filters_’
LogFilters(int32_t filters_) : filters(filters_)
^
/usr/local/include/openpal/logging/LogFilters.h:43:20: error: ‘int32_t’ has not been declared
inline bool IsSet(int32_t levels) const
^
/usr/local/include/openpal/logging/LogFilters.h:53:2: error: ‘int32_t’ does not name a type
int32_t GetBitfield() const
^
/usr/local/include/openpal/logging/LogFilters.h:60:2: error: ‘int32_t’ does not name a type
int32_t filters;
^
/usr/local/include/openpal/logging/LogFilters.h: In constructor ‘openpal::LogFilters::LogFilters()’:
/usr/local/include/openpal/logging/LogFilters.h:37:17: error: class ‘openpal::LogFilters’ does not have any field named ‘filters’
LogFilters() : filters(0)
^
/usr/local/include/openpal/logging/LogFilters.h: In member function ‘bool openpal::LogFilters::IsSet(int) const’:
/usr/local/include/openpal/logging/LogFilters.h:45:20: error: ‘filters’ was not declared in this scope
return (levels & filters) != 0;
^
/usr/local/include/openpal/logging/LogFilters.h: In member function ‘bool openpal::LogFilters:😮perator&(const openpal::LogFilters&😉 const’:
/usr/local/include/openpal/logging/LogFilters.h:50:20: error: ‘const class openpal::LogFilters’ has no member named ‘filters’
return IsSet(rhs.filters);
^
In file included from /usr/local/include/asiodnp3/DNP3Manager.h:25:0,
from dnp3.cpp:5:
/usr/local/include/openpal/executor/TimeDuration.h: At global scope:
/usr/local/include/openpal/executor/TimeDuration.h:66:46: error: ‘int64_t’ was not declared in this scope
class TimeDuration : public TimeDurationBase<int64_t>
Quote 0 0
thiagoralves
You need to use the "Blank with DNP3 (linux only)" option on the Hardware tab.
Quote 0 0