Commit 1c9f24d42e683fc757cdc90945373d8ddf37c22b

Authored by liufu
1 parent c4fe4e73

同步

HHWCS.Dao/Bll.cs
... ... @@ -730,5 +730,88 @@ namespace HHWCS.Bll
730 730 }
731 731  
732 732 #endregion
  733 +
  734 + #region 字符串和Byte之间的转化
  735 + /// <summary>
  736 + /// 数字和字节之间互转
  737 + /// </summary>
  738 + /// <param name="num"></param>
  739 + /// <returns></returns>
  740 + public static int IntToBitConverter(int num)
  741 + {
  742 + int temp = 0;
  743 + byte[] bytes = BitConverter.GetBytes(num);//将int32转换为字节数组
  744 + temp = BitConverter.ToInt32(bytes, 0);//将字节数组内容再转成int32类型
  745 + return temp;
  746 + }
  747 +
  748 + /// <summary>
  749 + /// 将字符串转为16进制字符,允许中文
  750 + /// </summary>
  751 + /// <param name="s"></param>
  752 + /// <param name="encode"></param>
  753 + /// <returns></returns>
  754 + public static string StringToHexString(string s, Encoding encode, string spanString)
  755 + {
  756 + byte[] b = encode.GetBytes(s);//按照指定编码将string编程字节数组
  757 + string result = string.Empty;
  758 + for (int i = 0; i < b.Length; i++)//逐字节变为16进制字符
  759 + {
  760 + result += Convert.ToString(b[i], 16) + spanString;
  761 + }
  762 + return result;
  763 + }
  764 + /// <summary>
  765 + /// 将16进制字符串转为字符串
  766 + /// </summary>
  767 + /// <param name="hs"></param>
  768 + /// <param name="encode"></param>
  769 + /// <returns></returns>
  770 + public static string HexStringToString(string hs, Encoding encode)
  771 + {
  772 + string strTemp = "";
  773 + byte[] b = new byte[hs.Length / 2];
  774 + for (int i = 0; i < hs.Length / 2; i++)
  775 + {
  776 + strTemp = hs.Substring(i * 2, 2);
  777 + b[i] = Convert.ToByte(strTemp, 16);
  778 + }
  779 + //按照指定编码将字节数组变为字符串
  780 + return encode.GetString(b);
  781 + }
  782 + /// <summary>
  783 + /// byte[]转为16进制字符串
  784 + /// </summary>
  785 + /// <param name="bytes"></param>
  786 + /// <returns></returns>
  787 + public static string ByteToHexStr(byte[] bytes)
  788 + {
  789 + string returnStr = "";
  790 + if (bytes != null)
  791 + {
  792 + for (int i = 0; i < bytes.Length; i++)
  793 + {
  794 + returnStr += bytes[i].ToString("X2");
  795 + }
  796 + }
  797 + return returnStr;
  798 + }
  799 + /// <summary>
  800 + /// 将16进制的字符串转为byte[]
  801 + /// </summary>
  802 + /// <param name="hexString"></param>
  803 + /// <returns></returns>
  804 + public static byte[] StrToHexByte(string hexString)
  805 + {
  806 + hexString = hexString.Replace(" ", "");
  807 + if ((hexString.Length % 2) != 0)
  808 + hexString += " ";
  809 + byte[] returnBytes = new byte[hexString.Length / 2];
  810 + for (int i = 0; i < returnBytes.Length; i++)
  811 + returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
  812 + return returnBytes;
  813 + }
  814 +
  815 + #endregion
733 816 }
734 817 }
... ...
HHWCSHost/View/Frm_Main.xaml.cs
... ... @@ -375,7 +375,7 @@ namespace HHWCSHost.View
375 375 }));
376 376  
377 377  
378   - return;
  378 + //return;
379 379 #endregion
380 380  
381 381 #region 检查是否连接正常
... ... @@ -465,7 +465,7 @@ namespace HHWCSHost.View
465 465 if (ReadAddress(props))
466 466 {
467 467 //todo:站台响应逻辑
468   - //PLC 有新消息标记 && WCS回复有新消息标记:此时WCS已经回复了消息,等待PLC响应,不做处理
  468 + //PLC 有新消息标记 && WCS回复有新消息标记:此时WCS已经回复了消息,等待PLC响应,不做处理,如果PLC新标记为3,表示解析错误
469 469  
470 470 //PLC没有新消息标记 && WCS有新消息标记:此时PLC已经确认消息,清除WCS回复消息
471 471  
... ...
HHWCSHost/data.txt
... ... @@ -22,4 +22,8 @@ disable 禁用
22 22 10 下达任务
23 23 20 开始执行
24 24 30 已经到站台
25   -40 已经完成
26 25 \ No newline at end of file
  26 +40 已经完成
  27 +
  28 +
  29 +交互:
  30 +1.我们无需写入任务号,PLC上报条码,我们根据条码来查找任务号
27 31 \ No newline at end of file
... ...