赞
踩
-
- #include <iostream>
- #include"snap7.h"
- #include <ctime>
-
- using namespace std;
-
- unsigned char Snap7Rcv[100];
- unsigned char Snap7RcvM226Es[100];
- unsigned char Snap7RcvM226Esvb[100];
- bool Snap7RcvM226EsBitS[100];
- TS7Client* mClient;
- void mSnap7GetDataFromS71200Db()
- {
- mClient = new TS7Client;
- mClient->ConnectTo("192.168.2.202", 0, 1);
- mClient->DBRead(9,0,100,&Snap7Rcv);
- mClient->Disconnect();
- delete mClient;
- }
-
- void mSnap7GetDataFromM226EsMbBlock()
- {
- mClient = new TS7Client;
- mClient->ConnectTo("192.168.2.201", 0,0);
- mClient->MBRead(500,100, &Snap7RcvM226Es);
- mClient->Disconnect();
- delete mClient;
- }
- void mSnap7GetDataFromM226EsVbBlock()
- {
- mClient = new TS7Client;
- mClient->ConnectTo("192.168.2.201", 0, 0);
- mClient->DBRead(1, 2000,100, &Snap7RcvM226Esvb);
- mClient->Disconnect();
- delete mClient;
- }
-
- void Delay(int time)
- {
- clock_t now = clock();
- while (clock() - now < time);
- }
- int main()
- {
- while (true)
- {
- mSnap7GetDataFromS71200Db();
- mSnap7GetDataFromM226EsMbBlock();
- mSnap7GetDataFromM226EsVbBlock();
-
- Delay(1000);
- for (int i = 0; i < 100; i++)
- {
- //cout << "mSnap7GetDataFromS71200Db-Snap7DB.Snap7Byte" << "[" << i << "]" << "=" << (int)Snap7Rcv[i] << endl;
- //cout << "mSnap7GetDataFromM226ES_MB-Snap7MB" << "[" << 500 + i << "]" << "=" << (int)Snap7RcvM226Es[i] << endl;
- cout << "mSnap7GetDataFromM226ES_VB-Snap7VB" << 2000 + i << "=" << (int)Snap7RcvM226Esvb[i] << endl;
-
- }
- }
-
- }
-
- void mSnap7GetDataFromM226EsVbBlock()
- {
- mClient = new TS7Client;
- mClient->ConnectTo("192.168.2.201", 0, 0);
- mClient->DBRead(1, 2000,100, &Snap7RcvM226Esvb);
- mClient->Disconnect();
- delete mClient;
- }
https://blog.csdn.net/lzc881012/article/details/135356054?spm=1001.2014.3001.5501https://blog.csdn.net/lzc881012/article/details/135356054?spm=1001.2014.3001.5501https://blog.csdn.net/lzc881012/article/details/135345037?spm=1001.2014.3001.5501https://blog.csdn.net/lzc881012/article/details/135345037?spm=1001.2014.3001.5501
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。