Commit c1e49efa 几米阳光

多个伺服可以同一个com不同的地址

1 个父辈 5a75347a
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
<add key ="DebugPosId" value ="1#AC1_2_1_1"/> <add key ="DebugPosId" value ="1#AC1_2_1_1"/>
<!--是否有门禁屏蔽功能,=1表示有此功能--> <!--是否有门禁屏蔽功能,=1表示有此功能-->
<add key ="HasDisableDoorControl" value ="0"/> <add key ="HasDisableDoorControl" value ="0"/>
<add key ="ACBaudRate" value ="9600"/>
</appSettings> </appSettings>
<log4net> <log4net>
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender"> <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
......
...@@ -331,7 +331,8 @@ namespace OnlineStore.AutoInOutStore ...@@ -331,7 +331,8 @@ namespace OnlineStore.AutoInOutStore
int lCountPulse1 = ACServerManager.GetActualtPosition(store.Config.Middle_Axis.DeviceName, store.Config.Middle_Axis.GetAxisValue()); int lCountPulse1 = ACServerManager.GetActualtPosition(store.Config.Middle_Axis.DeviceName, store.Config.Middle_Axis.GetAxisValue());
lblCountPulse1.Text = string.Format("{0:d}", lCountPulse1); lblCountPulse1.Text = string.Format("{0:d}", lCountPulse1);
txtMiddleTarget.Text = store.Config.Middle_Axis.TargetPosition.ToString(); txtMiddleTarget.Text = store.Config.Middle_Axis.TargetPosition.ToString();
if (deviceName.Equals(store.Config.Middle_Axis.DeviceName)) //if (deviceName.Equals(store.Config.Middle_Axis.DeviceName))
if(store.Config.Middle_Axis.IsSameAxis(deviceName,SlvAddr))
{ {
lblOutPulse.Text = lblOutPulse1.Text; lblOutPulse.Text = lblOutPulse1.Text;
lblCountPulse.Text = lblCountPulse1.Text; lblCountPulse.Text = lblCountPulse1.Text;
...@@ -346,8 +347,9 @@ namespace OnlineStore.AutoInOutStore ...@@ -346,8 +347,9 @@ namespace OnlineStore.AutoInOutStore
int lCountPulse2 = ACServerManager.GetActualtPosition(store.Config.UpDown_Axis.DeviceName, store.Config.UpDown_Axis.GetAxisValue()); int lCountPulse2 = ACServerManager.GetActualtPosition(store.Config.UpDown_Axis.DeviceName, store.Config.UpDown_Axis.GetAxisValue());
lblCountPulse2.Text = string.Format("{0:d}", lCountPulse2); lblCountPulse2.Text = string.Format("{0:d}", lCountPulse2);
txtUpdownTarget.Text = store.Config.UpDown_Axis.TargetPosition.ToString(); txtUpdownTarget.Text = store.Config.UpDown_Axis.TargetPosition.ToString();
if (deviceName.Equals(store.Config.UpDown_Axis.DeviceName)) //if (deviceName.Equals(store.Config.UpDown_Axis.DeviceName))
{ if (store.Config.UpDown_Axis.IsSameAxis(deviceName, SlvAddr))
{
lblOutPulse.Text = lblOutPulse2.Text; lblOutPulse.Text = lblOutPulse2.Text;
lblCountPulse.Text = lblCountPulse2.Text; lblCountPulse.Text = lblCountPulse2.Text;
} }
...@@ -360,8 +362,9 @@ namespace OnlineStore.AutoInOutStore ...@@ -360,8 +362,9 @@ namespace OnlineStore.AutoInOutStore
int lCountPulse3 = ACServerManager.GetActualtPosition(store.Config.InOut_Axis.DeviceName, store.Config.InOut_Axis.GetAxisValue()); int lCountPulse3 = ACServerManager.GetActualtPosition(store.Config.InOut_Axis.DeviceName, store.Config.InOut_Axis.GetAxisValue());
lblCountPulse3.Text = string.Format("{0:d}", lCountPulse3); lblCountPulse3.Text = string.Format("{0:d}", lCountPulse3);
txtInoutTarget.Text = store.Config.InOut_Axis.TargetPosition.ToString(); txtInoutTarget.Text = store.Config.InOut_Axis.TargetPosition.ToString();
if (deviceName.Equals(store.Config.InOut_Axis.DeviceName)) //if (deviceName.Equals(store.Config.InOut_Axis.DeviceName))
{ if (store.Config.InOut_Axis.IsSameAxis(deviceName, SlvAddr))
{
lblOutPulse.Text = lblOutPulse3.Text; lblOutPulse.Text = lblOutPulse3.Text;
lblCountPulse.Text = lblCountPulse3.Text; lblCountPulse.Text = lblCountPulse3.Text;
} }
...@@ -374,8 +377,9 @@ namespace OnlineStore.AutoInOutStore ...@@ -374,8 +377,9 @@ namespace OnlineStore.AutoInOutStore
int lCountPulse5 = ACServerManager.GetActualtPosition(store.Config.Batch_Axis.DeviceName, store.Config.Batch_Axis.GetAxisValue()); int lCountPulse5 = ACServerManager.GetActualtPosition(store.Config.Batch_Axis.DeviceName, store.Config.Batch_Axis.GetAxisValue());
lblCountPulse5.Text = string.Format("{0:d}", lCountPulse5); lblCountPulse5.Text = string.Format("{0:d}", lCountPulse5);
txtBatchTarget.Text = store.Config.Batch_Axis.TargetPosition.ToString(); txtBatchTarget.Text = store.Config.Batch_Axis.TargetPosition.ToString();
if (deviceName.Equals(store.Config.Batch_Axis.DeviceName)) //if (deviceName.Equals(store.Config.Batch_Axis.DeviceName))
{ if (store.Config.Batch_Axis.IsSameAxis(deviceName, SlvAddr))
{
lblOutPulse.Text = lblOutPulse5.Text; lblOutPulse.Text = lblOutPulse5.Text;
lblCountPulse.Text = lblCountPulse5.Text; lblCountPulse.Text = lblCountPulse5.Text;
} }
...@@ -535,12 +539,12 @@ namespace OnlineStore.AutoInOutStore ...@@ -535,12 +539,12 @@ namespace OnlineStore.AutoInOutStore
// MessageBox.Show("位置超出" + axisC.Explain + "上下限(" + axisC.PositionMin + "-" + axisC.PositionMax + ")"); // MessageBox.Show("位置超出" + axisC.Explain + "上下限(" + axisC.PositionMin + "-" + axisC.PositionMax + ")");
// return; // return;
//} //}
if (portName.Equals(store.Config.InOut_Axis.DeviceName) && (store.InOutAxisCanMove().Equals(false))) if (store.Config.InOut_Axis.IsSameAxis(portName,SlvAddr) && (store.InOutAxisCanMove().Equals(false)))
{ {
MessageBox.Show("定位气缸不在下降端,不能移动进出轴", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); MessageBox.Show("定位气缸不在下降端,不能移动进出轴", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return; return;
} }
else if (portName.Equals(store.Config.Middle_Axis.DeviceName) || portName.Equals(store.Config.UpDown_Axis.DeviceName)) else if ( store.Config.Middle_Axis.IsSameAxis(portName,SlvAddr ) || store.Config.UpDown_Axis.IsSameAxis(portName,SlvAddr))
{ {
if (!InOutIsIsP1()) if (!InOutIsIsP1())
{ {
...@@ -556,12 +560,12 @@ namespace OnlineStore.AutoInOutStore ...@@ -556,12 +560,12 @@ namespace OnlineStore.AutoInOutStore
string portName = txtAxisDeviceName.Text; string portName = txtAxisDeviceName.Text;
short SlvAddr = FormUtil.GetShortValue(txtAxisValue); short SlvAddr = FormUtil.GetShortValue(txtAxisValue);
int speed = FormUtil.GetIntValue(txtASpeed); int speed = FormUtil.GetIntValue(txtASpeed);
if (portName.Equals(store.Config.InOut_Axis.DeviceName) && (store.InOutAxisCanMove().Equals(false))) if (store.Config.InOut_Axis.IsSameAxis(portName, SlvAddr) && (store.InOutAxisCanMove().Equals(false)))
{ {
MessageBox.Show("定位气缸不在下降端,不能移动进出轴", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); MessageBox.Show("定位气缸不在下降端,不能移动进出轴", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return; return;
} }
else if (portName.Equals(store.Config.Middle_Axis.DeviceName) || portName.Equals(store.Config.UpDown_Axis.DeviceName)) else if (store.Config.Middle_Axis.IsSameAxis(portName, SlvAddr) || store.Config.UpDown_Axis.IsSameAxis(portName, SlvAddr))
{ {
if (!InOutIsIsP1()) if (!InOutIsIsP1())
{ {
...@@ -587,12 +591,12 @@ namespace OnlineStore.AutoInOutStore ...@@ -587,12 +591,12 @@ namespace OnlineStore.AutoInOutStore
// return; // return;
//} //}
if (portName.Equals(store.Config.InOut_Axis.DeviceName) && (store.InOutAxisCanMove().Equals(false))) if (store.Config.InOut_Axis.IsSameAxis(portName, SlvAddr) && (store.InOutAxisCanMove().Equals(false)))
{ {
MessageBox.Show("定位气缸不在下降端,不能移动进出轴", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); MessageBox.Show("定位气缸不在下降端,不能移动进出轴", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return; return;
} }
else if (portName.Equals(store.Config.Middle_Axis.DeviceName) || portName.Equals(store.Config.UpDown_Axis.DeviceName)) else if (store.Config.Middle_Axis.IsSameAxis(portName, SlvAddr) || store.Config.UpDown_Axis.IsSameAxis(portName, SlvAddr))
{ {
if (!InOutIsIsP1()) if (!InOutIsIsP1())
{ {
...@@ -1125,7 +1129,7 @@ namespace OnlineStore.AutoInOutStore ...@@ -1125,7 +1129,7 @@ namespace OnlineStore.AutoInOutStore
{ {
msg = ""; msg = "";
string deviceName = moveAxis.DeviceName; string deviceName = moveAxis.DeviceName;
short axisNo = moveAxis.GetAxisValue(); int axisNo = moveAxis.GetAxisValue();
bool isend = ACServerManager.GetBusyStatus(deviceName, axisNo).Equals(0); bool isend = ACServerManager.GetBusyStatus(deviceName, axisNo).Equals(0);
int outCount = ACServerManager.GetActualtPosition(deviceName, axisNo); int outCount = ACServerManager.GetActualtPosition(deviceName, axisNo);
...@@ -1207,12 +1211,12 @@ namespace OnlineStore.AutoInOutStore ...@@ -1207,12 +1211,12 @@ namespace OnlineStore.AutoInOutStore
{ {
string portName = txtAxisDeviceName.Text; string portName = txtAxisDeviceName.Text;
short SlvAddr = FormUtil.GetShortValue(txtAxisValue); short SlvAddr = FormUtil.GetShortValue(txtAxisValue);
if (portName.Equals(store.Config.InOut_Axis.DeviceName) && (store.InOutAxisCanMove().Equals(false))) if (store.Config.InOut_Axis.IsSameAxis(portName, SlvAddr) && (store.InOutAxisCanMove().Equals(false)))
{ {
MessageBox.Show("定位气缸不在下降端,不能移动进出轴", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); MessageBox.Show("定位气缸不在下降端,不能移动进出轴", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return; return;
} }
else if (portName.Equals(store.Config.Middle_Axis.DeviceName) || portName.Equals(store.Config.UpDown_Axis.DeviceName)) else if (store.Config.Middle_Axis.IsSameAxis(portName, SlvAddr) || store.Config.UpDown_Axis.IsSameAxis(portName, SlvAddr))
{ {
if (!InOutIsIsP1()) if (!InOutIsIsP1())
{ {
......
...@@ -82,5 +82,9 @@ namespace OnlineStore.Common ...@@ -82,5 +82,9 @@ namespace OnlineStore.Common
public static string DebugPosId = "DebugPosId"; public static string DebugPosId = "DebugPosId";
public static string HasDisableDoorControl = "HasDisableDoorControl"; public static string HasDisableDoorControl = "HasDisableDoorControl";
/// <summary>
/// 伺服波特率,默认9600
/// </summary>
public static string ACBaudRate = "ACBaudRate";
} }
} }
...@@ -19,13 +19,14 @@ namespace OnlineStore.DeviceLibrary ...@@ -19,13 +19,14 @@ namespace OnlineStore.DeviceLibrary
private static Dictionary<string, Dictionary<string, int>> ComAddrValue = new Dictionary<string, Dictionary<string, int>>(); private static Dictionary<string, Dictionary<string, int>> ComAddrValue = new Dictionary<string, Dictionary<string, int>>();
private static string mapObj = ""; private static string mapObj = "";
private static int GetAddrValue(string portName, string addr) private static int GetAddrValue(string portName, int slvAddr, string addr)
{ {
int value = -1; int value = -1;
try try
{ {
string name = portName + "_" + slvAddr;
Dictionary<string, int> map = null; Dictionary<string, int> map = null;
ComAddrValue.TryGetValue(portName, out map); ComAddrValue.TryGetValue(name, out map);
if (map == null) if (map == null)
{ {
return -1; return -1;
...@@ -41,27 +42,28 @@ namespace OnlineStore.DeviceLibrary ...@@ -41,27 +42,28 @@ namespace OnlineStore.DeviceLibrary
} }
return value; return value;
} }
private static void UpdateAddrValue(string portName, string addr, int value) private static void UpdateAddrValue(string portName, int slvAddr, string addr, int value)
{ {
try try
{ {
lock (mapObj) lock (mapObj)
{ {
string name = portName + "_" + slvAddr;
Dictionary<string, int> map = null; Dictionary<string, int> map = null;
ComAddrValue.TryGetValue(portName, out map); ComAddrValue.TryGetValue(name, out map);
if (map == null) if (map == null)
{ {
map = new Dictionary<string, int>(); map = new Dictionary<string, int>();
ComAddrValue.Add(portName, map); ComAddrValue.Add(name, map);
} }
if (map.ContainsKey(addr)) if (map.ContainsKey(addr))
{ {
ComAddrValue[portName][addr] = value; ComAddrValue[name][addr] = value;
} }
else else
{ {
ComAddrValue[portName].Add(addr, value); ComAddrValue[name].Add(addr, value);
} }
} }
} }
...@@ -75,16 +77,21 @@ namespace OnlineStore.DeviceLibrary ...@@ -75,16 +77,21 @@ namespace OnlineStore.DeviceLibrary
{ {
if (serialBeanMap.ContainsKey(portName)) if (serialBeanMap.ContainsKey(portName))
{ {
return true ; return true;
}
int ACBaudRate = ConfigAppSettings.GetIntValue(Setting_Init.ACBaudRate);
if (ACBaudRate <= 0)
{
ACBaudRate = 9600;
} }
AcSerialBean bean = new AcSerialBean(portName, 9600, Parity.Even, 8, StopBits.One); AcSerialBean bean = new AcSerialBean(portName, ACBaudRate, Parity.Even, 8, StopBits.One);
bool result = bean.openPort(); bool result = bean.openPort();
if (!result) if (!result)
{ {
LogUtil.info("打开串口【" + portName + "】失败"); LogUtil.info("打开串口【" + portName + "】【" + ACBaudRate + "】失败");
return false; return false;
} }
LogUtil.info("打开串口【" + portName + "】成功"); LogUtil.info("打开串口【" + portName + "】【" + ACBaudRate + "】成功");
//bean.DataReceived += DataReceived; //bean.DataReceived += DataReceived;
if (serialBeanMap.ContainsKey(portName)) if (serialBeanMap.ContainsKey(portName))
...@@ -203,7 +210,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -203,7 +210,7 @@ namespace OnlineStore.DeviceLibrary
//SendStrAndSleep(portName, slvAddrStr + "06 4638 " + SpeedToStr(homeLowSpeed, 4) + " ffff", sleep); //SendStrAndSleep(portName, slvAddrStr + "06 4638 " + SpeedToStr(homeLowSpeed, 4) + " ffff", sleep);
////原点返回加速度=30 ////原点返回加速度=30
//SendStrAndSleep(portName, slvAddrStr + "06 4639 " + SpeedToStr(homeAddSpeed, 4) + " ffff", sleep); //SendStrAndSleep(portName, slvAddrStr + "06 4639 " + SpeedToStr(homeAddSpeed, 4) + " ffff", sleep);
UpdateEEPROM(portName, slvAddr); //UpdateEEPROM(portName, slvAddr);
} }
public static void UpdateEEPROM(string portName, int slvAddr) public static void UpdateEEPROM(string portName, int slvAddr)
{ {
...@@ -282,13 +289,8 @@ namespace OnlineStore.DeviceLibrary ...@@ -282,13 +289,8 @@ namespace OnlineStore.DeviceLibrary
} }
data = ACCMDManager.buildCheckData(data, data.Length - 2); data = ACCMDManager.buildCheckData(data, data.Length - 2);
SendData(portName, data); SendData(portName, data);
System.Threading.Thread.Sleep(SleepMSendons); System.Threading.Thread.Sleep(SleepMSendons);
//运动 UpdateBlock(portName, slvAddr, ACCMDManager.Block_RelMove);
//data = ACCMDManager.GetWriteData(slvAddr, 06, ACCMDManager.BlockNo, ACCMDManager.Block_RelMove, 2);
//SendData(portName, data);
//Thread.Sleep(SleepMSendons);
UpdateBlock(portName, slvAddr, ACCMDManager.Block_RelMove);
OpenAndCloseSTB(portName, slvAddr); OpenAndCloseSTB(portName, slvAddr);
} }
...@@ -304,11 +306,11 @@ namespace OnlineStore.DeviceLibrary ...@@ -304,11 +306,11 @@ namespace OnlineStore.DeviceLibrary
if (isHomeEnd.Equals(1)) if (isHomeEnd.Equals(1))
{ {
int value = 2000; int value = 2000;
if (portName.Equals(StoreManager.Config.Batch_Axis.DeviceName)) if ( StoreManager.Config.Batch_Axis.IsSameAxis(portName,slvAddr))
{ {
value = 8000; value = 8000;
} }
LogUtil.info("轴【" + portName + "】原点返回时发现原点已亮且回过原点,需要先相对走" + value); LogUtil.info("轴【" + portName +"_"+slvAddr +"】原点返回时发现原点已亮且回过原点,需要先相对走" + value);
RelMove(portName, slvAddr, value); RelMove(portName, slvAddr, value);
bool isStop = false; bool isStop = false;
for (int i = 0; i <= 10; i++) for (int i = 0; i <= 10; i++)
...@@ -317,20 +319,20 @@ namespace OnlineStore.DeviceLibrary ...@@ -317,20 +319,20 @@ namespace OnlineStore.DeviceLibrary
if (GetBusyStatus(portName, slvAddr).Equals(0)) if (GetBusyStatus(portName, slvAddr).Equals(0))
{ {
isStop = true; isStop = true;
LogUtil.info("轴【" + portName + "】 相对走" + value + "已结束"); LogUtil.info("轴【" + portName + "_" + slvAddr + "】 相对走" + value + "已结束");
break; break;
} }
} }
if (!isStop) if (!isStop)
{ {
LogUtil.info("轴【" + portName + "】 相对走" + value + "已等待2分钟,直接停止"); LogUtil.info("轴【" + portName + "_" + slvAddr + "】 相对走" + value + "已等待2分钟,直接停止");
SuddenStop(portName, slvAddr); SuddenStop(portName, slvAddr);
} }
} }
} }
}catch(Exception ex) }catch(Exception ex)
{ {
LogUtil.error("轴【" + portName + "】原点返回前验证是否在原点出错:" + ex.StackTrace); LogUtil.error("轴【" + portName + "_" + slvAddr + "】原点返回前验证是否在原点出错:" + ex.StackTrace);
} }
//默认负方向原点返回 //默认负方向原点返回
UpdateBlock(portName, slvAddr, ACCMDManager.Block_HomeMove1); UpdateBlock(portName, slvAddr, ACCMDManager.Block_HomeMove1);
...@@ -339,34 +341,20 @@ namespace OnlineStore.DeviceLibrary ...@@ -339,34 +341,20 @@ namespace OnlineStore.DeviceLibrary
} }
public static void SetSpeed(string portName, int slvAddr, int speed) public static void SetSpeed(string portName, int slvAddr, int speed)
{ {
int preSpeed = GetAddrValue(portName, ACCMDManager.Speed_Addr); int preSpeed = GetAddrValue(portName,slvAddr, ACCMDManager.Speed_Addr);
if ((preSpeed.Equals(-1)) || (!preSpeed.Equals(Math.Abs(speed)))) if ((preSpeed.Equals(-1)) || (!preSpeed.Equals(Math.Abs(speed))))
{ {
string v1 = slvAddr + "064601 " + ACServerManager.SpeedToStr(speed, 4) + " ffff"; string v1 = slvAddr + "064601 " + ACServerManager.SpeedToStr(speed, 4) + " ffff";
LogUtil.debug("轴【" + portName + "】更新速度为【" + speed + "】,发送数据【" + v1 + "】"); LogUtil.debug("轴【" + portName + "_" + slvAddr + "】更新速度为【" + speed + "】,发送数据【" + v1 + "】");
SendStrAndSleep(portName, v1, SleepMSendons); SendStrAndSleep(portName, v1, SleepMSendons);
UpdateAddrValue(portName, ACCMDManager.Speed_Addr, Math.Abs(speed)); UpdateAddrValue(portName,slvAddr, ACCMDManager.Speed_Addr, Math.Abs(speed));
//byte[] data = ACCMDManager.GetWriteData(slvAddr, ACCMDManager.CMD_WriteRegisters, "4601", string.Format("{0:X2}", Math.Abs(speed)), 2);
//string msg = AcSerialBean.byteToHexStr(data, " ");
//SendData(portName, data);
//UpdateAddrValue(portName, ACCMDManager.Speed_Addr, Math.Abs(speed));
Thread.Sleep(SleepMSendons); Thread.Sleep(SleepMSendons);
} }
} }
public static void SpeedMove(string portName, int slvAddr, int speed) public static void SpeedMove(string portName, int slvAddr, int speed)
{ {
SetSpeed(portName, slvAddr, speed); SetSpeed(portName, slvAddr, speed);
//int preSpeed = GetAddrValue(portName, ACCMDManager.Speed_Addr);
//if ((preSpeed.Equals(-1)) || (!preSpeed.Equals(Math.Abs(speed))))
//{
// byte[] data = ACCMDManager.GetWriteData(slvAddr, ACCMDManager.CMD_WriteRegisters, "4601", string.Format("{0:X2}", Math.Abs(speed)), 2);
// string msg = AcSerialBean.byteToHexStr(data," ");
// LogUtil.info("轴【"+portName+"】更新速度为【"+speed+"】,发送数据【"+msg+"】");
// SendData(portName, data);
// UpdateAddrValue(portName, ACCMDManager.Speed_Addr, Math.Abs(speed));
// Thread.Sleep(SleepMSendons);
//}
if (speed > 0) if (speed > 0)
{ {
UpdateBlock(portName, slvAddr, ACCMDManager.Block_VolMove0); UpdateBlock(portName, slvAddr, ACCMDManager.Block_VolMove0);
...@@ -383,13 +371,13 @@ namespace OnlineStore.DeviceLibrary ...@@ -383,13 +371,13 @@ namespace OnlineStore.DeviceLibrary
//先更新速度 //先更新速度
string slvAddrStr = string.Format(strFromat, slvAddr); string slvAddrStr = string.Format(strFromat, slvAddr);
int preSpeed = GetAddrValue(portName, ACCMDManager.Speed_Addr); int preSpeed = GetAddrValue(portName,slvAddr, ACCMDManager.Speed_Addr);
if ((preSpeed.Equals(-1)) || (!preSpeed.Equals(targetSpeed))) if ((preSpeed.Equals(-1)) || (!preSpeed.Equals(targetSpeed)))
{ {
//速度 V1 =100 //速度 V1 =100
string v1 = slvAddrStr + "064601 " + SpeedToStr(targetSpeed, 4) + " ffff"; string v1 = slvAddrStr + "064601 " + SpeedToStr(targetSpeed, 4) + " ffff";
SendStrAndSleep(portName, v1, SleepMSendons); SendStrAndSleep(portName, v1, SleepMSendons);
UpdateAddrValue(portName, ACCMDManager.Speed_Addr, targetSpeed); UpdateAddrValue(portName,slvAddr, ACCMDManager.Speed_Addr, targetSpeed);
} }
//绝对运动 //绝对运动
AbsMove(portName, slvAddr, targetPosition); AbsMove(portName, slvAddr, targetPosition);
......
...@@ -27,18 +27,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -27,18 +27,7 @@ namespace OnlineStore.DeviceLibrary
} }
return null; return null;
} }
//public static void RunBlock(string portName, int slvAddr, int index)
//{
// //运动
// byte[] data = ACCMDManager.GetWriteData(slvAddr, ACCMDManager.CMD_WriteRegisters, ACCMDManager.BlockNo, index.ToString(), 2);
// SendData(portName, data);
// Thread.Sleep(100);
// CloseSTB(portName, slvAddr);
// Thread.Sleep(100);
// OnlyOpenSTB(portName, slvAddr);
//}
public static void SendStrAndSleep(string portName, string str, int sleepS) public static void SendStrAndSleep(string portName, string str, int sleepS)
{ {
byte[] data = AcSerialBean.StringToByte(str); byte[] data = AcSerialBean.StringToByte(str);
...@@ -47,112 +36,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -47,112 +36,7 @@ namespace OnlineStore.DeviceLibrary
data = ACCMDManager.buildCheckData(data, data.Length - 2); data = ACCMDManager.buildCheckData(data, data.Length - 2);
SendData(portName, data); SendData(portName, data);
System.Threading.Thread.Sleep(sleepS); System.Threading.Thread.Sleep(sleepS);
} }
public static void SendStr(string portName, string str)
{
byte[] data = AcSerialBean.StringToByte(str);
data[data.Length - 1] = 0x00;
data[data.Length - 2] = 0x00;
data = ACCMDManager.buildCheckData(data, data.Length - 2);
SendData(portName, data);
}
private static void DataReceived(string portName, object sender, SerialDataReceivedEventArgs e, byte[] bits)
{
string strSend = "";
for (int i = 0; i < bits.Length; i++)
{
strSend += string.Format("{0:X2} ", bits[i]);
}
if (IsShowMsg)
{
LogUtil.info( "串口" + portName + " 收到数据:" + strSend + "");
}
string str = "";
string strFromat = "{0:X2}";
byte slvAddr = bits[0];
int lenth = bits[2];
byte cmd = bits[1];
if (cmd.Equals(ACCMDManager.CMD_ReadRegisters) && bits.Length > 6)
{
if (PreReadAddr.Equals(ACCMDManager.TargetPostion))
{
if (lenth == 4)
{
str = string.Format(strFromat, bits[5]) + string.Format(strFromat, bits[6]) + string.Format(strFromat, bits[3]) + string.Format(strFromat, bits[4]);
int value = Convert.ToInt32(str.Trim().Replace(" ", ""), 16);
SaveData(portName, slvAddr, ACCMDManager.TargetPostion, value);
}
}
else if (PreReadAddr.Equals(ACCMDManager.ActualPosition))
{
if (lenth == 4)
{
str = string.Format(strFromat, bits[5]) + string.Format(strFromat, bits[6]) + string.Format(strFromat, bits[3]) + string.Format(strFromat, bits[4]);
int value = Convert.ToInt32(str.Trim().Replace(" ", ""), 16);
SaveData(portName, slvAddr, ACCMDManager.ActualPosition, value);
}
}
else
{
for (int i = 3; i < 3 + lenth; i++)
{
str += string.Format("{0:X2} ", bits[i]);
}
str = str.Replace(" ", "");
int value = Convert.ToInt32(str, 16);
LogUtil.info("转换后结果:" + value + "");
//this.richTextBox1.AppendText("转换后结果:" + value + "");
//Console.WriteLine("转换后结果:" + value);
}
//MessageBox.Show("收到数据:"+value);
}
else if (cmd.Equals(ACCMDManager.CMD_ReadCoil) && bits.Length >= 6)
{
if (PreReadCoilAddr.Equals(ACCMDManager.ServerOn_Addr))
{
if (lenth == 1)
{
str = string.Format(strFromat, bits[3]);
int value = Convert.ToInt32(str.Trim().Replace(" ", ""), 16);
SaveData(portName, slvAddr, ACCMDManager.ServerOn_Addr, value);
}
}
else
if (PreReadCoilAddr.Equals(ACCMDManager.Alarm_Status))
{
if (lenth == 1)
{
str = string.Format(strFromat, bits[3]);
int value = Convert.ToInt32(str.Trim().Replace(" ", ""), 16);
SaveData(portName, slvAddr, ACCMDManager.Alarm_Status, value);
}
}
else if (PreReadCoilAddr.Equals(ACCMDManager.BUSYStatus))
{
if (lenth == 1)
{
str = string.Format(strFromat, bits[3]);
int value = Convert.ToInt32(str.Trim().Replace(" ", ""), 16);
SaveData(portName, slvAddr, ACCMDManager.BUSYStatus, value);
}
}
else if (PreReadCoilAddr.Equals(ACCMDManager.HOME_CMP_Status))
{
if (lenth == 1)
{
str = string.Format(strFromat, bits[3]);
int value = Convert.ToInt32(str.Trim().Replace(" ", ""), 16);
SaveData(portName, slvAddr, ACCMDManager.HOME_CMP_Status, value);
}
}
}
if (strSend.Equals(""))
{
return;
}
}
public static void SaveData(string portName, byte slvAddr, string regAddr, int value) public static void SaveData(string portName, byte slvAddr, string regAddr, int value)
{ {
...@@ -265,6 +149,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -265,6 +149,7 @@ namespace OnlineStore.DeviceLibrary
else else
{ {
bean.SendCommand(data, ref returnData, outTime, reviceLength); bean.SendCommand(data, ref returnData, outTime, reviceLength);
System.Threading.Thread.Sleep(2);
} }
} }
catch (Exception ex) catch (Exception ex)
...@@ -320,14 +205,14 @@ namespace OnlineStore.DeviceLibrary ...@@ -320,14 +205,14 @@ namespace OnlineStore.DeviceLibrary
data = "0000"; data = "0000";
dataArray = ACCMDManager.GetWriteData(slvAddr, ACCMDManager.CMD_WriteCoil, addr, data, length); dataArray = ACCMDManager.GetWriteData(slvAddr, ACCMDManager.CMD_WriteCoil, addr, data, length);
SendData(portName, dataArray); SendData(portName, dataArray);
} }
public static void OpenAndCloseSTB(string portName, int slvAddr) public static void OpenAndCloseSTB(string portName, int slvAddr)
{ {
OnlyOpenSTB(portName, slvAddr); OnlyOpenSTB(portName, slvAddr);
System.Threading.Thread.Sleep(100); System.Threading.Thread.Sleep(100);
CloseSTB(portName, slvAddr); CloseSTB(portName, slvAddr);
System.Threading.Thread.Sleep(100);
} }
public static void OnlyOpenSTB(string portName, int slvAddr) public static void OnlyOpenSTB(string portName, int slvAddr)
...@@ -349,13 +234,13 @@ namespace OnlineStore.DeviceLibrary ...@@ -349,13 +234,13 @@ namespace OnlineStore.DeviceLibrary
public static void UpdateBlock(string portName, int slvAddr, string blockNum) public static void UpdateBlock(string portName, int slvAddr, string blockNum)
{ {
int preNum = GetAddrValue(portName, ACCMDManager.BlockNo); int preNum = GetAddrValue(portName,slvAddr, ACCMDManager.BlockNo);
if (preNum.Equals(-1) || (!preNum.ToString().Equals(blockNum))) if (preNum.Equals(-1) || (!preNum.ToString().Equals(blockNum)))
{ {
byte[] data = ACCMDManager.GetWriteData(slvAddr, ACCMDManager.CMD_WriteRegisters, ACCMDManager.BlockNo, blockNum , 2); byte[] data = ACCMDManager.GetWriteData(slvAddr, ACCMDManager.CMD_WriteRegisters, ACCMDManager.BlockNo, blockNum , 2);
SendData(portName, data); SendData(portName, data);
int value = Convert.ToInt16(blockNum); int value = Convert.ToInt16(blockNum);
UpdateAddrValue(portName, ACCMDManager.BlockNo, value); UpdateAddrValue(portName,slvAddr, ACCMDManager.BlockNo, value);
Thread.Sleep(SleepMSendons); Thread.Sleep(SleepMSendons);
} }
} }
......
...@@ -171,10 +171,10 @@ namespace OnlineStore.DeviceLibrary ...@@ -171,10 +171,10 @@ namespace OnlineStore.DeviceLibrary
moveAxisList.Add(Config.InOut_Axis); moveAxisList.Add(Config.InOut_Axis);
moveAxisList.Add(Config.Batch_Axis); moveAxisList.Add(Config.Batch_Axis);
this.AxisAlarmCodeMap = new Dictionary<string, AxisAlarmInfo>(); this.AxisAlarmCodeMap = new Dictionary<string, AxisAlarmInfo>();
this.AxisAlarmCodeMap.Add(Config.UpDown_Axis.DeviceName, new AxisAlarmInfo()); this.AxisAlarmCodeMap.Add(Config.UpDown_Axis.GetNameStr(), new AxisAlarmInfo());
this.AxisAlarmCodeMap.Add(Config.InOut_Axis.DeviceName, new AxisAlarmInfo()); this.AxisAlarmCodeMap.Add(Config.InOut_Axis.GetNameStr(), new AxisAlarmInfo());
this.AxisAlarmCodeMap.Add(this.Config.Middle_Axis.DeviceName, new AxisAlarmInfo()); this.AxisAlarmCodeMap.Add(this.Config.Middle_Axis.GetNameStr(), new AxisAlarmInfo());
this.AxisAlarmCodeMap.Add(this.Config.Batch_Axis.DeviceName, new AxisAlarmInfo()); this.AxisAlarmCodeMap.Add(this.Config.Batch_Axis.GetNameStr(), new AxisAlarmInfo());
} }
/// <summary> /// <summary>
...@@ -599,7 +599,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -599,7 +599,7 @@ namespace OnlineStore.DeviceLibrary
foreach (ConfigMoveAxis moveAxis in moveAxisList) foreach (ConfigMoveAxis moveAxis in moveAxisList)
{ {
string portName = moveAxis.DeviceName; string portName = moveAxis.DeviceName;
short slvAddr = moveAxis.GetAxisValue(); int slvAddr = moveAxis.GetAxisValue();
ACServerManager.OpenPort(portName); ACServerManager.OpenPort(portName);
Thread.Sleep(50); Thread.Sleep(50);
//初始化串口 //初始化串口
...@@ -1170,15 +1170,15 @@ namespace OnlineStore.DeviceLibrary ...@@ -1170,15 +1170,15 @@ namespace OnlineStore.DeviceLibrary
// { // {
foreach (ConfigMoveAxis axisInfo in moveAxisList) foreach (ConfigMoveAxis axisInfo in moveAxisList)
{ {
short axis = axisInfo.GetAxisValue(); int axis = axisInfo.GetAxisValue();
string deviceName = axisInfo.DeviceName; string deviceName = axisInfo.DeviceName;
AxisAlarmInfo info = AxisAlarmCodeMap[deviceName]; AxisAlarmInfo info = AxisAlarmCodeMap[axisInfo.GetNameStr()];
int alarmIo = ACServerManager.GetAlarmStatus(deviceName, axis); int alarmIo = ACServerManager.GetAlarmStatus(deviceName, axis);
if (alarmIo == 1) if (alarmIo == 1)
{ {
if (axisInfo.DeviceName.Equals(Config.Batch_Axis.DeviceName)) if (Config.Batch_Axis.IsSameAxis(axisInfo.DeviceName,axisInfo.GetAxisValue()) )
{ {
AutomaticBaiting.WarnMsg = " 运动轴" + axisInfo.Explain + "报警"; AutomaticBaiting.WarnMsg = " 运动轴" + axisInfo.Explain + "报警";
info.AlarmIoValue = alarmIo; info.AlarmIoValue = alarmIo;
...@@ -1201,7 +1201,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -1201,7 +1201,7 @@ namespace OnlineStore.DeviceLibrary
info.AlarmIoValue = alarmIo; info.AlarmIoValue = alarmIo;
} }
} }
AxisAlarmCodeMap[deviceName] = info; AxisAlarmCodeMap[axisInfo.GetNameStr()] = info;
} }
//}); //});
//判断报警状态 //判断报警状态
......
...@@ -140,7 +140,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -140,7 +140,7 @@ namespace OnlineStore.DeviceLibrary
wait.IsEnd = ACAxisMoveIsEnd(wait.AxisInfo, wait.TargetPosition, wait.TargetSpeed, out msg); wait.IsEnd = ACAxisMoveIsEnd(wait.AxisInfo, wait.TargetPosition, wait.TargetSpeed, out msg);
} }
if (!wait.IsEnd && (wait.AxisInfo.DeviceName.Equals(Config.Batch_Axis.DeviceName)) && wait.TargetPosition.Equals(Config.BatchAxis_P1)) if (!wait.IsEnd && (Config.Batch_Axis.IsSameAxis(wait.AxisInfo.DeviceName,wait.AxisInfo.GetAxisValue())) && wait.TargetPosition.Equals(Config.BatchAxis_P1))
{ {
wait.IsEnd = AutomaticBaiting.BatchAxisIsEnd(wait); wait.IsEnd = AutomaticBaiting.BatchAxisIsEnd(wait);
} }
......
...@@ -367,7 +367,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -367,7 +367,7 @@ namespace OnlineStore.DeviceLibrary
{ {
msg = ""; msg = "";
string deviceName = moveAxis.DeviceName; string deviceName = moveAxis.DeviceName;
short axisNo = moveAxis.GetAxisValue(); int axisNo = moveAxis.GetAxisValue();
bool isOk = ACServerManager.GetBusyStatus(deviceName, axisNo).Equals(0); bool isOk = ACServerManager.GetBusyStatus(deviceName, axisNo).Equals(0);
int outCount = ACServerManager.GetActualtPosition(deviceName, axisNo); int outCount = ACServerManager.GetActualtPosition(deviceName, axisNo);
......
...@@ -128,7 +128,18 @@ namespace OnlineStore.LoadCSVLibrary ...@@ -128,7 +128,18 @@ namespace OnlineStore.LoadCSVLibrary
/// 最大位置 /// 最大位置
/// </summary> /// </summary>
public int PositionMax { get; set; } public int PositionMax { get; set; }
public bool IsSameAxis(string portName, int slv)
{
if (DeviceName.Equals(portName) && slv.Equals(GetAxisValue()))
{
return true;
}
return false;
}
public string GetNameStr()
{
return DeviceName + "_" + GetAxisValue();
}
public bool PositionIsHasLimit(){ public bool PositionIsHasLimit(){
if (PositionMin.Equals(PositionMax)) if (PositionMin.Equals(PositionMax))
{ {
...@@ -154,10 +165,9 @@ namespace OnlineStore.LoadCSVLibrary ...@@ -154,10 +165,9 @@ namespace OnlineStore.LoadCSVLibrary
/// <summary> /// <summary>
/// 使用康泰克板卡表示轴编号,使用Ac伺服电机表示伺服地址 /// 使用康泰克板卡表示轴编号,使用Ac伺服电机表示伺服地址
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
/// private int axisValue = -1;
private short axisValue = -1; public int GetAxisValue()
public short GetAxisValue()
{ {
if (ProVale.Equals("") || ProVale.Equals("-1")) if (ProVale.Equals("") || ProVale.Equals("-1"))
{ {
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!