Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: rapsberry 3 - How to force GPIO Ouput to LOW level

rapsberry 3 - How to force GPIO Ouput to LOW level 5 years 6 months ago #9874

  • cresus
  • cresus's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 7
  • Karma: 0
Configuration:
-Raspberry Pi 3
-Pwr55


Hi everyone,
I am trying to manage GPIO of my Rpi3 and i have a problem.
If a output GPIO is HIGH before i stop/reset the Plc, it stays after always HIGH. Not good...
I want to force all my Ouputs to LOW level when Plc don't RUN.

I wrote a application "ra_appl" for to fix that.
I am not sure that it is the best way...
I use WiringPi library in my application for to force output when function close() is called.
But it doesn't work because I think close() is never called when i stop/reset the Plc.
Below the code of ra_appl.

#include "pwr.h"
#include "rt_appl.h"
#include "rt_mh_appl.h"
#include "co_error.h"
#include "rt_errh.h"
#include "co_time.h"
#include <wiringPi.h>
#include <stdio.h>

using namespace std;
#include <iostream>

#define LedPin23 4 //GPIO 23
#define LedPin24 5 //GPIO 24

pwr_tOid m_apploid;
pwr_tStatus sts;
pwr_tUInt32 num;
mh_sApplMessage msg;
pwr_tUInt32 msgid;

class ra_appl : public rt_appl {
public:
ra_appl() : rt_appl( "ra_appl", errh_eAnix_appl1,0.1) {}
void open();
void close();
void scan();
};

void ra_appl::open()
{
// Link to database objects
if(wiringPiSetup() == -1)
{
cout << "setup wiringPi failed !\n" << endl;
//return -1;
}

pinMode(LedPin24, OUTPUT);

cout << "OK open" << endl;
}

void ra_appl::close()
{
// Unlink to database objects
digitalWrite(LedPin23, LOW); //led off
digitalWrite(LedPin24, LOW); //led off
cout << "OK close" << endl;
}

void ra_appl::scan()
{
cout << "OK scan" << endl;
}


int main()
{
ra_appl appl;
appl.init();
appl.register_appl( "Nodes-Gpio2-ra_myappl");
appl.set_scantime(1.0);

m_apploid=appl.apploid();
cout << "toid.oix=:" <<m_apploid.oix <<endl;
cout << "toid.vid=:" <<m_apploid.vid <<endl;
sts = mh_ApplConnect( m_apploid, mh_mApplFlags(0), "", mh_eEvent_Info, mh_eEventPrio_A, mh_mEventFlags_Bell, "", &num);
if (EVEN(sts)) throw co_error(sts);

memset( &msg, 0, sizeof(msg));
msg.EventFlags = mh_mEventFlags(mh_mEventFlags_Returned | mh_mEventFlags_NoObject | mh_mEventFlags_Bell);
time_GetTime( &msg.EventTime);
strcpy( msg.EventName, "Message from ra_myappl");
strcpy( msg.EventText, "I'm up and running now !");
msg.EventType = mh_eEvent_Alarm;
msg.EventPrio = mh_eEventPrio_B;
sts = mh_ApplMessage( &msgid, &msg);
if (EVEN(sts)) throw co_error(sts);

appl.mainloop();
}
Attachments:
Last Edit: 5 years 6 months ago by cresus.
The administrator has disabled public write access.

rapsberry 3 - How to force GPIO Ouput to LOW level 5 years 6 months ago #9876

  • claes
  • claes's Avatar
  • OFFLINE
  • Platinum Boarder
  • Posts: 3177
  • Thank you received: 502
  • Karma: 133
Hi cresus,

'Stop' sends out a terminate signal to all processes and causes the close() function to be called, while 'Reset' just kills all the processes and in this case close() is not called.

/Claes
The administrator has disabled public write access.
  • Page:
  • 1
Time to create page: 8.331 seconds