void EthercatIo::InitializeConnection() { pAddr = &Addr; nPort = AdsPortOpen(); nErr = AdsGetLocalAddress(pAddr); if (nErr) { std::cerr << "Error: AdsGetLocalAddress: " << nErr << '\n'; failInInitializing = true; } pAddr->port = 801; //10.112.98.1.1.1 netId local in lepuski pAddr->netId.b[0]=10; pAddr->netId.b[1]=112; pAddr->netId.b[2]=98; pAddr->netId.b[3]=1; pAddr->netId.b[4]=1; pAddr->netId.b[5]=1; // Creating handles to variables nErr=AdsSyncReadWriteReq(pAddr, ADSIGRP_SYM_HNDBYNAME, 0x0, sizeof(ULONG), &hInputs, sizeof(".FromADS"),".FromADS"); if(nErr) { std::cerr << "Error: AdsSyncReadWriteReq: " << nErr << '\n'; failInInitializing=true; } nErr=AdsSyncReadWriteReq(pAddr, ADSIGRP_SYM_HNDBYNAME, 0x0, sizeof(ULONG), &hOutputs, sizeof(".FromADS"),".FromADS"); if(nErr) { std::cerr << "Error: AdsSyncReadWriteReq: " << nErr << '\n'; failInInitializing=true; } }
int main(int argc, char **argv) { short unsigned int nAdsState; short unsigned int nDeviceState; AdsVersion Version; AdsVersion *pVersion = &Version; char pDevName[16]; long nErr; AmsAddr Addr; PAmsAddr pAddr = &Addr; /* Open communication port on the ADS router */ AdsPortOpen(); /* set the target ip AMS Net Id */ /* When the address is defined */ //pAddr->netId = (AmsNetId) { { //192, 168, 1, 72, 1, 1}}; /* if the server runs on the local address */ AdsGetLocalAddress(pAddr); /* PLC Port */ pAddr->port = AMSPORT_LOGGER; /* example, read state */ nErr = AdsSyncReadStateReq(pAddr, &nAdsState, &nDeviceState); if (nErr) printf("Error: AdsSyncReadStateReq: %ld\n", nErr); else { printf("AdsState: %d\n", nAdsState); printf("DeviceState: %d\n", nDeviceState); } /* Read device information */ nErr = AdsSyncReadDeviceInfoReq(pAddr, pDevName, pVersion); if (nErr) printf("Error: AdsSyncReadDeviceInfoReq: %ld\n", nErr); else { printf("Name: %s\n", pDevName); printf("Version: %d\n", (int)pVersion->version); printf("Revision: %d\n", (int)pVersion->revision); printf("Build: %d\n", pVersion->build); } /* Close communication port */ nErr = AdsPortClose(); if (nErr) printf("Error: AdsPortClose: %ld", nErr); return 0; }
// end of init_gripper_para bool init_gripper_motion() { long nErr,nPort,add0,add1,add2; // just like hResult for VCI CAN communication nErr = 0; // it seems that when it is not 0, it indicates error pAddr = &Addr; nPort = AdsPortOpen(); // in fact, this var is not used nErr = AdsGetLocalAddress(pAddr); std::cout<<"initialize gripper ..."<<std::endl; add1 = 0x27; add2 = 0x01; // byte 0 pAddr->port = 300; // it is the same for both grippers add0 = 0x11004; dwData = 0x00; nErr = AdsSyncWriteReq(pAddr,add0,add1,add2,&dwData); if (nErr){ std:: cerr << "Error: initial_gripper::AdsSyncWriteReq 1 : " << nErr << '\n'; return false; } dwData=0x01; nErr = AdsSyncWriteReq(pAddr,add0,add1,add2,&dwData); if (nErr){ std::cerr << "Error: initial_gripper::AdsSyncWriteReq 2 : " << nErr << '\n'; return false; } GoToPosReqFlag = true; gPos = 0; Speed = 255; Force = 255; //Sleep(8000); return true; }
bool init_gripper_para() { long nErr,nPort,add0,add1,add2; // just like hResult for VCI CAN communication nErr = 0; // it seems that when it is not 0, it indicates error pAddr = &Addr; nPort = AdsPortOpen(); // in fact, this var is not used nErr = AdsGetLocalAddress(pAddr); if(nErr) { std::cerr << "Error: AdsGetLocalAddress: " << nErr << std::endl; return false; } pAddr->port = 300; // it is the same for both grippers add0=0x11004; GoToPosReqFlag = false; Pos = 0; Speed = 200; Force = 100; }