Commit 1cc651a5 几米阳光

去掉不需要的diam

1 个父辈 1d5a6205
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
</appSettings> </appSettings>
<log4net> <log4net>
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender"> <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="logs/LDACStore.log" /> <file value="logs/ZHACStore.log" />
<appendToFile value="true" /> <appendToFile value="true" />
<rollingStyle value="Date" /> <rollingStyle value="Date" />
<datePattern value="yyyy-MM-dd" /> <datePattern value="yyyy-MM-dd" />
......
...@@ -56,8 +56,6 @@ ...@@ -56,8 +56,6 @@
<Compile Include="Setting_Init.cs" /> <Compile Include="Setting_Init.cs" />
<Compile Include="util\AcSerialBean.cs" /> <Compile Include="util\AcSerialBean.cs" />
<Compile Include="util\ConfigAppSettings.cs" /> <Compile Include="util\ConfigAppSettings.cs" />
<Compile Include="util\CSVFileHelper.cs" />
<Compile Include="util\CSVReaderControl.cs" />
<Compile Include="util\FormUtil.cs" /> <Compile Include="util\FormUtil.cs" />
<Compile Include="util\HttpHelper.cs" /> <Compile Include="util\HttpHelper.cs" />
<Compile Include="util\HumitureController.cs" /> <Compile Include="util\HumitureController.cs" />
...@@ -71,14 +69,9 @@ ...@@ -71,14 +69,9 @@
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="util\ScanCodeManager.cs" /> <Compile Include="util\ScanCodeManager.cs" />
<Compile Include="util\ScanSocket.cs" />
<Compile Include="util\SerialBean.cs" />
<Compile Include="util\TcpClient.cs" /> <Compile Include="util\TcpClient.cs" />
<Compile Include="util\TcpServer.cs" /> <Compile Include="util\TcpServer.cs" />
<Compile Include="util\UdpServer.cs" /> <Compile Include="util\UdpServer.cs" />
<Compile Include="xml\ModblsPositionXML.cs" />
<Compile Include="xml\XMLCache.cs" />
<Compile Include="xml\XmlData.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<WCFMetadata Include="Service References\" /> <WCFMetadata Include="Service References\" />
......
using log4net;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows.Forms;
namespace OnLineStore.Common
{
public class CSVFileHelper
{
public static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
/// <summary>
/// 将DataTable中数据写入到CSV文件中
/// </summary>
/// <param name="dt">提供保存数据的DataTable</param>
/// <param name="fileName">CSV的文件路径</param>
public static void SaveCSV(DataTable dt, string fullPath)
{
FileInfo fi = new FileInfo(fullPath);
if (!fi.Directory.Exists)
{
fi.Directory.Create();
}
FileStream fs = new FileStream(fullPath, System.IO.FileMode.Create, System.IO.FileAccess.Write);
//StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.Default);
StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.UTF8);
string data = "";
//写出列名称
for (int i = 0; i < dt.Columns.Count; i++)
{
data += dt.Columns[i].ColumnName.ToString();
if (i < dt.Columns.Count - 1)
{
data += ",";
}
}
sw.WriteLine(data);
//写出各行数据
for (int i = 0; i < dt.Rows.Count; i++)
{
data = "";
for (int j = 0; j < dt.Columns.Count; j++)
{
string str = dt.Rows[i][j].ToString();
str = str.Replace("\"", "\"\"");//替换英文冒号 英文冒号需要换成两个冒号
if (str.Contains(',') || str.Contains('"')
|| str.Contains('\r') || str.Contains('\n')) //含逗号 冒号 换行符的需要放到引号中
{
str = string.Format("\"{0}\"", str);
}
data += str;
if (j < dt.Columns.Count - 1)
{
data += ",";
}
}
sw.WriteLine(data);
}
sw.Close();
fs.Close();
DialogResult result = MessageBox.Show("CSV文件保存成功!");
}
public static string[][] Read(string fullname)
{
if (!File.Exists(fullname)) return new string[][] { };
var lines = File.ReadAllLines(fullname).Skip(1);
var list=new List<string[]>();
var builder = new StringBuilder();
foreach (var line in lines)
{
builder=new StringBuilder ();
var comma = false;
var array = line.ToCharArray();
var values = new List<string>();
var length = array.Length - 1;
var index = 0;
while (index < length)
{
var item = array[index++];
switch (item)
{
case ',':
if (comma)
{
builder.Append(item);
}
else
{
values.Add(builder.ToString());
builder = new StringBuilder();
}
break;
case '"':
comma = !comma;
break;
default:
builder.Append(item);
break;
}
}
var count = values.Count;
if (count == 0) continue;
list.Add(values.ToArray());
}
return list.ToArray();
}
//public static List<StoreBagConfig> ReadList(string fullname)
//{
// List<StoreBagConfig> result = new List<StoreBagConfig>();
// if (!File.Exists(fullname)) {
// return result;
// }
// var lines = File.ReadAllLines(fullname).Skip(1);
// var list = new List<string[]>();
// int index=0;
// foreach (var line in lines)
// {
// var array = line.Split(',');
// var length = array.Length ;
// if (length == 5)
// {
// int col = Int32.Parse(array[0]);
// int row = Int32.Parse(array[1]);
// int axisPosition = Int32.Parse(array[2]);
// int highPosition = Int32.Parse(array[3]);
// int lowPosition = Int32.Parse(array[4]);
// StoreBagConfig config = new StoreBagConfig();
// config.AxisPostion = axisPosition;
// config.BagColoum = col;
// config.CsvRowIndex = index;
// config.HighPostion = highPosition;
// config.LowPosition = lowPosition;
// config.BagRow = row;
// result.Add(config);
// }
// else
// {
// LogUtil.error(LOGGER,"读取csv,index="+index+",数据格式不匹配!,line="+line);
// }
// index++;
// }
// return result;
//}
}
}
...@@ -9,6 +9,9 @@ using System.Text; ...@@ -9,6 +9,9 @@ using System.Text;
namespace OnlineStore.Common namespace OnlineStore.Common
{ {
/// <summary>
/// 壁挂王字壳温湿度变送器(485型)
/// </summary>
public class HumitureController public class HumitureController
{ {
public static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); public static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
...@@ -116,9 +119,9 @@ namespace OnlineStore.Common ...@@ -116,9 +119,9 @@ namespace OnlineStore.Common
private static byte[] buildCheckData(byte[] sendData, int length) private static byte[] buildCheckData(byte[] sendData, int length)
{ {
ushort pChecksum = 0; ushort pChecksum = 0;
SerialBean.CalculateCRC(sendData, length, out pChecksum); AcSerialBean.CalculateCRC(sendData, length, out pChecksum);
string checkStr = Convert.ToString(pChecksum, 16); string checkStr = Convert.ToString(pChecksum, 16);
byte[] checkByte = SerialBean.StringToByte(checkStr); byte[] checkByte = AcSerialBean.StringToByte(checkStr);
if (checkByte.Length == 1) if (checkByte.Length == 1)
{ {
sendData[length] = checkByte[0]; sendData[length] = checkByte[0];
......
...@@ -461,23 +461,23 @@ namespace OnlineStore.Common ...@@ -461,23 +461,23 @@ namespace OnlineStore.Common
/// </summary> /// </summary>
/// <param name="s"></param> /// <param name="s"></param>
/// <returns></returns> /// <returns></returns>
public static byte[] StringToByte(string s) //public static byte[] StringToByte(string s)
{ //{
string temps = ReplaceSpace(s); // string temps = ReplaceSpace(s);
if (temps.Length % 2 != 0) // if (temps.Length % 2 != 0)
{ // {
temps = "0" + temps; // temps = "0" + temps;
} // }
byte[] tempb = new byte[50]; // byte[] tempb = new byte[50];
int j = 0; // int j = 0;
for (int i = 0; i < temps.Length; i = i + 2, j++) // for (int i = 0; i < temps.Length; i = i + 2, j++)
{ // {
tempb[j] = Convert.ToByte(temps.Substring(i, 2), 16); // tempb[j] = Convert.ToByte(temps.Substring(i, 2), 16);
} // }
byte[] send = new byte[j]; // byte[] send = new byte[j];
Array.Copy(tempb, send, j); // Array.Copy(tempb, send, j);
return send; // return send;
} //}
//除去空格 //除去空格
public static string ReplaceSpace(string str) public static string ReplaceSpace(string str)
...@@ -525,33 +525,33 @@ namespace OnlineStore.Common ...@@ -525,33 +525,33 @@ namespace OnlineStore.Common
pChecksum = check; pChecksum = check;
} }
public static void CalculateCRC(byte[] pByte, int nNumberOfBytes, out ushort pChecksum) //public static void CalculateCRC(byte[] pByte, int nNumberOfBytes, out ushort pChecksum)
{ //{
int nBit; // int nBit;
ushort nShiftedBit; // ushort nShiftedBit;
pChecksum = 0xFFFF; // pChecksum = 0xFFFF;
for (int nByte = 0; nByte < nNumberOfBytes; nByte++) // for (int nByte = 0; nByte < nNumberOfBytes; nByte++)
{ // {
pChecksum ^= pByte[nByte]; // pChecksum ^= pByte[nByte];
for (nBit = 0; nBit < 8; nBit++) // for (nBit = 0; nBit < 8; nBit++)
{ // {
if ((pChecksum & 0x1) == 1) // if ((pChecksum & 0x1) == 1)
{ // {
nShiftedBit = 1; // nShiftedBit = 1;
} // }
else // else
{ // {
nShiftedBit = 0; // nShiftedBit = 0;
} // }
pChecksum >>= 1; // pChecksum >>= 1;
if (nShiftedBit != 0) // if (nShiftedBit != 0)
{ // {
pChecksum ^= 0xA001; // pChecksum ^= 0xA001;
} // }
} // }
} // }
} //}
#endregion #endregion
} }
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OnlineStore.Common
{
public class ModblsPositionXML : XmlData
{
public int num { get; set; }
public int type { get; set; }
public int position { get; set; }
/// <summary>
/// 获取电缸移动到的位置
/// </summary>
/// <param name="num">层数,1000表示料口的位置</param>
/// <param name="type">1=低位置,2=高位置</param>
/// <returns></returns>
public static ModblsPositionXML getByNumAndType(int num, int type)
{
Dictionary<int, ModblsPositionXML> allDic = XMLCache<ModblsPositionXML>.getAllData(typeof(ModblsPositionXML));
foreach (ModblsPositionXML mo in allDic.Values)
{
if (mo.num == num && mo.type == type)
{
return mo;
}
}
return null;
}
public static List<ModblsPositionXML> getSortList()
{
List<ModblsPositionXML> list = new List<ModblsPositionXML>();
Dictionary<int, ModblsPositionXML> allDic = XMLCache<ModblsPositionXML>.getAllData(typeof(ModblsPositionXML));
list = (from m in allDic.Values.ToList<ModblsPositionXML>() orderby m.num ascending, m.type ascending, m.id descending select m).ToList<ModblsPositionXML>();
return list;
}
}
}
using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Xml;
namespace OnlineStore.Common
{
public class XMLCache<T>
{
public static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public static Dictionary<string, Dictionary<int, T>> xmlCache = new Dictionary<string, Dictionary<int, T>>();
public static Dictionary<int, T> getAllData(Type type)
{
if (!xmlCache.ContainsKey(type.Name))
{
if (type == null)
{
return null;
}
loadXml(type);
}
Dictionary<int, T> allData = xmlCache[type.Name];
return allData;
}
private static Dictionary<int, T> loadXml(Type type)
{
string className = type.Name;
Dictionary<int, T> data = new Dictionary<int, T>();
// Type type = Assembly.Load("testTool.xml." + className).GetType();
string nodeName = className.Substring(0, className.Length - 3);
string parNodeName = nodeName + "Info";
string xmlName = className.Substring(0, className.Length - 3) + "Info.xml";
XmlDocument xmlDoc = new XmlDocument();
string xmlPath = System.Windows.Forms.Application.StartupPath + @"\data\";
xmlDoc.Load(xmlPath + xmlName);
XmlNode parNode = xmlDoc.SelectSingleNode(parNodeName);
XmlNodeList xmlNodeList = parNode.ChildNodes;
for (int i = 0; i < xmlNodeList.Count; i++)
{
XmlNode node = xmlNodeList.Item(i);
XmlAttributeCollection collo = node.Attributes;
XmlAttribute[] list = new XmlAttribute[collo.Count];
collo.CopyTo(list, 0);
var bllIns = type.Assembly.CreateInstance(type.FullName);
//取得属性集合
PropertyInfo[] props = type.GetProperties();
int id = 0;
foreach (XmlAttribute xmlA in list)
{
try
{
var prop = props.First(c => c.Name == xmlA.Name);//获取同名属性
if (prop != null)
{//如果属性存在
prop.SetValue(bllIns, Convert.ChangeType(xmlA.Value, prop.PropertyType), null);//赋值****在这里需要考虑类型问题
}
if (xmlA.Name.Equals("id"))
{
id = int.Parse(xmlA.Value);
}
}
catch (Exception ex)
{
LogUtil.error(LOGGER, "出现错误:" + ex.Message);
}
}
if (!data.ContainsKey(id))
{
data.Add(id, (T)bllIns);
}
}
xmlCache.Add(className, data);
return data;
}
internal static T getXmlById(Type type, int id)
{
if (!xmlCache.ContainsKey(type.Name))
{
if (type == null)
{
return default(T);
}
loadXml(type);
}
Dictionary<int, T> allData = xmlCache[type.Name];
if (!allData.ContainsKey(id))
{
System.Windows.Forms.MessageBox.Show("找不到ID=" + id + "的" + type.Name);
}
return allData[id];
}
public static void SaveXml(Type type, XmlData mo)
{
string className = type.Name;
//判断xml是否已经存在
string xmlName = className.Substring(0, className.Length - 3) + "Info.xml";
XmlDocument xmlDoc = new XmlDocument();
string xmlPath = System.Windows.Forms.Application.StartupPath + @"\data\";
xmlDoc.Load(xmlPath + xmlName);
string nodeName = className.Substring(0, className.Length - 3);
string parNodeName = nodeName + "Info";
XmlNode parNode = xmlDoc.SelectSingleNode(parNodeName);
XmlNodeList xmlNodeList = parNode.ChildNodes;
//新增
if (mo.id == 0)
{
Dictionary<int, T> dic = getAllData(type);
int id = 0;
foreach (int key in dic.Keys)
{
if (key >= id)
{
id = key + 1;
}
}
mo.id = id;
XmlNode node = xmlNodeList.Item(xmlNodeList.Count - 1);
XmlNode newNode = node.CloneNode(true);
XmlAttributeCollection collo = node.Attributes;
XmlAttribute[] list = new XmlAttribute[collo.Count];
collo.CopyTo(list, 0);
//取得属性集合
PropertyInfo[] props = type.GetProperties();
// parNode.RemoveChild(node);
foreach (XmlAttribute xmlA in list)
{
var prop = props.First(c => c.Name == xmlA.Name);//获取同名属性
if (prop != null)
{
node.Attributes.Remove(xmlA);
xmlA.Value = prop.GetValue(mo,null).ToString();
node.Attributes.Append(xmlA);
}
}
parNode.InsertBefore(newNode, node);
}
//修改
else
{
xmlCache[className].Remove(mo.id);
for (int i = 0; i < xmlNodeList.Count; i++)
{
XmlNode node = xmlNodeList.Item(i);
XmlAttributeCollection collo = node.Attributes;
XmlAttribute[] list = new XmlAttribute[collo.Count];
collo.CopyTo(list, 0);
bool isRight = false;
foreach (XmlAttribute xmlA in list)
{
try
{
if (xmlA.Name.Equals("id"))
{
int id = int.Parse(xmlA.Value);
if (id.Equals(mo.id))
{
isRight = true;
}
break;
}
}
catch (Exception ex)
{
LogUtil.error(LOGGER, "出现错误:" + ex.StackTrace);
}
}
if (isRight)
{ //取得属性集合
PropertyInfo[] props = type.GetProperties();
// parNode.RemoveChild(node);
foreach (XmlAttribute xmlA in list)
{
var prop = props.First(c => c.Name == xmlA.Name);//获取同名属性
if (prop != null)
{
node.Attributes.Remove(xmlA);
xmlA.Value = prop.GetValue(mo, null).ToString();
node.Attributes.Append(xmlA);
}
}
parNode.ReplaceChild(node, node);
break;
}
}
}
xmlDoc.Save(xmlPath + xmlName);
xmlCache[className].Add(mo.id, (T)(object)mo);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OnlineStore.Common
{
public class XmlData
{
public int id { get; set; }
}
}
...@@ -179,7 +179,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -179,7 +179,7 @@ namespace OnlineStore.DeviceLibrary
data[5] = 6; // Message size data[5] = 6; // Message size
data[6] = slaveId; // Slave address //必须设置为"1": 2012.04-24 覃发光; data[6] = slaveId; // Slave address //必须设置为"1": 2012.04-24 覃发光;
data[7] = function; ; // Function code data[7] = function; ; // Function code
byte[] _adr = SerialBean.StringToByte(address); byte[] _adr = AcSerialBean.StringToByte(address);
data[8] = _adr[0]; // Start address data[8] = _adr[0]; // Start address
data[9] = _adr[1]; // Start address data[9] = _adr[1]; // Start address
byte[] _length = BitConverter.GetBytes((short)1); byte[] _length = BitConverter.GetBytes((short)1);
...@@ -206,7 +206,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -206,7 +206,7 @@ namespace OnlineStore.DeviceLibrary
data[5] = 6; // Message size data[5] = 6; // Message size
data[6] = SlaveID; // Slave address //必须设置为"1": 2012.04-24 覃发光; data[6] = SlaveID; // Slave address //必须设置为"1": 2012.04-24 覃发光;
data[7] = function; // Function code data[7] = function; // Function code
byte[] _adr = SerialBean.StringToByte(startAddress); byte[] _adr = AcSerialBean.StringToByte(startAddress);
if (_adr.Length .Equals( 2)) if (_adr.Length .Equals( 2))
{ {
data[8] = _adr[0]; // Start address data[8] = _adr[0]; // Start address
......
...@@ -260,6 +260,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -260,6 +260,7 @@ namespace OnlineStore.DeviceLibrary
string strFromat = "{0:X2}"; string strFromat = "{0:X2}";
string msg = "";
for (int index = 0; index < DefaultAILength; index++) for (int index = 0; index < DefaultAILength; index++)
{ {
string str1 = String.Format(strFromat, values[index * 4 + 2]) + String.Format(strFromat, values[index * 4 + 3]) string str1 = String.Format(strFromat, values[index * 4 + 2]) + String.Format(strFromat, values[index * 4 + 3])
...@@ -271,8 +272,10 @@ namespace OnlineStore.DeviceLibrary ...@@ -271,8 +272,10 @@ namespace OnlineStore.DeviceLibrary
{ {
Console.WriteLine(str1 + " float convert = {0}", value); Console.WriteLine(str1 + " float convert = {0}", value);
} }
msg += "【" + index + "=" + value + "】";
kndList.Add(io); kndList.Add(io);
} }
LogUtil.info(msg);
lock (AIMapLock) lock (AIMapLock)
{ {
if (AIValueMap.ContainsKey(ioIp)) if (AIValueMap.ContainsKey(ioIp))
...@@ -281,23 +284,23 @@ namespace OnlineStore.DeviceLibrary ...@@ -281,23 +284,23 @@ namespace OnlineStore.DeviceLibrary
} }
AIValueMap.Add(ioIp, kndList); AIValueMap.Add(ioIp, kndList);
} }
try //try
{ //{
//每次上传后验证下 // //每次上传后验证下
int v1 = (int)GetAIValue(ioIp, 1); // int v1 = (int)GetAIValue(ioIp, 1);
int v2 = (int)GetAIValue(ioIp, 2); // int v2 = (int)GetAIValue(ioIp, 2);
int v3 = (int)GetAIValue(ioIp, 3); // int v3 = (int)GetAIValue(ioIp, 3);
if (v1.Equals(0) && v2.Equals(0) && v3.Equals(0)) // if (v1.Equals(0) && v2.Equals(0) && v3.Equals(0))
{ // {
string value = AcSerialBean.ByteToString(values); // string value = AcSerialBean.ByteToString(values);
LogUtil.error("收到【" + ioIp + "】的数据【" + value + "】,三个高度都为0,断开重新连接"); // LogUtil.error("收到【" + ioIp + "】的数据【" + value + "】,三个高度都为0,断开重新连接");
ConnectionIP(ioIp); // ConnectionIP(ioIp);
} // }
} //}
catch (Exception ex) //catch (Exception ex)
{ //{
LogUtil.error("验证数据出错:" + ex.StackTrace); // LogUtil.error("验证数据出错:" + ex.StackTrace);
} //}
} }
} }
catch (Exception ex) catch (Exception ex)
...@@ -331,7 +334,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -331,7 +334,7 @@ namespace OnlineStore.DeviceLibrary
break; break;
} }
} }
LOGGER.Debug ("Read data:【" + reviceMsg + "】 "); // LOGGER.Info ("Read data:【" + reviceMsg + "】 ");
if (ID == 0xFF) if (ID == 0xFF)
{ {
return; return;
......
...@@ -123,15 +123,10 @@ namespace OnlineStore.DeviceLibrary ...@@ -123,15 +123,10 @@ namespace OnlineStore.DeviceLibrary
if (!clinet.ISConnection()) if (!clinet.ISConnection())
{ {
ushort port = 502; ushort port = 502;
ConnectionIP(io, port); //ConnectionIP(io, port);
LogUtil.error(LOGGER, io + "当前没有连上,重连" + io); LogUtil.error(LOGGER, io + "当前没有连上,重连" + io);
} }
} }
//if (DBStoreManager.StoreBoxMap != null && DBStoreManager.StoreBoxMap.Count > 0 && !FileLister.isConnect)
//{
// string RemoteURL = ConfigAppSettings.GetValue(Setting_Init.RemoteURL);
// FileGenerated.StartListerDirectory(RemoteURL, "*.*");
//}
} }
catch (Exception ex) catch (Exception ex)
{ {
......
...@@ -132,9 +132,9 @@ namespace OnlineStore.DeviceLibrary ...@@ -132,9 +132,9 @@ namespace OnlineStore.DeviceLibrary
public static byte[] buildCheckData(byte[] sendData, int length) public static byte[] buildCheckData(byte[] sendData, int length)
{ {
ushort pChecksum = 0; ushort pChecksum = 0;
SerialBean.CalculateCRC(sendData, length, out pChecksum); AcSerialBean.CalculateCRC(sendData, length, out pChecksum);
string checkStr = Convert.ToString(pChecksum, 16); string checkStr = Convert.ToString(pChecksum, 16);
byte[] checkByte = SerialBean.StringToByte(checkStr); byte[] checkByte = AcSerialBean.StringToByte(checkStr);
if (checkByte.Length == 1) if (checkByte.Length == 1)
{ {
sendData[length] = checkByte[0]; sendData[length] = checkByte[0];
...@@ -177,7 +177,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -177,7 +177,7 @@ namespace OnlineStore.DeviceLibrary
byte[] sendData = new byte[8]; byte[] sendData = new byte[8];
sendData[0] = (byte)slvAddr; sendData[0] = (byte)slvAddr;
sendData[1] = CMD_WriteCoil; sendData[1] = CMD_WriteCoil;
byte[] addrByte = SerialBean.StringToByte(addr.ToString()); byte[] addrByte = AcSerialBean.StringToByte(addr.ToString());
if (addrByte.Length == 1) if (addrByte.Length == 1)
{ {
sendData[2] = 0x00; sendData[2] = 0x00;
...@@ -189,7 +189,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -189,7 +189,7 @@ namespace OnlineStore.DeviceLibrary
sendData[2] = addrByte[0]; sendData[2] = addrByte[0];
} }
byte[] dataByte = SerialBean.StringToByte(dataValue); byte[] dataByte = AcSerialBean.StringToByte(dataValue);
if (dataByte.Length == 1) if (dataByte.Length == 1)
{ {
sendData[4] = 0x00; sendData[4] = 0x00;
...@@ -210,7 +210,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -210,7 +210,7 @@ namespace OnlineStore.DeviceLibrary
byte[] sendData = new byte[8]; byte[] sendData = new byte[8];
sendData[0] = (byte)slvAddr; sendData[0] = (byte)slvAddr;
sendData[1] = CMD_ReadCoil; sendData[1] = CMD_ReadCoil;
byte[] addrByte = SerialBean.StringToByte(addr.ToString()); byte[] addrByte = AcSerialBean.StringToByte(addr.ToString());
if (addrByte.Length == 1) if (addrByte.Length == 1)
{ {
sendData[2] = 0x00; sendData[2] = 0x00;
...@@ -222,7 +222,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -222,7 +222,7 @@ namespace OnlineStore.DeviceLibrary
sendData[2] = addrByte[0]; sendData[2] = addrByte[0];
} }
byte[] dataByte = SerialBean.StringToByte(length.ToString()); byte[] dataByte = AcSerialBean.StringToByte(length.ToString());
if (dataByte.Length == 1) if (dataByte.Length == 1)
{ {
sendData[4] = 0x00; sendData[4] = 0x00;
...@@ -253,7 +253,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -253,7 +253,7 @@ namespace OnlineStore.DeviceLibrary
byte[] sendData = new byte[8 ]; byte[] sendData = new byte[8 ];
sendData[0] = (byte)slvAddr; sendData[0] = (byte)slvAddr;
sendData[1] = CMD_ReadRegisters; sendData[1] = CMD_ReadRegisters;
byte[] addrByte = SerialBean.StringToByte(addr.ToString()); byte[] addrByte = AcSerialBean.StringToByte(addr.ToString());
if (addrByte.Length == 1) if (addrByte.Length == 1)
{ {
sendData[2] = 0x00; sendData[2] = 0x00;
...@@ -265,7 +265,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -265,7 +265,7 @@ namespace OnlineStore.DeviceLibrary
sendData[2] = addrByte[0]; sendData[2] = addrByte[0];
} }
byte[] dataByte = SerialBean.StringToByte(length.ToString()); byte[] dataByte = AcSerialBean.StringToByte(length.ToString());
if (dataByte.Length == 1) if (dataByte.Length == 1)
{ {
sendData[4] = 0x00; sendData[4] = 0x00;
...@@ -295,7 +295,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -295,7 +295,7 @@ namespace OnlineStore.DeviceLibrary
byte[] sendData = new byte[8]; byte[] sendData = new byte[8];
sendData[0] = (byte)slvAddr; sendData[0] = (byte)slvAddr;
sendData[1] = CMD_WriteRegisters; sendData[1] = CMD_WriteRegisters;
byte[] addrByte = SerialBean.StringToByte(addr.ToString()); byte[] addrByte = AcSerialBean.StringToByte(addr.ToString());
if (addrByte.Length == 1) if (addrByte.Length == 1)
{ {
sendData[2] = 0x00; sendData[2] = 0x00;
...@@ -307,7 +307,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -307,7 +307,7 @@ namespace OnlineStore.DeviceLibrary
sendData[2] = addrByte[0]; sendData[2] = addrByte[0];
} }
byte[] dataByte = SerialBean.StringToByte(dataValue); byte[] dataByte = AcSerialBean.StringToByte(dataValue);
if (dataByte.Length == 1) if (dataByte.Length == 1)
{ {
sendData[4] = 0x00; sendData[4] = 0x00;
......
...@@ -247,8 +247,8 @@ namespace OnlineStore.DeviceLibrary ...@@ -247,8 +247,8 @@ namespace OnlineStore.DeviceLibrary
public static void RelMove(string portName, int slvAddr, int position) public static void RelMove(string portName, int slvAddr, int position)
{ {
//int position = Convert.ToInt32(txtPosition.Text); //int position = Convert.ToInt32(txtPosition.Text);
byte[] positionData = SerialBean.StringToByte(position.ToString("X8")); byte[] positionData = AcSerialBean.StringToByte(position.ToString("X8"));
byte[] data = SerialBean.StringToByte("0110480C 000408 10000111EC78FFFF ffff"); byte[] data = AcSerialBean.StringToByte("0110480C 000408 10000111EC78FFFF ffff");
data[0] = (byte)slvAddr; data[0] = (byte)slvAddr;
data[data.Length - 1] = 0x00; data[data.Length - 1] = 0x00;
data[data.Length - 2] = 0x00; data[data.Length - 2] = 0x00;
...@@ -387,8 +387,8 @@ namespace OnlineStore.DeviceLibrary ...@@ -387,8 +387,8 @@ namespace OnlineStore.DeviceLibrary
public static void AbsMove(string portName, int slvAddr, int position) public static void AbsMove(string portName, int slvAddr, int position)
{ {
//int position = Convert.ToInt32(txtPosition.Text, 10); //int position = Convert.ToInt32(txtPosition.Text, 10);
byte[] positionData = SerialBean.StringToByte(position.ToString("X8")); byte[] positionData = AcSerialBean.StringToByte(position.ToString("X8"));
byte[] data = SerialBean.StringToByte("01104808 000408 10000211 EC78FFFF ffff"); byte[] data = AcSerialBean.StringToByte("01104808 000408 10000211 EC78FFFF ffff");
data[0] = (byte)slvAddr; data[0] = (byte)slvAddr;
data[data.Length - 1] = 0x00; data[data.Length - 1] = 0x00;
data[data.Length - 2] = 0x00; data[data.Length - 2] = 0x00;
......
...@@ -40,7 +40,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -40,7 +40,7 @@ namespace OnlineStore.DeviceLibrary
//} //}
public static void SendStrAndSleep(string portName, string str, int sleepS) public static void SendStrAndSleep(string portName, string str, int sleepS)
{ {
byte[] data = SerialBean.StringToByte(str); byte[] data = AcSerialBean.StringToByte(str);
data[data.Length - 1] = 0x00; data[data.Length - 1] = 0x00;
data[data.Length - 2] = 0x00; data[data.Length - 2] = 0x00;
data = ACCMDManager.buildCheckData(data, data.Length - 2); data = ACCMDManager.buildCheckData(data, data.Length - 2);
...@@ -49,7 +49,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -49,7 +49,7 @@ namespace OnlineStore.DeviceLibrary
} }
public static void SendStr(string portName, string str) public static void SendStr(string portName, string str)
{ {
byte[] data = SerialBean.StringToByte(str); byte[] data = AcSerialBean.StringToByte(str);
data[data.Length - 1] = 0x00; data[data.Length - 1] = 0x00;
data[data.Length - 2] = 0x00; data[data.Length - 2] = 0x00;
data = ACCMDManager.buildCheckData(data, data.Length - 2); data = ACCMDManager.buildCheckData(data, data.Length - 2);
...@@ -282,7 +282,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -282,7 +282,7 @@ namespace OnlineStore.DeviceLibrary
public static void SendStr(string portName, int slvAddr, string str) public static void SendStr(string portName, int slvAddr, string str)
{ {
//string str = txtSendStr.Text; //string str = txtSendStr.Text;
byte[] data = SerialBean.StringToByte(str); byte[] data = AcSerialBean.StringToByte(str);
data[data.Length - 1] = 0x00; data[data.Length - 1] = 0x00;
data[data.Length - 2] = 0x00; data[data.Length - 2] = 0x00;
data = ACCMDManager.buildCheckData(data, data.Length - 2); data = ACCMDManager.buildCheckData(data, data.Length - 2);
......
...@@ -134,9 +134,9 @@ namespace OnlineStore.DeviceLibrary ...@@ -134,9 +134,9 @@ namespace OnlineStore.DeviceLibrary
//校验 //校验
ushort pChecksum = 0; ushort pChecksum = 0;
SerialBean.CalculateCRC(bits, bits.Length - 2, out pChecksum); AcSerialBean.CalculateCRC(bits, bits.Length - 2, out pChecksum);
string checkStr = Convert.ToString(pChecksum, 16); string checkStr = Convert.ToString(pChecksum, 16);
byte[] checkByte = SerialBean.StringToByte(checkStr); byte[] checkByte = AcSerialBean.StringToByte(checkStr);
if (checkByte.Length == 1) if (checkByte.Length == 1)
{ {
if (!bits[bits.Length - 2].Equals(checkByte[0])) if (!bits[bits.Length - 2].Equals(checkByte[0]))
...@@ -179,9 +179,9 @@ namespace OnlineStore.DeviceLibrary ...@@ -179,9 +179,9 @@ namespace OnlineStore.DeviceLibrary
} }
//校验 //校验
ushort pChecksum = 0; ushort pChecksum = 0;
SerialBean.CalculateCRC(bits, bits.Length - 2, out pChecksum); AcSerialBean.CalculateCRC(bits, bits.Length - 2, out pChecksum);
string checkStr = Convert.ToString(pChecksum, 16); string checkStr = Convert.ToString(pChecksum, 16);
byte[] checkByte = SerialBean.StringToByte(checkStr); byte[] checkByte = AcSerialBean.StringToByte(checkStr);
if (checkByte.Length == 1) if (checkByte.Length == 1)
{ {
if (!bits[bits.Length - 2].Equals(checkByte[0])) if (!bits[bits.Length - 2].Equals(checkByte[0]))
...@@ -213,7 +213,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -213,7 +213,7 @@ namespace OnlineStore.DeviceLibrary
int slvAddr = (int)bits[0]; int slvAddr = (int)bits[0];
byte[] positionData = new byte[4]; byte[] positionData = new byte[4];
Array.Copy(bits, 3, positionData, 0, 4); Array.Copy(bits, 3, positionData, 0, 4);
string a = SerialBean.byteToHexStr(positionData); string a = AcSerialBean.byteToHexStr(positionData);
absValue = Convert.ToInt32(a, 16); absValue = Convert.ToInt32(a, 16);
LogUtil.debug(LOGGER, "收到驱动器【" + slvAddr + "】绝对位置【" + absValue + "】"); LogUtil.debug(LOGGER, "收到驱动器【" + slvAddr + "】绝对位置【" + absValue + "】");
if (shuokeMap.ContainsKey(slvAddr)) if (shuokeMap.ContainsKey(slvAddr))
...@@ -393,7 +393,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -393,7 +393,7 @@ namespace OnlineStore.DeviceLibrary
sendData[5] = 0x00; sendData[5] = 0x00;
sendData[6] = 0x00; sendData[6] = 0x00;
string speed = Convert.ToString(position, 16); string speed = Convert.ToString(position, 16);
byte[] speedByte = SerialBean.StringToByte(speed); byte[] speedByte = AcSerialBean.StringToByte(speed);
for (int i = 0; i < speedByte.Length; i++) for (int i = 0; i < speedByte.Length; i++)
{ {
...@@ -444,7 +444,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -444,7 +444,7 @@ namespace OnlineStore.DeviceLibrary
sendData[5] = 0x00; sendData[5] = 0x00;
sendData[6] = 0x00; sendData[6] = 0x00;
string speed = Convert.ToString(dataValue, 16); string speed = Convert.ToString(dataValue, 16);
byte[] speedByte = SerialBean.StringToByte(speed); byte[] speedByte = AcSerialBean.StringToByte(speed);
for (int i = 0; i < speedByte.Length; i++) for (int i = 0; i < speedByte.Length; i++)
{ {
...@@ -462,9 +462,9 @@ namespace OnlineStore.DeviceLibrary ...@@ -462,9 +462,9 @@ namespace OnlineStore.DeviceLibrary
private static byte[] buildCheckData(byte[] sendData, int length) private static byte[] buildCheckData(byte[] sendData, int length)
{ {
ushort pChecksum = 0; ushort pChecksum = 0;
SerialBean.CalculateCRC(sendData, length, out pChecksum); AcSerialBean.CalculateCRC(sendData, length, out pChecksum);
string checkStr = Convert.ToString(pChecksum, 16); string checkStr = Convert.ToString(pChecksum, 16);
byte[] checkByte = SerialBean.StringToByte(checkStr); byte[] checkByte = AcSerialBean.StringToByte(checkStr);
if (checkByte.Length == 1) if (checkByte.Length == 1)
{ {
sendData[length] = checkByte[0]; sendData[length] = checkByte[0];
......
...@@ -90,7 +90,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -90,7 +90,7 @@ namespace OnlineStore.DeviceLibrary
string nameStr = ConfigAppSettings.GetValue(Setting_Init.CameraName); string nameStr = ConfigAppSettings.GetValue(Setting_Init.CameraName);
string codeStr = ConfigAppSettings.GetValue(Setting_Init.CodeType); string codeStr = ConfigAppSettings.GetValue(Setting_Init.CodeType);
CodeManager.LoadConfig(nameStr,codeStr); CodeManager.LoadConfig(nameStr,codeStr);
//初始化 //连接设备 //初始化 //连接设备
KNDManager.ConnectionKND(Config.DIODeviceNameList); KNDManager.ConnectionKND(Config.DIODeviceNameList);
KNDAIManager.ConnectionIP(Config.AIDevice_IP); KNDAIManager.ConnectionIP(Config.AIDevice_IP);
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
using OnlineStore.Common; using OnlineStore.Common;
using OnlineStore.DeviceLibrary; using OnlineStore.DeviceLibrary;
using OnlineStore.LoadCSVLibrary; using OnlineStore.LoadCSVLibrary;
using OnLineStore.Common;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!