Categories

See More
Popular Forum

MBA (4887) B.Tech (1769) Engineering (1486) Class 12 (1030) Study Abroad (1004) Computer Science and Engineering (988) Business Management Studies (865) BBA (846) Diploma (746) CAT (651) B.Com (648) B.Sc (643) JEE Mains (618) Mechanical Engineering (574) Exam (525) India (462) Career (452) All Time Q&A (439) Mass Communication (427) BCA (417) Science (384) Computers & IT (Non-Engg) (383) Medicine & Health Sciences (381) Hotel Management (373) Civil Engineering (353) MCA (349) Tuteehub Top Questions (348) Distance (340) Colleges in India (334)
See More

How to write and read channels in Wago 750-350 ethercat?

General Tech Bugs & Fixes

Max. 2000 characters
Tuteehub
Replies

usr_profile.png

User

( 7 months ago )

 

I have an EtherCat Wago 750-354 and I would like to do simple test for the output module (turn the leds on and off). I read the tutorial and I wrote short code for testing but I am not able to write the output module.

The tutorial link is: https://openethercatsociety.github.io/doc/soem/tutorial_8txt.html

and here is my code:

#define SLAVE_NR 1

void set_output_int8 (uint16 slave_no, uint8 module_index, int8 value)
{
  uint8 *data_ptr;

  data_ptr = ec_slave[slave_no].outputs;
  /* Move pointer to correct module index*/
  //data_ptr += module_index * 8;
  /* Read value byte by byte since all targets can't handle misaligned addresses */
  *data_ptr++ = value;
}

void set_output_bit (uint16 slave_no, uint8 module_index, uint8 value)
{
   /* Get the the startbit position in slaves IO byte */
   uint8 startbit = ec_slave[slave_no].Ostartbit;
   /* Set or Clear bit */
   if (value == 0)
      *ec_slave[slave_no].outputs &= ~(1 << (module_index - 1 + startbit));
   else
      *ec_slave[slave_no].outputs |= (1 << (module_index - 1 + startbit));
}


char IOmap[4096];
volatile int wkc;


int main(int argc, char **argv)
{
  int chk;

 //initialise SOEM
 if (ec_init("enp4s0f1"))
 {

   if ( ec_config_init(FALSE) > 0 )
  {
     std::cout<<"slave found and configured"<<ec_slavecount<<std::endl;

     ec_config_map(&IOmap);

     ec_configdc();

     std::cout<<"Slave mapped, state to SAFE_OP"<<std::endl;

     /* wait for all slaves to reach SAFE_OP state */
     ec_statecheck(1, EC_STATE_SAFE_OP,  EC_TIMEOUTSTATE * 4);


     std::cout<<"Request operational state for the slave"<<std::endl;

     ec_slave[1].state = EC_STATE_OPERATIONAL;
     /* send one valid process data to make outputs in slaves happy*/
     ec_send_processdata();
     ec_receive_processdata(EC_TIMEOUTRET);
     /* request OP state for all slaves */
     ec_writestate(1);
     chk = 40;
     /* wait for all slaves to reach OP state */
     do
     {
        ec_send_processdata();
        ec_receive_processdata(EC_TIMEOUTRET

what's your interest