Author | SHA1 | Message | Date |
---|---|---|---|
|
0a248791e0 | 完成RTU从站功能测试样例和测试代码 | 4 years ago |
|
5aff146bac | 添加TCP主站功能测试代码 | 4 years ago |
@@ -5,7 +5,7 @@ char read_buf[MAX_NUMBER]; | |||
bitset<MAX_Address> Coil_date; //0-9999 | |||
UINT16 Register[MAX_Address]; // 0-9999 | |||
unsigned int Response_Message_Len; | |||
unsigned int RTU_Enable = 0; | |||
unsigned int RTU_Enable = 1; | |||
/********************************************************************************************* | |||
* 功能 : 初始化线圈和寄存器 | |||
@@ -7,5 +7,7 @@ | |||
#define MAX_NUMBER 256 | |||
int Modbus_RTU_Salve(void); | |||
bool Create_Response_Message(UINT8 *Requst_Message, UINT8 *Response_Message, DWORD Read_len); | |||
void Init_Coil_Register(void); | |||
#endif |
@@ -52,3 +52,15 @@ | |||
2020-9-7 18:47:2 Recv:00 00 00 00 00 06 01 0F 00 00 00 01 | |||
2020-9-7 18:47:16 Send:00 00 00 00 00 07 01 0F 00 00 00 01 01 01 | |||
2020-9-7 18:47:30 Recv:00 00 00 00 00 06 01 0F 00 00 00 01 | |||
2020-9-8 14:42:47 Send:00 00 00 00 00 06 01 01 00 00 07 B0 | |||
2020-9-8 14:45:56 Send:00 00 00 00 00 06 01 01 00 00 07 B0 | |||
2020-9-8 14:46:36 Send:00 00 00 00 00 06 09 01 00 00 07 B0 | |||
2020-9-8 14:51:59 Send:00 00 00 00 00 06 01 01 00 00 07 B0 | |||
2020-9-8 14:51:59 Recv:00 00 00 00 00 F9 01 01 F6 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | |||
2020-9-8 14:53:17 Send:00 00 00 00 00 06 01 01 00 00 07 B0 | |||
2020-9-8 14:53:17 Recv:00 00 00 00 00 F9 01 01 F6 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | |||
2020-9-8 14:55:11 Send:00 00 00 00 00 06 01 01 00 00 07 D0 | |||
2020-9-8 14:55:43 Send:00 00 00 00 00 06 09 01 00 00 07 D0 | |||
2020-9-8 14:55:47 Recv:00 00 00 00 00 FD 09 01 FB 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | |||
2020-9-8 14:56:20 Send:00 00 00 00 00 06 09 01 00 00 07 B0 | |||
2020-9-8 14:56:23 Recv:00 00 00 00 00 F9 09 01 F7 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
@@ -102,7 +102,7 @@ SOCKET Init_client(string IP, unsigned int Port_number) | |||
} | |||
cout << "连接TCP从站成功" << endl; | |||
TIMEVAL timeout; | |||
timeout.tv_sec = 200; //ms | |||
timeout.tv_sec = 20000; //ms | |||
timeout.tv_usec = 0; //us | |||
setsockopt(ClientSocket, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(struct timeval));//设置接收超时时间 | |||
return ClientSocket; | |||
@@ -187,16 +187,16 @@ bool Analysis_Response_Message(UINT8 *Response_Message, UINT8 *Request_Message, | |||
Printf_Anomaly_date(Response_Message); | |||
return true; | |||
} | |||
else if (Response_Message[6] == Request_Message[6] && Response_Message_len - 5 == Response_Message[5]) //判断是否是正常响应帧 | |||
else if (Response_Message[6] == Request_Message[6]) //判断是否是正常响应帧 | |||
{ | |||
if (Response_Message[7] == 0x01) | |||
if (Response_Message[7] == 0x01 && Response_Message_len - 6 == Response_Message[5]) | |||
Printf_Coil_date(Response_Message, Request_Message); | |||
if (Response_Message[7] == 0x03) | |||
if (Response_Message[7] == 0x03 && Response_Message_len - 6 == Response_Message[5]) | |||
Printf_Register_date(Response_Message, Request_Message); | |||
if (Response_Message[7] == 0x10) | |||
printf("成功写入从站线圈%d个", ((Request_Message[10] << 8) | Request_Message[11])); | |||
if (Response_Message[7] == 0x0F) | |||
printf("成功写入从站寄存器%d个" ,((Request_Message[10] << 8) | Request_Message[11])); | |||
printf("成功写入从站线圈%d个\n", ((Request_Message[10] << 8) | Request_Message[11])); | |||
if (Response_Message[7] == 0x10) | |||
printf("成功写入从站寄存器%d个\n" ,((Request_Message[10] << 8) | Request_Message[11])); | |||
return true; | |||
} | |||
return false; | |||
@@ -244,7 +244,7 @@ bool Tcp_client(string IP, unsigned int Port_number) | |||
printf("从站响应 :"); | |||
for (int i = 0; i < Response_Message_len; i++) | |||
{ | |||
printf("%02x ", Response_Message[i]); | |||
printf("0x%02x, ", Response_Message[i]); | |||
} | |||
printf("\n"); | |||
if (Analysis_Response_Message(Response_Message, Request_Message, Response_Message_len)) | |||
@@ -9,6 +9,7 @@ bool InitSocket_Version(void); | |||
bool Check_IP(char* IP); | |||
void Input_IP(string& IP, unsigned int *Port_number); | |||
bool Tcp_client(string IP, unsigned int Port_number); | |||
bool Analysis_Response_Message(UINT8 *Response_Message, UINT8 *Request_Message, int Response_Message_len); | |||
#endif |
@@ -146,6 +146,8 @@ bool Check_Write_date(string Write_date, int Write_date_number) | |||
unsigned int Count_Write_date_number(int Function_code, unsigned int Operations_Number) | |||
{ | |||
unsigned int Write_date_number = 0; | |||
if (Function_code == 0x01 || Function_code == 0x03) | |||
return Write_date_number; | |||
if (Function_code == 0x0F) //读线圈 | |||
{ | |||
Write_date_number = Operations_Number / 8; | |||
@@ -154,7 +156,7 @@ unsigned int Count_Write_date_number(int Function_code, unsigned int Operations_ | |||
} | |||
if (Function_code == 0x10) | |||
Write_date_number = Operations_Number * 2; | |||
return Write_date_number; | |||
return Write_date_number +1; | |||
} | |||
/********************************************************************************************* | |||
@@ -227,7 +229,7 @@ int HexStringtoByte(UINT8 *Message, string Write_date, int Message_len, int Func | |||
{ | |||
if (Write_date.length() == 0) | |||
return Message_len; | |||
Message[Message_len] = Count_Write_date_number(Function_code, Operations_Number); | |||
Message[Message_len] = Count_Write_date_number(Function_code, Operations_Number)-1; | |||
Message_len++; | |||
const char *b = Write_date.c_str(); | |||
for (unsigned int i = 0; i + 3 < Write_date.length(); i = i + 3) | |||
@@ -11,7 +11,7 @@ | |||
#pragma comment(lib,"ws2_32.lib") | |||
using namespace std; | |||
#define DEVICE_ID 0x01 //É豸ID | |||
#define DEVICE_ID 0x09 //É豸ID | |||
@@ -22,7 +22,7 @@ bool Check_Write_date(string Write_date, int Write_date_number); | |||
unsigned int Count_Write_date_number(int Function_code, unsigned int Operations_Number); | |||
string Input_Write_date(int Function_code, unsigned int Operations_Number); | |||
void Crate_MBAP(UINT8 *Message, int Function_code, unsigned int Operations_Number); | |||
int HexStringtoByte(UINT8 *Message, string Write_date, int Message_len); | |||
int HexStringtoByte(UINT8 *Message, string Write_date, int Message_len, int Function_code, unsigned int Operations_Number); | |||
int Crate_TCP_Message(UINT8 *Message, int Function_code, unsigned int Operations_Number, unsigned int Starting_address, string Write_date); | |||
void Log_Note(UINT8 *Message, int flage, int Message_len); | |||
@@ -7,6 +7,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Modbus_RTU_Salve", "Modbus_ | |||
EndProject | |||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Modbus_TCP", "Modbus_TCP\Modbus_TCP.vcxproj", "{CC08BE54-3DFF-41F2-9F8B-17E0FD5E3757}" | |||
EndProject | |||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TCP_Master_test", "TCP_Master_test\TCP_Master_test.vcxproj", "{677F6F19-D890-4DE8-9EFD-08FE0E154AD0}" | |||
EndProject | |||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RTU_Salve_test", "RTU_Salve_test\RTU_Salve_test.vcxproj", "{4443732F-F883-4E71-ACDD-E5E777C63728}" | |||
EndProject | |||
Global | |||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | |||
Debug|Win32 = Debug|Win32 | |||
@@ -21,6 +25,14 @@ Global | |||
{CC08BE54-3DFF-41F2-9F8B-17E0FD5E3757}.Debug|Win32.Build.0 = Debug|Win32 | |||
{CC08BE54-3DFF-41F2-9F8B-17E0FD5E3757}.Release|Win32.ActiveCfg = Release|Win32 | |||
{CC08BE54-3DFF-41F2-9F8B-17E0FD5E3757}.Release|Win32.Build.0 = Release|Win32 | |||
{677F6F19-D890-4DE8-9EFD-08FE0E154AD0}.Debug|Win32.ActiveCfg = Debug|Win32 | |||
{677F6F19-D890-4DE8-9EFD-08FE0E154AD0}.Debug|Win32.Build.0 = Debug|Win32 | |||
{677F6F19-D890-4DE8-9EFD-08FE0E154AD0}.Release|Win32.ActiveCfg = Release|Win32 | |||
{677F6F19-D890-4DE8-9EFD-08FE0E154AD0}.Release|Win32.Build.0 = Release|Win32 | |||
{4443732F-F883-4E71-ACDD-E5E777C63728}.Debug|Win32.ActiveCfg = Debug|Win32 | |||
{4443732F-F883-4E71-ACDD-E5E777C63728}.Debug|Win32.Build.0 = Debug|Win32 | |||
{4443732F-F883-4E71-ACDD-E5E777C63728}.Release|Win32.ActiveCfg = Release|Win32 | |||
{4443732F-F883-4E71-ACDD-E5E777C63728}.Release|Win32.Build.0 = Release|Win32 | |||
EndGlobalSection | |||
GlobalSection(SolutionProperties) = preSolution | |||
HideSolutionNode = FALSE | |||
@@ -0,0 +1,164 @@ | |||
[Example] | |||
Number = 37 | |||
[Example1] | |||
Input1 = "09 01 00 00 00 01 FC 82" | |||
Output = "09 01 01 01 92 28" | |||
[Example2] | |||
Input1 = "09 01 00 00 00 0A BD 45" | |||
Output = "09 01 02 FF 03 59 CC" | |||
[Example3] | |||
Input1 = "09 01 00 00 00 C8 3C D4" | |||
Output = "09 01 19 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF D6 40" | |||
[Example4] | |||
Input1 = "09 01 00 00 07 D0 3E EE" | |||
Output = "09 01 FA FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 8D BF" | |||
[Example5] | |||
Input1 = "09 01 00 00 07 D1 FF 2E" | |||
Output = "09 81 03 81 93" | |||
[Example6] | |||
Input1 = "09 01 00 00 00 00 3D 42" | |||
Output = "09 81 03 81 93" | |||
[Example7] | |||
Input1 = "09 01 00 00 00 01 00 82 41" | |||
Output = "09 81 03 81 93" | |||
[Example8] | |||
Input1 = "09 01 00 00 00 01 11 11" | |||
Output = "" | |||
[Example9] | |||
Input1 = "08 01 00 00 00 01 FD 53" | |||
Output = "" | |||
[Example10] | |||
Input1 = "09 01 27 06 00 14 D7 F8" | |||
Output = "09 81 02 40 53" | |||
[Example11] | |||
Input1 = "09 03 00 00 00 01 85 42" | |||
Output = "09 03 02 FF FF 58 35" | |||
[Example12] | |||
Input1 = "09 03 00 00 00 64 45 69" | |||
Output = "09 03 C8 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ED 8C" | |||
[Example13] | |||
Input1 = "09 03 00 00 00 7B 04 A1" | |||
Output = "09 03 F6 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 34 54" | |||
[Example14] | |||
Input1 = "09 03 00 00 00 7D 84 A3" | |||
Output = "09 03 FA FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 70 F8" | |||
[Example15] | |||
Input1 = "09 03 00 00 00 00 44 82" | |||
Output = "09 83 03 80 F3" | |||
[Example16] | |||
Input1 = "09 03 00 00 00 7E C4 A2" | |||
Output = "09 83 03 80 F3" | |||
[Example17] | |||
Input1 = "09 03 00 00 00 01 00 83 A3" | |||
Output = "09 83 03 80 F3" | |||
[Example18] | |||
Input1 = "09 03 00 00 00 01 11 11" | |||
Output = "" | |||
[Example19] | |||
Input1 = "08 03 00 00 00 01 84 93" | |||
Output = "" | |||
[Example20] | |||
Input1 = "09 03 27 06 00 14 AE 38" | |||
Output = "09 83 02 41 33" | |||
[Example21] | |||
Input1 = "09 0F 00 00 00 01 01 01 EE F1" | |||
Output = "09 0F 00 00 00 01 95 43" | |||
[Example22] | |||
Input1 = "09 0F 00 00 07 B0 F6 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 B8 78" | |||
Output = "09 0F 00 00 07 B0 57 07" | |||
[Example23] | |||
Input1 = "09 0F 00 00 00 00 54 83" | |||
Output = "09 8F 03 85 F3" | |||
[Example24] | |||
Input1 = "09 0F 00 00 00 01 01 01 00 71 4C" | |||
Output = "09 8F 03 85 F3" | |||
[Example25] | |||
Input1 = "09 0F 00 00 07 B1 F6 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 20 DB" | |||
Output = "09 8F 03 85 F3" | |||
[Example26] | |||
Input1 = "09 0F 00 00 00 01 01 01 11 F1" | |||
Output = "" | |||
[Example27] | |||
Input1 = "08 0F 00 00 00 01 01 01 2F 3D" | |||
Output = "" | |||
[Example28] | |||
Input1 = "09 0F 27 06 00 14 03 02 FF FF 54 11" | |||
Output = "09 8F 02 44 33" | |||
[Example29] | |||
Input1 = "09 10 00 00 00 01 02 00 00 C1 90" | |||
Output = "09 10 00 00 00 01 00 81" | |||
[Example30] | |||
Input1 = "09 10 00 00 00 02 04 00 00 00 00 D9 CF" | |||
Output = "09 10 00 00 00 02 40 80" | |||
[Example31] | |||
Input1 = "09 10 00 00 00 7B F6 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 CE 42" | |||
Output = "09 10 00 00 00 7B 81 62" | |||
[Example32] | |||
Input1 = "09 10 00 00 00 00 C1 41" | |||
Output = "09 90 03 8D C3" | |||
[Example33] | |||
Input1 = "09 10 00 00 00 01 02 00 00 00 51 90" | |||
Output = "09 90 03 8D C3" | |||
[Example34] | |||
Input1 = "09 10 00 00 00 01 02 01 01 11 11" | |||
Output = "" | |||
[Example35] | |||
Input1 = "08 10 00 00 00 01 02 01 01 0C 50" | |||
Output = "" | |||
[Example36] | |||
Input1 = "09 10 27 0F 00 02 04 00 00 00 00 26 7E" | |||
Output = "09 90 02 4C 03" | |||
[Example37] | |||
Input1 = "09 10 27 06 00 14 28 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 D9 BB" | |||
Output = "09 90 02 4C 03" |
@@ -0,0 +1,81 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |||
<ItemGroup Label="ProjectConfigurations"> | |||
<ProjectConfiguration Include="Debug|Win32"> | |||
<Configuration>Debug</Configuration> | |||
<Platform>Win32</Platform> | |||
</ProjectConfiguration> | |||
<ProjectConfiguration Include="Release|Win32"> | |||
<Configuration>Release</Configuration> | |||
<Platform>Win32</Platform> | |||
</ProjectConfiguration> | |||
</ItemGroup> | |||
<PropertyGroup Label="Globals"> | |||
<ProjectGuid>{4443732F-F883-4E71-ACDD-E5E777C63728}</ProjectGuid> | |||
<RootNamespace>RTU_Salve_test</RootNamespace> | |||
</PropertyGroup> | |||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> | |||
<ConfigurationType>Application</ConfigurationType> | |||
<UseDebugLibraries>true</UseDebugLibraries> | |||
<PlatformToolset>v120</PlatformToolset> | |||
<CharacterSet>MultiByte</CharacterSet> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> | |||
<ConfigurationType>Application</ConfigurationType> | |||
<UseDebugLibraries>false</UseDebugLibraries> | |||
<PlatformToolset>v120</PlatformToolset> | |||
<WholeProgramOptimization>true</WholeProgramOptimization> | |||
<CharacterSet>MultiByte</CharacterSet> | |||
</PropertyGroup> | |||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> | |||
<ImportGroup Label="ExtensionSettings"> | |||
</ImportGroup> | |||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | |||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |||
</ImportGroup> | |||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | |||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |||
</ImportGroup> | |||
<PropertyGroup Label="UserMacros" /> | |||
<PropertyGroup /> | |||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | |||
<ClCompile> | |||
<WarningLevel>Level3</WarningLevel> | |||
<Optimization>Disabled</Optimization> | |||
<SDLCheck>true</SDLCheck> | |||
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||
</ClCompile> | |||
<Link> | |||
<GenerateDebugInformation>true</GenerateDebugInformation> | |||
</Link> | |||
</ItemDefinitionGroup> | |||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | |||
<ClCompile> | |||
<WarningLevel>Level3</WarningLevel> | |||
<Optimization>MaxSpeed</Optimization> | |||
<FunctionLevelLinking>true</FunctionLevelLinking> | |||
<IntrinsicFunctions>true</IntrinsicFunctions> | |||
<SDLCheck>true</SDLCheck> | |||
</ClCompile> | |||
<Link> | |||
<GenerateDebugInformation>true</GenerateDebugInformation> | |||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | |||
<OptimizeReferences>true</OptimizeReferences> | |||
</Link> | |||
</ItemDefinitionGroup> | |||
<ItemGroup> | |||
<ClCompile Include="..\Modbus_RTU_Salve\common.cpp" /> | |||
<ClCompile Include="..\Modbus_RTU_Salve\RTU_Salve.cpp" /> | |||
<ClCompile Include="RTU_test.cpp" /> | |||
<ClCompile Include="RTU_Test_Code.cpp" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ClInclude Include="..\Modbus_RTU_Salve\common.h" /> | |||
<ClInclude Include="..\Modbus_RTU_Salve\RTU_Salve.h" /> | |||
<ClInclude Include="RTU_Test_Code.h" /> | |||
</ItemGroup> | |||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | |||
<ImportGroup Label="ExtensionTargets"> | |||
</ImportGroup> | |||
</Project> |
@@ -0,0 +1,42 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |||
<ItemGroup> | |||
<Filter Include="源文件"> | |||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> | |||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions> | |||
</Filter> | |||
<Filter Include="头文件"> | |||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> | |||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions> | |||
</Filter> | |||
<Filter Include="资源文件"> | |||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> | |||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> | |||
</Filter> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ClCompile Include="RTU_test.cpp"> | |||
<Filter>源文件</Filter> | |||
</ClCompile> | |||
<ClCompile Include="RTU_Test_Code.cpp"> | |||
<Filter>源文件</Filter> | |||
</ClCompile> | |||
<ClCompile Include="..\Modbus_RTU_Salve\common.cpp"> | |||
<Filter>源文件</Filter> | |||
</ClCompile> | |||
<ClCompile Include="..\Modbus_RTU_Salve\RTU_Salve.cpp"> | |||
<Filter>源文件</Filter> | |||
</ClCompile> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ClInclude Include="RTU_Test_Code.h"> | |||
<Filter>头文件</Filter> | |||
</ClInclude> | |||
<ClInclude Include="..\Modbus_RTU_Salve\common.h"> | |||
<Filter>头文件</Filter> | |||
</ClInclude> | |||
<ClInclude Include="..\Modbus_RTU_Salve\RTU_Salve.h"> | |||
<Filter>头文件</Filter> | |||
</ClInclude> | |||
</ItemGroup> | |||
</Project> |
@@ -0,0 +1,106 @@ | |||
#include "RTU_Test_Code.h" | |||
/********************************************************************************************* | |||
* Function Test 1: Parsing Request Message | |||
*********************************************************************************************/ | |||
void Parsing_Request_Message_Test(void) | |||
{ | |||
char buf[LEN]; | |||
CString name = "Example"; | |||
char s[10] = ""; | |||
int Input1; | |||
int j = 0; | |||
int number = GetPrivateProfileInt(name, "Number", 0, TESTPATH3); | |||
for (int i = 1; i < number + 1; i++) | |||
{ | |||
memset(buf, 0, sizeof(buf)); | |||
memset(s, 0, sizeof(s)); | |||
_itoa_s(i, s, 10); | |||
CString name1 = name + s; | |||
Input1 = GetPrivateProfileString(name1, "Input1", "", buf, LEN, TESTPATH3); | |||
UINT8 Requst_Message[300]; | |||
UINT8 Response_Message[300]; | |||
string Act_Message = buf; | |||
const char *b = Act_Message.c_str(); | |||
unsigned int Act_len = 0; | |||
for (unsigned int i = 0; i + 3 < Act_Message.length(); i = i + 3) | |||
{ | |||
sscanf_s(b + i, "%02X", (int *)(Requst_Message + Act_len)); | |||
Act_len++; | |||
} | |||
sscanf_s(b + Act_Message.length() - 2, "%02X", (int *)(Requst_Message + Act_len)); | |||
//bool Create_Response_Message(UINT8 *Requst_Message, UINT8 *Response_Message, DWORD Read_len) | |||
bool a = Create_Response_Message(Requst_Message, Response_Message, Act_len+1); | |||
j++; | |||
printf("%d---%d\n", j, a); | |||
} | |||
} | |||
/********************************************************************************************* | |||
* Function Test 2: Create Response Message | |||
*********************************************************************************************/ | |||
void Create_Response_Message_Test(void) | |||
{ | |||
char buf[LEN]; | |||
char buf1[LEN]; | |||
CString name = "Example"; | |||
char s[10] = ""; | |||
int Input1, Input2; | |||
int number = GetPrivateProfileInt(name, "Number", 0, TESTPATH3); | |||
Init_Coil_Register(); | |||
for (int i = 1; i < number + 1; i++) | |||
{ | |||
memset(buf, 0, sizeof(buf)); | |||
memset(buf1, 0, sizeof(buf1)); | |||
memset(s, 0, sizeof(s)); | |||
_itoa_s(i, s, 10); | |||
CString name1 = name + s; | |||
Input1 = GetPrivateProfileString(name1, "Input1", "", buf, LEN, TESTPATH3); | |||
Input2 = GetPrivateProfileString(name1, "Output", "", buf1, LEN, TESTPATH3); | |||
UINT8 Request_Message[300]; | |||
memset(Request_Message, 0, 300); | |||
string Act_Message = buf; | |||
const char *b = Act_Message.c_str(); | |||
unsigned int Act_len = 0; | |||
for (unsigned int i = 0; i + 3 < Act_Message.length(); i = i + 3) | |||
{ | |||
sscanf_s(b + i, "%02X", (int *)(Request_Message + Act_len)); | |||
Act_len++; | |||
} | |||
sscanf_s(b + Act_Message.length() - 2, "%02X", (int *)(Request_Message + Act_len)); | |||
UINT8 Act_Response_Message[300]; | |||
memset(Act_Response_Message, 0, 300); | |||
unsigned int Act_len1 = 0; | |||
if (Input2 != 0) | |||
{ | |||
string Act_Message1 = buf1; | |||
const char *a = Act_Message1.c_str(); | |||
for (unsigned int i = 0; i + 3 < Act_Message1.length(); i = i + 3) | |||
{ | |||
sscanf_s(a + i, "%02X", (int *)(Act_Response_Message + Act_len1)); | |||
Act_len1++; | |||
} | |||
sscanf_s(a + Act_Message1.length() - 2, "%02X", (int *)(Act_Response_Message + Act_len1)); | |||
} | |||
UINT8 Response_Message[300]; | |||
memset(Response_Message, 0, 300); | |||
Create_Response_Message(Request_Message, Response_Message, Act_len + 1); | |||
printf("µÚ%d×éÑùÀý£º\n",i); | |||
for (unsigned int j = 0; j < Act_len1 + 1; j++) | |||
{ | |||
printf("%02X ", Act_Response_Message[j]); | |||
} | |||
printf("\n"); | |||
for (unsigned int m = 0; m < Act_len1 + 1; m++) | |||
{ | |||
printf("%02X ", Response_Message[m]); | |||
} | |||
printf("\n"); | |||
printf("\n"); | |||
} | |||
} |
@@ -0,0 +1,14 @@ | |||
#ifndef __RTU_TEST_CODE_H | |||
#define __RTU_TEST_CODE_H | |||
#include "../Modbus_RTU_Salve/RTU_Salve.h" | |||
#include <windows.h> | |||
#include <atlstr.h> | |||
#define TESTPATH3 "./3.ini" | |||
#define LEN 65535 | |||
void Parsing_Request_Message_Test(void); | |||
void Create_Response_Message_Test(void); | |||
#endif |
@@ -0,0 +1,9 @@ | |||
#include "RTU_Test_Code.h" | |||
int main() | |||
{ | |||
Parsing_Request_Message_Test(); | |||
Create_Response_Message_Test(); | |||
getchar(); | |||
return 0; | |||
} |
@@ -0,0 +1,75 @@ | |||
[Example] | |||
Number = 12 | |||
[Example1] | |||
Input1 = 1 | |||
Input2 = 1 | |||
Input3 = "" | |||
Output = "00 00 00 00 00 06 09 01 00 00 00 01" | |||
[Example2] | |||
Input1 = 1 | |||
Input2 = 100 | |||
Input3 = "" | |||
Output = "00 00 00 00 00 06 09 01 00 00 00 64" | |||
[Example3] | |||
Input1 = 1 | |||
Input2 = 2000 | |||
Input3 = "" | |||
Output = "00 00 00 00 00 06 09 01 00 00 07 D0" | |||
[Example4] | |||
Input1 = 3 | |||
Input2 = 1 | |||
Input3 = "" | |||
Output = "00 00 00 00 00 06 09 03 00 00 00 01" | |||
[Example5] | |||
Input1 = 3 | |||
Input2 = 10 | |||
Input3 = "" | |||
Output = "00 00 00 00 00 06 09 03 00 00 00 0A" | |||
[Example6] | |||
Input1 = 3 | |||
Input2 = 125 | |||
Input3 = "" | |||
Output = "00 00 00 00 00 06 09 03 00 00 00 7D" | |||
[Example7] | |||
Input1 = 15 | |||
Input2 = 1 | |||
Input3 = "01" | |||
Output = "00 00 00 00 00 08 09 03 00 00 00 01 01 01" | |||
[Example8] | |||
Input1 = 15 | |||
Input2 = 10 | |||
Input3 = "FF 03" | |||
Output = "00 00 00 00 00 09 09 03 00 00 00 0A 02 FF 03" | |||
[Example9] | |||
Input1 = 15 | |||
Input2 = 1968 | |||
Input3 = "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00" | |||
Output = "00 00 00 00 00 FD 09 0F 00 00 07 BD F6 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00" | |||
[Example10] | |||
Input1 = 16 | |||
Input2 = 1 | |||
Input3 = "FF FF" | |||
Output = "00 00 00 00 00 09 09 10 00 00 00 01 02 FF FF" | |||
[Example11] | |||
Input1 = 16 | |||
Input2 = 5 | |||
Input3 = "FF FF FF FF FF FF FF FF FF FF" | |||
Output = "00 00 00 00 00 11 09 10 00 00 00 05 0A FF FF FF FF FF FF FF FF FF FF" | |||
[Example12] | |||
Input1 = 16 | |||
Input2 = 123 | |||
Input3 = "F6 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00" | |||
Output = "00 00 00 00 00 FD 09 10 00 00 00 7B F6 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00" | |||
@@ -0,0 +1,128 @@ | |||
[Example] | |||
Number = 28 | |||
[Example1] | |||
Input1 = "00 00 00 00 00 04 09 01 01 01" | |||
Input2 = "00 00 00 00 00 06 09 01 00 00 00 01" | |||
[Example2] | |||
Input1 = "00 00 00 00 00 10 09 01 0D 00 00 00 00 00 00 00 00 00 00 00 00 00" | |||
Input2 = "00 00 00 00 00 06 09 01 00 00 00 64" | |||
[Example3] | |||
Input1 = "00 00 00 00 00 FD 09 01 FA 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00" | |||
Input2 = "00 00 00 00 00 06 09 01 00 00 07 D0" | |||
[Example4] | |||
Input1 = "00 00 00 00 00 05 09 03 02 FF FF" | |||
Input2 = "00 00 00 00 00 06 09 03 00 00 00 01" | |||
[Example5] | |||
Input1 = "00 00 00 00 00 17 09 03 14 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF" | |||
Input2 = "00 00 00 00 00 06 09 03 00 00 00 0A" | |||
[Example6] | |||
Input1 = "00 00 00 00 00 FD 09 03 FA 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00" | |||
Input2 = "00 00 00 00 00 06 09 03 00 00 00 7D" | |||
[Example7] | |||
Input1 = "00 00 00 00 00 06 09 0F 00 00 00 01" | |||
Input2 = "00 00 00 00 00 08 09 0F 00 00 00 01 01 01" | |||
[Example8] | |||
Input1 = "00 00 00 00 00 06 09 0F 00 00 00 0A" | |||
Input2 = "00 00 00 00 00 09 09 0F 00 00 00 0A 02 FF 03" | |||
[Example9] | |||
Input1 = "00 00 00 00 00 06 09 0F 00 00 07 B0" | |||
Input2 = "00 00 00 00 00 FD 09 0F 00 00 07 B0 F6 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00" | |||
[Example10] | |||
Input1 = "00 00 00 00 00 06 09 10 00 00 00 01" | |||
Input2 = "00 00 00 00 00 09 09 10 00 00 00 01 02 FF FF" | |||
[Example11] | |||
Input1 = "00 00 00 00 00 06 09 10 00 00 00 05" | |||
Input2 = "00 00 00 00 00 11 09 10 00 00 00 05 0A FF FF FF FF FF FF FF FF FF FF" | |||
[Example12] | |||
Input1 = "00 00 00 00 00 06 09 10 00 00 00 7B" | |||
Input2 = "00 00 00 00 00 FD 09 10 00 00 00 7B F6 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00" | |||
[Example13] | |||
Input1 = "00 00 00 00 00 03 09 90 01" | |||
Input2 = "00 00 00 00 00 09 09 10 00 00 00 01" | |||
[Example14] | |||
Input1 = "00 00 00 00 00 03 09 90 02" | |||
Input2 = "00 00 00 00 00 09 09 10 00 00 00 01" | |||
[Example15] | |||
Input1 = "00 00 00 00 00 03 09 90 03" | |||
Input2 = "00 00 00 00 00 09 09 10 00 00 00 01" | |||
[Example16] | |||
Input1 = "00 00 00 00 00 03 09 90 04" | |||
Input2 = "00 00 00 00 00 09 09 10 00 00 00 01" | |||
[Example17] | |||
Input1 = "00 00 00 00 00 03 09 8F 01" | |||
Input2 = "00 00 00 00 00 09 09 0F 00 00 00 01" | |||
[Example18] | |||
Input1 = "00 00 00 00 00 03 09 8F 02" | |||
Input2 = "00 00 00 00 00 09 09 0F 00 00 00 01" | |||
[Example19] | |||
Input1 = "00 00 00 00 00 03 09 8F 03" | |||
Input2 = "00 00 00 00 00 09 09 0F 00 00 00 01" | |||
[Example20] | |||
Input1 = "00 00 00 00 00 03 09 8F 04" | |||
Input2 = "00 00 00 00 00 09 09 0F 00 00 00 01" | |||
[Example21] | |||
Input1 = "00 00 00 00 00 03 09 81 01" | |||
Input2 = "00 00 00 00 00 09 09 01 00 00 00 01" | |||
[Example22] | |||
Input1 = "00 00 00 00 00 03 09 81 02" | |||
Input2 = "00 00 00 00 00 09 09 01 00 00 00 01" | |||
[Example23] | |||
Input1 = "00 00 00 00 00 03 09 81 03" | |||
Input2 = "00 00 00 00 00 09 09 01 00 00 00 01" | |||
[Example24] | |||
Input1 = "00 00 00 00 00 03 09 81 04" | |||
Input2 = "00 00 00 00 00 09 09 01 00 00 00 01" | |||
[Example25] | |||
Input1 = "00 00 00 00 00 03 09 83 01" | |||
Input2 = "00 00 00 00 00 09 09 03 00 00 00 01" | |||
[Example26] | |||
Input1 = "00 00 00 00 00 03 09 83 02" | |||
Input2 = "00 00 00 00 00 09 09 03 00 00 00 01" | |||
[Example27] | |||
Input1 = "00 00 00 00 00 03 09 83 03" | |||
Input2 = "00 00 00 00 00 09 09 03 00 00 00 01" | |||
[Example28] | |||
Input1 = "00 00 00 00 00 03 09 83 04" | |||
Input2 = "00 00 00 00 00 09 09 03 00 00 00 01" |
@@ -0,0 +1,81 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |||
<ItemGroup Label="ProjectConfigurations"> | |||
<ProjectConfiguration Include="Debug|Win32"> | |||
<Configuration>Debug</Configuration> | |||
<Platform>Win32</Platform> | |||
</ProjectConfiguration> | |||
<ProjectConfiguration Include="Release|Win32"> | |||
<Configuration>Release</Configuration> | |||
<Platform>Win32</Platform> | |||
</ProjectConfiguration> | |||
</ItemGroup> | |||
<PropertyGroup Label="Globals"> | |||
<ProjectGuid>{677F6F19-D890-4DE8-9EFD-08FE0E154AD0}</ProjectGuid> | |||
<RootNamespace>TCP_Master_test</RootNamespace> | |||
</PropertyGroup> | |||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> | |||
<ConfigurationType>Application</ConfigurationType> | |||
<UseDebugLibraries>true</UseDebugLibraries> | |||
<PlatformToolset>v120</PlatformToolset> | |||
<CharacterSet>MultiByte</CharacterSet> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> | |||
<ConfigurationType>Application</ConfigurationType> | |||
<UseDebugLibraries>false</UseDebugLibraries> | |||
<PlatformToolset>v120</PlatformToolset> | |||
<WholeProgramOptimization>true</WholeProgramOptimization> | |||
<CharacterSet>MultiByte</CharacterSet> | |||
</PropertyGroup> | |||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> | |||
<ImportGroup Label="ExtensionSettings"> | |||
</ImportGroup> | |||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | |||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |||
</ImportGroup> | |||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | |||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |||
</ImportGroup> | |||
<PropertyGroup Label="UserMacros" /> | |||
<PropertyGroup /> | |||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | |||
<ClCompile> | |||
<WarningLevel>Level3</WarningLevel> | |||
<Optimization>Disabled</Optimization> | |||
<SDLCheck>true</SDLCheck> | |||
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||
</ClCompile> | |||
<Link> | |||
<GenerateDebugInformation>true</GenerateDebugInformation> | |||
</Link> | |||
</ItemDefinitionGroup> | |||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | |||
<ClCompile> | |||
<WarningLevel>Level3</WarningLevel> | |||
<Optimization>MaxSpeed</Optimization> | |||
<FunctionLevelLinking>true</FunctionLevelLinking> | |||
<IntrinsicFunctions>true</IntrinsicFunctions> | |||
<SDLCheck>true</SDLCheck> | |||
</ClCompile> | |||
<Link> | |||
<GenerateDebugInformation>true</GenerateDebugInformation> | |||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | |||
<OptimizeReferences>true</OptimizeReferences> | |||
</Link> | |||
</ItemDefinitionGroup> | |||
<ItemGroup> | |||
<ClCompile Include="..\Modbus_TCP\common.cpp" /> | |||
<ClCompile Include="..\Modbus_TCP\TCP_client.cpp" /> | |||
<ClCompile Include="TCP_Test.cpp" /> | |||
<ClCompile Include="TCP_Test_Code.cpp" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ClInclude Include="..\Modbus_TCP\common.h" /> | |||
<ClInclude Include="..\Modbus_TCP\TCP_client.h" /> | |||
<ClInclude Include="TCP_Test_Code.h" /> | |||
</ItemGroup> | |||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | |||
<ImportGroup Label="ExtensionTargets"> | |||
</ImportGroup> | |||
</Project> |
@@ -0,0 +1,42 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |||
<ItemGroup> | |||
<Filter Include="源文件"> | |||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> | |||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions> | |||
</Filter> | |||
<Filter Include="头文件"> | |||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> | |||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions> | |||
</Filter> | |||
<Filter Include="资源文件"> | |||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> | |||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> | |||
</Filter> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ClCompile Include="TCP_Test.cpp"> | |||
<Filter>源文件</Filter> | |||
</ClCompile> | |||
<ClCompile Include="TCP_Test_Code.cpp"> | |||
<Filter>源文件</Filter> | |||
</ClCompile> | |||
<ClCompile Include="..\Modbus_TCP\common.cpp"> | |||
<Filter>源文件</Filter> | |||
</ClCompile> | |||
<ClCompile Include="..\Modbus_TCP\TCP_client.cpp"> | |||
<Filter>源文件</Filter> | |||
</ClCompile> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ClInclude Include="TCP_Test_Code.h"> | |||
<Filter>头文件</Filter> | |||
</ClInclude> | |||
<ClInclude Include="..\Modbus_TCP\common.h"> | |||
<Filter>头文件</Filter> | |||
</ClInclude> | |||
<ClInclude Include="..\Modbus_TCP\TCP_client.h"> | |||
<Filter>头文件</Filter> | |||
</ClInclude> | |||
</ItemGroup> | |||
</Project> |
@@ -0,0 +1,9 @@ | |||
#include "TCP_Test_Code.h" | |||
int main() | |||
{ | |||
Generate_request_message_test(); | |||
Analysis_response_message_test(); | |||
getchar(); | |||
return 0; | |||
} |
@@ -0,0 +1,102 @@ | |||
#include "TCP_Test_Code.h" | |||
/********************************************************************************************* | |||
* Function Test 1: Generate request message | |||
*********************************************************************************************/ | |||
void Generate_request_message_test(void) | |||
{ | |||
char buf[LEN]; | |||
char buf1[LEN]; | |||
CString name = "Example"; | |||
char s[10] = ""; | |||
int Output, Input1, Input2, Input3; | |||
int number = GetPrivateProfileInt(name, "Number", 0, TESTPATH1); | |||
for (int i = 1; i < number + 1; i++) | |||
{ | |||
memset(buf, 0, sizeof(buf)); | |||
memset(buf1, 0, sizeof(buf1)); | |||
memset(s, 0, sizeof(s)); | |||
_itoa_s(i, s, 10); | |||
CString name1 = name + s; | |||
Input1 = GetPrivateProfileInt(name1, "Input1", 0, TESTPATH1); | |||
Input2 = GetPrivateProfileInt(name1, "Input2", 0, TESTPATH1); | |||
Input3 = GetPrivateProfileString(name1, "Input3", "", buf, LEN, TESTPATH1); | |||
Output = GetPrivateProfileString(name1, "Output", "", buf1, LEN, TESTPATH1); | |||
UINT8 test_Message[300]; | |||
UINT8 Output_Message[300]; | |||
string Write_date = buf; | |||
string Act_Message = buf1; | |||
const char *b = Act_Message.c_str(); | |||
unsigned int Act_len = 0; | |||
for (unsigned int i = 0; i + 3 < Act_Message.length(); i = i + 3) | |||
{ | |||
sscanf_s(b + i, "%02X", (int *)(Output_Message + Act_len)); | |||
Act_len++; | |||
} | |||
sscanf_s(b + Act_Message.length() - 2, "%02X", (int *)(Output_Message + Act_len)); | |||
int len = Crate_TCP_Message(test_Message, Input1, Input2, 0, Write_date); | |||
for (int j = 0; j < len; j++) | |||
{ | |||
printf("%02X ", test_Message[j]); | |||
} | |||
printf("\n"); | |||
for (int m = 0; m < len; m++) | |||
{ | |||
printf("%02X ", Output_Message[m]); | |||
} | |||
printf("\n"); | |||
} | |||
} | |||
/********************************************************************************************* | |||
* Function Test 2: Analysis response message | |||
*********************************************************************************************/ | |||
void Analysis_response_message_test(void) | |||
{ | |||
char buf[LEN]; | |||
char buf1[LEN]; | |||
CString name = "Example"; | |||
char s[10] = ""; | |||
int Input1, Input2; | |||
int number = GetPrivateProfileInt(name, "Number", 0, TESTPATH2); | |||
for (int i = 1; i < number + 1; i++) | |||
{ | |||
memset(buf, 0, sizeof(buf)); | |||
memset(buf1, 0, sizeof(buf1)); | |||
memset(s, 0, sizeof(s)); | |||
_itoa_s(i, s, 10); | |||
CString name1 = name + s; | |||
Input1 = GetPrivateProfileString(name1, "Input1", "", buf, LEN, TESTPATH2); | |||
Input2 = GetPrivateProfileString(name1, "Input2", "", buf1, LEN, TESTPATH2); | |||
UINT8 Response_Message[300]; | |||
string Act_Message = buf; | |||
const char *b = Act_Message.c_str(); | |||
unsigned int Act_len = 0; | |||
for (unsigned int i = 0; i + 3 < Act_Message.length(); i = i + 3) | |||
{ | |||
sscanf_s(b + i, "%02X", (int *)(Response_Message + Act_len)); | |||
Act_len++; | |||
} | |||
sscanf_s(b + Act_Message.length() - 2, "%02X", (int *)(Response_Message + Act_len)); | |||
UINT8 Request_Message[300]; | |||
string Act_Message1 = buf1; | |||
const char *a = Act_Message1.c_str(); | |||
unsigned int Act_len1 = 0; | |||
for (unsigned int i = 0; i + 3 < Act_Message1.length(); i = i + 3) | |||
{ | |||
sscanf_s(a + i, "%02X", (int *)(Request_Message + Act_len1)); | |||
Act_len1++; | |||
} | |||
sscanf_s(a + Act_Message1.length() - 2, "%02X", (int *)(Request_Message + Act_len1)); | |||
Analysis_Response_Message(Response_Message, Request_Message, Act_len+1); | |||
} | |||
} | |||
@@ -0,0 +1,16 @@ | |||
#ifndef __TCP_TEST_CODE_H | |||
#define __TCP_TEST_CODE_H | |||
#include <stdio.h> | |||
#include "../Modbus_TCP/common.h" | |||
#include "../Modbus_TCP/TCP_client.h" | |||
#include <windows.h> | |||
#include <atlstr.h> | |||
#define TESTPATH1 "./1.ini" | |||
#define TESTPATH2 "./2.ini" | |||
#define LEN 65535 | |||
void Generate_request_message_test(void); | |||
void Analysis_response_message_test(void); | |||
#endif |