Commit 0a8030fe 几米阳光

送丝器修改

1 个父辈 637e6ef8
......@@ -341,8 +341,7 @@ namespace URSoldering.Common
}
if (_serialPort.BytesToRead >= ReceiveData.Length)
{
ReceiveData = new byte[_serialPort.BytesToRead];
ret = _serialPort.Read(ReceiveData, 0, _serialPort.BytesToRead);
ret = _serialPort.Read(ReceiveData, 0, ReceiveData.Length);
}
else if(_serialPort.BytesToRead>0)
{
......@@ -524,7 +523,7 @@ namespace URSoldering.Common
int j = 0;
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];
Array.Copy(tempb, send, j);
......
......@@ -26,16 +26,16 @@ namespace URSoldering.DeviceLibrary
private static StopBits stopBits = StopBits.One; //停止位
private static SerialBean sb = null;
private static string CMD_WriteMode = "WMOD00002";
private static string CMD_SetSpeed = "WSPD";
private static string CMD_SetSendLength = "WLEN";
private static string CMD_GetSpeed = "RLEN";
private static string CMD_GetSendLength = "RSPD";
private static string CMD_GetStatus = "RECV";
private static string CMD_StartForwardSend = "WSFD00001";
private static string CMD_StartBackSend = "WSFD00000";
private static string CMD_StopSend = "WSSD00000";
private static string CMD_Reset = "WCTP00000";
private static string CMD_WriteMode = "0010WMOD00002";
private static string CMD_SetSpeed = "0010WSPD";
private static string CMD_SetSendLength = "0010WLEN";
private static string CMD_GetSendLength = "0010RLEN";
private static string CMD_GetSpeed = "0010RSPD";
private static string CMD_GetStatus = "0010RECV";
private static string CMD_StartForwardSend = "0010WSFD00001";
private static string CMD_StartBackSend = "0010WSFD00000";
private static string CMD_StopSend = "0010WSSD00000";
private static string CMD_Reset = "0010WCTP00000";
//private static string CMD_WriteMode = "02 57 4D 4F 44 30 30 30 30 32 03 22";
//private static string CMD_SetSpeed = "02 57 53 50 44 30 30 31 31 30 03 21";
......@@ -110,14 +110,16 @@ namespace URSoldering.DeviceLibrary
{
bool isOk = false;
byte[] reviceData = parseCommand(CMD_GetSpeed, out isOk);
return getReviceData(reviceData);
int data = getReviceData(reviceData);
return data ;
}
public static int queryLength()
{
bool isOk = false;
byte[] reviceData = parseCommand(CMD_GetSendLength, out isOk);
return getReviceData(reviceData);
int data = getReviceData(reviceData);
return data;
}
public static int getReviceData(byte[] dataArray)
{
......@@ -128,10 +130,12 @@ namespace URSoldering.DeviceLibrary
{
return 0;
}
for (int i = 5; i <= 9; i++)
if (dataArray.Length >= 14)
{
strData +=dataArray[i] + "";
for (int i = 9; i <= 13; i++)
{
strData += (char)dataArray[i] + "";
}
}
}
catch (Exception ex)
......@@ -229,7 +233,11 @@ namespace URSoldering.DeviceLibrary
byte[] messageAll = new byte[message.Length + 1];
message.CopyTo(messageAll, 0);
messageAll[messageAll.Length - 1] = (byte)bcc;
if ("R".Equals(commandText.Substring(0, 1)))
if (commandText.Length >= 5 && ("R".Equals(commandText.Substring(4, 1))))
{
data = new byte[messageAll.Length + 5];
}
else if ("R".Equals(commandText.Substring(0, 1)))
{
data = new byte[messageAll.Length + 5];
}
......@@ -237,6 +245,8 @@ namespace URSoldering.DeviceLibrary
{
data = new byte[messageAll.Length - 5];
}
string str = SerialBean.byteToHexStr(messageAll);
LogUtil.info(" 【"+commandText+"】 转换后【"+str+"】");
//data = new byte[messageAll.Length];
sb.SendCommand(messageAll, ref data, 2, out isOk);
string rawMsg = Encoding.ASCII.GetString(data, 0, data.Length);
......
......@@ -140,18 +140,29 @@ namespace URSoldering.Client
private void btnSend_Click(object sender, EventArgs e)
{
string msg = "";
string str = "02 30 30 31 30 57 53 46 44 30 30 30 30 31 03 37 ";
byte[] data = SerialBean.StringToByte(str);
if (data != null && data.Length > 0)
{
msg = Encoding.ASCII.GetString(data, 1, data.Length - 3);
}
txtRevice.Text = "";
string text = txtSend.Text;
bool isOk = false;
byte[] reviceData =SendWireManager.parseCommand(text, out isOk);
int length = reviceData.Length - 3;
if (length <= 0)
byte[] reviceData = SendWireManager.parseCommand(text, out isOk);
if (reviceData != null && reviceData.Length > 0)
{
length = reviceData.Length;
int length = reviceData.Length - 3;
if (length <= 0)
{
length = reviceData.Length;
}
string rawMsg = Encoding.ASCII.GetString(reviceData, 1, length);
txtRevice.Text = rawMsg;
}
string rawMsg = Encoding.ASCII.GetString(reviceData, 1, length);
txtRevice.Text = rawMsg;
}
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!