|
|
@@ -292,26 +292,29 @@ namespace UAS_MES_NEW.PublicMethod
|
|
|
string prefix = "";
|
|
|
string regcode = "";
|
|
|
string makecode = "";
|
|
|
+ string prebigxbox = "";
|
|
|
if (dt.Rows.Count > 0)
|
|
|
{
|
|
|
prefix = dt.Rows[0]["pr_prefix"].ToString();
|
|
|
regcode = dt.Rows[0]["pr_regcode"].ToString();
|
|
|
makecode = dt.Rows[0]["ms_makecode"].ToString();
|
|
|
+ prebigxbox = dt.Rows[0]["pr_prebigxbox"].ToString();
|
|
|
}
|
|
|
dynamic obj = new ExpandoObject();
|
|
|
|
|
|
obj.tool_name = "zte";
|
|
|
obj.request = "Storage2";
|
|
|
obj.User = "mes";
|
|
|
- obj.password = "Mes@hy_231019";
|
|
|
- obj.po_sn = makecode;
|
|
|
- obj.wholeDeviceCode = "";
|
|
|
+ obj.password = "258456";
|
|
|
+ obj.po_sn = "250916001001";
|
|
|
+ obj.wholeDeviceCode = iSN;
|
|
|
obj.reg_code = regcode;
|
|
|
obj.prefix_en_no = prefix;
|
|
|
- obj.prefix_big_box = "";
|
|
|
- obj.packing_num = "";
|
|
|
+ obj.prefix_big_box = prebigxbox;
|
|
|
+ obj.packing_num = 6;
|
|
|
obj.isn = iSN;
|
|
|
|
|
|
+
|
|
|
string json = JsonConvert.SerializeObject(obj, Formatting.Indented);
|
|
|
string returnstr = ToServerReq(json);
|
|
|
JObject deviceObj = JObject.Parse(returnstr);
|
|
|
@@ -323,6 +326,7 @@ namespace UAS_MES_NEW.PublicMethod
|
|
|
string mac_end = deviceObj["mac_end"].ToString();
|
|
|
string reg_code = deviceObj["reg_code"].ToString();
|
|
|
string reserve3 = deviceObj["reserve3"].ToString();
|
|
|
+ string status = deviceObj["status"].ToString();
|
|
|
string device_type = deviceObj["device_type"].ToString();
|
|
|
string en_no = deviceObj["en_no"].ToString();
|
|
|
dh.ExecuteSql("insert into ZTEDATA(ZD_ID,ZD_D_SN,zd_WholeDeviceCode,ZD_DEV_EN_NO,ZD_SN, ZD_MAKECODE, ZD_TYPE, ZD_VALUE,zd_mac,ZD_MAC_START, ZD_MAC_END,ZD_RESERVE3,zd_enno,zd_devicetype,zd_regcode)" +
|
|
|
@@ -394,7 +398,7 @@ namespace UAS_MES_NEW.PublicMethod
|
|
|
}); ;
|
|
|
}
|
|
|
string json = JsonConvert.SerializeObject(root, Formatting.Indented);
|
|
|
- string returnstr = SendData(json);
|
|
|
+ string returnstr = ToServerReq(json);
|
|
|
Console.WriteLine(json);
|
|
|
}
|
|
|
|
|
|
@@ -413,16 +417,15 @@ namespace UAS_MES_NEW.PublicMethod
|
|
|
makecode = dt.Rows[i]["pd_makecode"].ToString();
|
|
|
}
|
|
|
obj.request = "Q_wai_xiang";
|
|
|
- obj.packing_num = 20;
|
|
|
+ obj.packing_num = dt.Rows.Count;
|
|
|
obj.User = "mes";
|
|
|
- obj.po_sn = makecode;
|
|
|
- obj.password = "Mes@hy_231019";
|
|
|
+ obj.po_sn = "250916001001";
|
|
|
+ obj.password = "258456";
|
|
|
obj.tool_name = "zte";
|
|
|
obj.noType = 0;
|
|
|
|
|
|
-
|
|
|
string json = JsonConvert.SerializeObject(obj, Formatting.Indented);
|
|
|
- string returnstr = SendData(json);
|
|
|
+ string returnstr = ToServerReq(json);
|
|
|
|
|
|
var settings = new JsonSerializerSettings
|
|
|
{
|
|
|
@@ -470,121 +473,16 @@ namespace UAS_MES_NEW.PublicMethod
|
|
|
obj.packing_num = dt.Rows.Count;
|
|
|
obj.User = "mes";
|
|
|
obj.po_sn = makecode;
|
|
|
- obj.password = "Mes@hy_231019";
|
|
|
+ obj.password = "258456";
|
|
|
obj.tool_name = "zte";
|
|
|
|
|
|
string json = JsonConvert.SerializeObject(obj, Formatting.Indented);
|
|
|
- string returnstr = SendData(json);
|
|
|
+ string returnstr = ToServerReq(json);
|
|
|
Console.WriteLine(returnstr);
|
|
|
Console.WriteLine(json);
|
|
|
}
|
|
|
|
|
|
- //发送数据
|
|
|
- public static string SendData(string json)
|
|
|
- {
|
|
|
- string serverIP = "192.168.1.160";
|
|
|
- int port = 21610;
|
|
|
-
|
|
|
- try
|
|
|
- {
|
|
|
- TcpClient client = new TcpClient();
|
|
|
- client.Connect(serverIP, port);
|
|
|
- NetworkStream stream = client.GetStream();
|
|
|
-
|
|
|
- // 发送数据
|
|
|
- byte[] data = BuildPacket(json);
|
|
|
- stream.Write(data, 0, data.Length);
|
|
|
- Console.WriteLine($"已发送请求: {json}");
|
|
|
-
|
|
|
- // 接收响应 - 使用安全的方式
|
|
|
- return ReceiveDataSafely(stream);
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- Console.WriteLine($"错误: {ex.Message}");
|
|
|
- return "";
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private static string ReceiveDataSafely(NetworkStream stream)
|
|
|
- {
|
|
|
- MemoryStream ms = new MemoryStream();
|
|
|
- byte[] buffer = new byte[8192];
|
|
|
- int totalBytesRead = 0;
|
|
|
- const int MAX_SIZE = 10 * 1024 * 1024;
|
|
|
-
|
|
|
- try
|
|
|
- {
|
|
|
- stream.ReadTimeout = 5000;
|
|
|
-
|
|
|
- while (true)
|
|
|
- {
|
|
|
- int bytesRead = stream.Read(buffer, 0, buffer.Length);
|
|
|
- if (bytesRead == 0) break;
|
|
|
-
|
|
|
- ms.Write(buffer, 0, bytesRead);
|
|
|
- totalBytesRead += bytesRead;
|
|
|
-
|
|
|
- Console.WriteLine($"本次读取: {bytesRead} 字节, 累计: {totalBytesRead} 字节");
|
|
|
-
|
|
|
- if (totalBytesRead > MAX_SIZE)
|
|
|
- {
|
|
|
- throw new Exception($"接收数据超过大小限制: {MAX_SIZE} 字节");
|
|
|
- }
|
|
|
-
|
|
|
- if (!stream.DataAvailable)
|
|
|
- {
|
|
|
- Thread.Sleep(100);
|
|
|
- if (!stream.DataAvailable) break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- byte[] receivedData = ms.ToArray();
|
|
|
-
|
|
|
- // 直接使用GBK编码(最常用的中文编码)
|
|
|
- Encoding chineseEncoding = Encoding.GetEncoding("GBK");
|
|
|
- string response = chineseEncoding.GetString(receivedData);
|
|
|
-
|
|
|
- Console.WriteLine($"使用GBK编码的响应: {response}");
|
|
|
- return response;
|
|
|
- }
|
|
|
- catch (TimeoutException)
|
|
|
- {
|
|
|
- byte[] partialData = ms.ToArray();
|
|
|
- Encoding chineseEncoding = Encoding.GetEncoding("GBK");
|
|
|
- string partialResponse = chineseEncoding.GetString(partialData);
|
|
|
- Console.WriteLine($"接收超时,已接收数据: {partialResponse}");
|
|
|
- return partialResponse;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
public static readonly uint PROTOCOL_FLAG = 0x4C4F4F54;
|
|
|
- public static byte[] BuildPacket(string jsonData)
|
|
|
- {
|
|
|
- if (string.IsNullOrEmpty(jsonData))
|
|
|
- {
|
|
|
- throw new ArgumentException("JSON数据不能为空");
|
|
|
- }
|
|
|
-
|
|
|
- using (MemoryStream ms = new MemoryStream())
|
|
|
- {
|
|
|
- // 1. 写入flag (小端序)
|
|
|
- byte[] flagBytes = BitConverter.GetBytes(PROTOCOL_FLAG);
|
|
|
- ms.Write(flagBytes, 0, 4);
|
|
|
-
|
|
|
- // 2. 将JSON字符串转换为UTF8字节数组
|
|
|
- byte[] jsonBytes = Encoding.UTF8.GetBytes(jsonData);
|
|
|
-
|
|
|
- // 3. 写入data_len (小端序)
|
|
|
- byte[] lengthBytes = BitConverter.GetBytes(jsonBytes.Length);
|
|
|
- ms.Write(lengthBytes, 0, 4);
|
|
|
-
|
|
|
- // 4. 写入data
|
|
|
- ms.Write(jsonBytes, 0, jsonBytes.Length);
|
|
|
-
|
|
|
- return ms.ToArray();
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
public static string ToServerReq(string strJSON)
|
|
|
{
|
|
|
@@ -625,10 +523,6 @@ namespace UAS_MES_NEW.PublicMethod
|
|
|
int nRecvSize = 0, nSize = 0;
|
|
|
nRecvSize = clientSocket.Receive(bytRecv, 0, FACT_DATA_HEAD.MY_LEN, SocketFlags.None);
|
|
|
|
|
|
- // string strTmp;
|
|
|
- // strTmp = string.Format("clientSocket.Receive={0}", nRecvSize);
|
|
|
- // Trace.WriteLine(strTmp);
|
|
|
-
|
|
|
if (nRecvSize > 0)
|
|
|
{
|
|
|
FACT_DATA_HEAD stHead = new FACT_DATA_HEAD(bytRecv);
|