| @@ -78,3 +78,32 @@ void Input_IP(string& IP, unsigned int *Port_number) | |||||
| } while (*Port_number == 0 || *Port_number > 65535); //端口不能为0 ,端口号范围0---65535 | } while (*Port_number == 0 || *Port_number > 65535); //端口不能为0 ,端口号范围0---65535 | ||||
| } | } | ||||
| /********************************************************************************************* | |||||
| * 功能 : 选择功能码 | |||||
| * 描述 : 在功能码 0x01 0x03 0x0F 0x10中选择一个功能码 | |||||
| * 输入 : 无 | |||||
| * 输出 : 选择的功能码 | |||||
| *********************************************************************************************/ | |||||
| int Input_Function_code(void) | |||||
| { | |||||
| int Function_code; | |||||
| cin >> hex; | |||||
| int i = 1; | |||||
| printf("功能码 : 0x01 0x03 0x0F 0x10 \n"); | |||||
| printf("说明 : 读线圈 读寄存器 写多个线圈 写多个寄存器\n"); | |||||
| do | |||||
| { | |||||
| if (i == 1) | |||||
| { | |||||
| i = 0; | |||||
| cout << "请输入选择的功能码:"; | |||||
| } | |||||
| else | |||||
| cout << "输入功能码错误,请重新选择的功能码"; | |||||
| cin >> Function_code; | |||||
| cin.clear(); | |||||
| cin.sync(); | |||||
| } while (Function_code != 0x01 && Function_code != 0x03 && Function_code != 0x0F && Function_code != 0x10); | |||||
| return Function_code; | |||||
| } | |||||
| @@ -1,20 +1,35 @@ | |||||
| #include "main.h" | #include "main.h" | ||||
| string input() | |||||
| { | |||||
| string str; | |||||
| cout << "请输入string内容:" << endl; | |||||
| getline(cin, str, '\n'); | |||||
| cout << str << endl; | |||||
| return str; | |||||
| } | |||||
| int main() | int main() | ||||
| { | { | ||||
| string IP; | |||||
| unsigned int Port_number; | |||||
| Input_IP(IP, &Port_number); | |||||
| Tcp_client(IP, Port_number); | |||||
| //string IP; | |||||
| //unsigned int Port_number; | |||||
| //Input_IP(IP, &Port_number); | |||||
| //Tcp_client(IP, Port_number); | |||||
| int Function_code; | |||||
| while (1) | |||||
| { | |||||
| cin >> hex; | |||||
| int i = 1; | |||||
| printf("功能码 : 0x01 0x03 0x0F 0x10 \n"); | |||||
| printf("说明 : 读线圈 读寄存器 写多个线圈 写多个寄存器\n"); | |||||
| do | |||||
| { | |||||
| if (i == 1) | |||||
| { | |||||
| i = 0; | |||||
| cout << "请输入选择的功能码:"; | |||||
| } | |||||
| else | |||||
| cout << "输入功能码错误,请重新选择的功能码"; | |||||
| cin >> Function_code; | |||||
| cin.clear(); | |||||
| cin.sync(); | |||||
| } while (Function_code != 0x01 && Function_code != 0x03 && Function_code != 0x0F && Function_code != 0x10); | |||||
| printf("%02X", Function_code); | |||||
| getchar(); | |||||
| } | |||||
| getchar(); | getchar(); | ||||
| return 0; | return 0; | ||||
| } | } | ||||