瀏覽代碼

20200930, 调试snap7通信

huli 4 年之前
父節點
當前提交
4a0f832357
共有 3 個文件被更改,包括 34 次插入27 次删除
  1. 13 18
      main.cpp
  2. 20 0
      snap7_communication/snap7_buf.h
  3. 1 9
      snap7_communication/snap7_communication_base.cpp

+ 13 - 18
main.cpp

@@ -98,27 +98,22 @@ int main(int argc,char* argv[])
 	std::cout << " huli test :::: " << " t_read = " << (int)t_write[0] << std::endl;
 	std::cout << " huli test :::: " << " AsDBRead result = " <<  result << std::endl;
 
-	return 0;
+//	return 0;
 
 
 
-//	char a=1;
-//	typeof(a) b=2;
-//
-//	typeid(a).name();
-//	std::cout << " huli test :::: " << " a = " << a << std::endl;
-//	std::cout << " huli test :::: " << " typeid(a).name() = " << typeid(a).name() << std::endl;
-//	std::cout << " huli test :::: " << " b = " << b << std::endl;
-//	std::cout << " huli test :::: " << " typeid(b).name() = " << typeid(b).name() << std::endl;
-//
-//
-//	std::vector<int> xcv;
-//	xcv.push_back(123);
-//	for_each(xcv.begin(), xcv.end(), myfunction);
-//
-////	foreach
-//
-//	return 0;
+	char a=1;
+	typeof(a) b=2;
+
+	typeid(a).name();
+	std::cout << " huli test :::: " << " a = " << a << std::endl;
+	std::cout << " huli test :::: " << " typeid(a).name() = " << typeid(a).name() << std::endl;
+	std::cout << " huli test :::: " << " b = " << b << std::endl;
+	std::cout << " huli test :::: " << " typeid(b).name() = " << typeid(b).name() << std::endl;
+	std::cout << " huli test :::: " << " typeid(int).name() = " << typeid(int).name() << std::endl;
+
+
+	return 0;
 
 
 	const char* logPath = "./";

+ 20 - 0
snap7_communication/snap7_buf.h

@@ -4,6 +4,10 @@
 #ifndef NNXX_TESTS_SNAP7_BUF_H
 #define NNXX_TESTS_SNAP7_BUF_H
 
+#include <string>
+#include <map>
+#include <vector>
+
 //Snap7协议的数据结构
 class Snap7_buf
 {
@@ -15,6 +19,16 @@ public:
 	    ONCE_COMMUNICATION               	= 1,    //一次通信
 	    LOOP_COMMUNICATION					= 2,	//循环通信
 	};
+
+	//变量信息
+	struct Variable_information
+	{
+	    std::string		m_variable_name;		//变量名称
+	    char 			m_variable_type;		//变量类型, 使用 typeid(a).name() 获取
+	    int 			m_variable_index;		//变量下标, 偏移量
+	    int 			m_variable_size;		//变量类型大小
+		int				m_variable_count;		//变量个数
+	};
 public:
 	Snap7_buf();
 	Snap7_buf(const Snap7_buf& other);
@@ -23,6 +37,9 @@ public:
 public://API functions
 	Snap7_buf(int id, int start_index, int size, Communication_mode communication_mode = NO_COMMUNICATION);
 	Snap7_buf(int id, int start_index, int size, void* p_buf_obverse, void* p_buf_reverse, Communication_mode communication_mode = NO_COMMUNICATION);
+
+	void obverse_to_reverse();
+	void reverse_to_obverse();
 public://get or set member variable
 	int get_id();
 	int get_start_index();
@@ -42,6 +59,9 @@ public://member variable
 	void*		mp_buf_reverse;			//Snap7协议的倒序数据指针, 用作s7通信, 内存由本类管理
 	//注:s7的通信的数据必须要倒序之后才能进行通信,
 
+//	std::map<std::string, Variable_information>			m_variable_information_map;
+	std::vector<Variable_information>		m_variable_information_vector;
+
 	Communication_mode 		m_communication_mode;	//Snap7协议的通信模式
 	//注:s7协议传输很慢, 防止相同的数据重复发送...
 

+ 1 - 9
snap7_communication/snap7_communication_base.cpp

@@ -239,20 +239,12 @@ Error_manager Snap7_communication_base::read_data_buf(Snap7_buf& snap7_buf)
 	if ( snap7_buf.m_communication_mode != Snap7_buf::NO_COMMUNICATION)
 	{
 		std::unique_lock<std::mutex> lck(m_communication_lock);
-//		int result = m_snap7_client.AsDBRead(snap7_buf.m_id, snap7_buf.m_start_index, snap7_buf.m_size, snap7_buf.mp_buf_reverse);
-
-		char t_buf[20] ;
-		memset(t_buf, 0, 20);
-		int result = m_snap7_client.AsDBRead(123, 10, 30, t_buf);
+		int result = m_snap7_client.AsDBRead(snap7_buf.m_id, snap7_buf.m_start_index, snap7_buf.m_size, snap7_buf.mp_buf_reverse);
 		if ( result == 0 )
 		{
 			m_snap7_client.WaitAsCompletion(100);
 		}
-		unsigned char ccccc = *((unsigned char*)t_buf);
-		std::cout << " huli test :::: " << " ccccc = " << (unsigned int)ccccc << std::endl;
-
 
-		std::cout << " huli test :::: " << " AsDBRead result = " <<  result << std::endl;
 		if ( snap7_buf.m_communication_mode == Snap7_buf::ONCE_COMMUNICATION )
 		{
 			snap7_buf.m_communication_mode = Snap7_buf::NO_COMMUNICATION;