1
This commit is contained in:
parent
9798c01b1f
commit
b558baced5
@ -57,6 +57,7 @@ namespace DAL
|
||||
input.ToRunControlCard = (bool)row["ToRunControlCard"];
|
||||
input.HightEff = (bool)row["HightEff"];
|
||||
input.MyType = (int)row["MyType"];
|
||||
input.EmptySignal = (bool)row["EmptySignal"];
|
||||
list.Add(input);
|
||||
}
|
||||
return list;
|
||||
@ -99,6 +100,7 @@ namespace DAL
|
||||
Output.OutputMeaning = (string)row["OutputMeaning"];
|
||||
Output.ToRunControlCard = (bool)row["ToRunControlCard"];
|
||||
Output.MyType = Convert.ToInt32(row["MyType"]);
|
||||
Output.EmptySignal = (bool)row["EmptySignal"];
|
||||
list.Add(Output);
|
||||
}
|
||||
return list;
|
||||
@ -133,7 +135,7 @@ namespace DAL
|
||||
c = new ZmotionCard();
|
||||
break;
|
||||
default:
|
||||
c = new LeiSaiCard();
|
||||
c = new LeiSaiMBCard();
|
||||
break;
|
||||
|
||||
}
|
||||
@ -1323,8 +1325,6 @@ namespace DAL
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region 串口相关
|
||||
|
||||
Binary file not shown.
@ -63,98 +63,149 @@ namespace Model
|
||||
}
|
||||
set
|
||||
{
|
||||
//levelState = value;
|
||||
//if (ToRunControlCard)
|
||||
//{
|
||||
// if (MyCard == null)
|
||||
// {
|
||||
// this.InputColor = ColorStr.Gray;
|
||||
// return;
|
||||
// }
|
||||
// switch (MyCard.Brand)
|
||||
// {
|
||||
// case 1:
|
||||
// if (HightEff)
|
||||
// {
|
||||
// if (value == 0)
|
||||
// {
|
||||
// this.InputColor = ColorStr.Gray;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// this.InputColor = ColorStr.Green;
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (value == 1)
|
||||
// {
|
||||
// this.InputColor = ColorStr.Gray;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// this.InputColor = ColorStr.Green;
|
||||
// }
|
||||
// }
|
||||
// break;
|
||||
// case 2:
|
||||
// if (HightEff)
|
||||
// {
|
||||
// if (value == 0)
|
||||
// {
|
||||
// this.InputColor = ColorStr.Green;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// this.InputColor = ColorStr.Gray;
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (value == 1)
|
||||
// {
|
||||
// this.InputColor = ColorStr.Green;
|
||||
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// this.InputColor = ColorStr.Gray;
|
||||
// }
|
||||
// }
|
||||
// break;
|
||||
|
||||
// }
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// if (HightEff)
|
||||
// {
|
||||
// if (value == 0)
|
||||
// {
|
||||
// this.InputColor = ColorStr.Gray;
|
||||
// }
|
||||
// else if (value >= 0)
|
||||
// {
|
||||
// this.InputColor = ColorStr.Green;
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (value == 1)
|
||||
// {
|
||||
// this.InputColor = ColorStr.Gray;
|
||||
// }
|
||||
// else if (value >= 0)
|
||||
// {
|
||||
// this.InputColor = ColorStr.Green;
|
||||
// }else
|
||||
// {
|
||||
// this.InputColor = ColorStr.Red;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
levelState = value;
|
||||
if (ToRunControlCard)
|
||||
{
|
||||
if (MyCard == null)
|
||||
{
|
||||
this.InputColor = ColorStr.Gray;
|
||||
return;
|
||||
}
|
||||
switch (MyCard.Brand)
|
||||
{
|
||||
case 1:
|
||||
if (HightEff)
|
||||
{
|
||||
if (value == 0)
|
||||
{
|
||||
this.InputColor = ColorStr.Gray;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.InputColor = ColorStr.Green;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (value == 1)
|
||||
{
|
||||
this.InputColor = ColorStr.Gray;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.InputColor = ColorStr.Green;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (HightEff)
|
||||
{
|
||||
if (value == 0)
|
||||
{
|
||||
this.InputColor = ColorStr.Green;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.InputColor = ColorStr.Gray;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (value == 1)
|
||||
{
|
||||
this.InputColor = ColorStr.Green;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
this.InputColor = ColorStr.Gray;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
if (g_handle == (IntPtr)0)
|
||||
{
|
||||
if (HightEff)
|
||||
{
|
||||
if (value == 0)
|
||||
if (value == 1)
|
||||
{
|
||||
this.InputColor = ColorStr.Gray;
|
||||
}
|
||||
else if (value >= 0)
|
||||
else
|
||||
{
|
||||
this.InputColor = ColorStr.Green;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (value == 1)
|
||||
if (value == 0)
|
||||
{
|
||||
this.InputColor = ColorStr.Gray;
|
||||
}
|
||||
else if (value >= 0)
|
||||
else
|
||||
{
|
||||
this.InputColor = ColorStr.Green;
|
||||
}else
|
||||
{
|
||||
this.InputColor = ColorStr.Red;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (HightEff)
|
||||
{
|
||||
if (value == 1)
|
||||
{
|
||||
this.InputColor = ColorStr.Green;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.InputColor = ColorStr.Gray;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (value == 0)
|
||||
{
|
||||
this.InputColor = ColorStr.Green;
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
this.InputColor = ColorStr.Gray;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -168,6 +219,11 @@ namespace Model
|
||||
/// </summary>
|
||||
public bool ToRunControlCard { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 空信号
|
||||
/// </summary>
|
||||
public bool EmptySignal { get; set; }
|
||||
|
||||
private string inputColor;
|
||||
/// <summary>
|
||||
/// 表示显色
|
||||
@ -213,46 +269,49 @@ namespace Model
|
||||
//LevelState = LTSMC.smc_read_inbit(CardID, IoNumber);
|
||||
|
||||
|
||||
if (MyCard != null)
|
||||
//if (MyCard != null)
|
||||
//{
|
||||
// //确认运动控制的品牌
|
||||
// switch (MyCard.Brand)
|
||||
// {
|
||||
// case 1:
|
||||
// //根据品牌的不同,选择相应的状态获取方式
|
||||
// if (MyCard.InterfaceType == 2)
|
||||
// {
|
||||
// LevelState = LTSMC.smc_read_inbit(MyCard.CardID, IoNumber);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// LevelState = LTSMC.smc_read_inbit(MyCard.CardID, IoNumber);
|
||||
// }
|
||||
|
||||
// break;
|
||||
// case 2:
|
||||
// if (MyCard.InterfaceType == 2)
|
||||
// {
|
||||
// uint state = 0;
|
||||
// zmcaux.ZAux_Direct_GetIn(MyCard.g_handle, IoNumber, ref state);
|
||||
// LevelState = Convert.ToInt32(state);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// int state = 100;
|
||||
// ADTMC.adt_read_inbit(MyCard.CardID, IoNumber, out state);
|
||||
// LevelState = state;
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
//}
|
||||
|
||||
if (MS_MB_API.Connect())
|
||||
{
|
||||
//确认运动控制的品牌
|
||||
switch (MyCard.Brand)
|
||||
{
|
||||
case 1:
|
||||
//根据品牌的不同,选择相应的状态获取方式
|
||||
if (MyCard.InterfaceType == 2)
|
||||
{
|
||||
LevelState = LTSMC.smc_read_inbit(MyCard.CardID, IoNumber);
|
||||
}
|
||||
else
|
||||
{
|
||||
LevelState = LTDMC.dmc_read_inbit(MyCard.CardID, IoNumber);
|
||||
}
|
||||
|
||||
break;
|
||||
case 2:
|
||||
if (MyCard.InterfaceType == 2)
|
||||
{
|
||||
uint state = 0;
|
||||
zmcaux.ZAux_Direct_GetIn(MyCard.g_handle, IoNumber, ref state);
|
||||
LevelState = Convert.ToInt32(state);
|
||||
}
|
||||
else if (MyCard.InterfaceType == 0)
|
||||
{
|
||||
LevelState = adt8949.adt8949_read_bit(MyCard.CardID, IoNumber);
|
||||
}
|
||||
else
|
||||
{
|
||||
int state = 100;
|
||||
ADTMC.adt_read_inbit(MyCard.CardID, IoNumber, out state);
|
||||
LevelState = state;
|
||||
}
|
||||
break;
|
||||
}
|
||||
LevelState = MS_MB_API.Inputs[IoNumber];
|
||||
}
|
||||
else
|
||||
{
|
||||
LevelState = 0;
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -263,5 +322,25 @@ namespace Model
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将八进制整数转换为十进制整数
|
||||
/// </summary>
|
||||
/// <param name="octal">八进制整数</param>
|
||||
/// <returns>十进制整数</returns>
|
||||
public int OctalToDecimal(int octal)
|
||||
{
|
||||
int decimalValue = 0;
|
||||
int baseValue = 1;
|
||||
int temp = octal;
|
||||
while (temp > 0)
|
||||
{
|
||||
int lastDigit = temp % 10;
|
||||
decimalValue += lastDigit * baseValue;
|
||||
baseValue *= 8;
|
||||
temp /= 10;
|
||||
}
|
||||
return decimalValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
340
Model/MS_MB_API.cs
Normal file
340
Model/MS_MB_API.cs
Normal file
@ -0,0 +1,340 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
|
||||
namespace Model
|
||||
{
|
||||
public class MS_MB_API
|
||||
{
|
||||
static string IP = "192.168.0.8";
|
||||
static bool s_link;
|
||||
static int c_id = 0;
|
||||
static Comm_Config config = new Comm_Config();
|
||||
static byte[] bit_In = new byte[64];
|
||||
static byte[] bit_Out = new byte[64];
|
||||
static byte[] zero = new byte[64];
|
||||
|
||||
public static byte[] Inputs = new byte[64];
|
||||
public static byte[] Outputs = new byte[64];
|
||||
|
||||
|
||||
static Thread IO;
|
||||
static MS_MB_API()
|
||||
{
|
||||
IO = new Thread(IOUpdate);
|
||||
IO.IsBackground = true;
|
||||
IO.Start();
|
||||
|
||||
}
|
||||
|
||||
public static void IOUpdate()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
Thread.Sleep(10);
|
||||
|
||||
if (Connect())
|
||||
{
|
||||
var errorCode = MS_ReadBits_X(c_id, 0, 64, ref bit_In[0]);
|
||||
if (errorCode != MS_MB_ERR_NONE)
|
||||
{
|
||||
s_link = false;
|
||||
return;
|
||||
}
|
||||
Inputs = bit_In;
|
||||
bit_Out = Outputs;
|
||||
errorCode = MS_WriteBits_Y(c_id, 0, 64, bit_Out);
|
||||
if (errorCode != MS_MB_ERR_NONE)
|
||||
{
|
||||
s_link = false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Inputs = zero;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static bool Connect()
|
||||
{
|
||||
|
||||
if (s_link == false)
|
||||
{
|
||||
|
||||
config.enet.ip = IP;
|
||||
config.enet.port = 502;
|
||||
config.type = COMM_TYPE_ENET;
|
||||
|
||||
|
||||
if (MS_OpenComm(config, ref c_id) == MS_MB_ERR_NONE)
|
||||
{
|
||||
MS_CommSetSlave(c_id, 1);
|
||||
s_link = true;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return s_link;
|
||||
}
|
||||
public bool Connect(string ip)
|
||||
{
|
||||
IP = ip;
|
||||
return Connect();
|
||||
|
||||
}
|
||||
|
||||
public MS_MB_API()
|
||||
{
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct MS_AIXS_INFO
|
||||
{
|
||||
public byte motion_state;
|
||||
public byte enable;
|
||||
public byte busy;
|
||||
public byte limit_positive;
|
||||
public byte limit_negative;
|
||||
public byte home_switch;
|
||||
public byte cmd_done;
|
||||
public byte[] reserve;
|
||||
|
||||
public int position;
|
||||
public int velocity;
|
||||
|
||||
public MS_AIXS_INFO(int dummy)
|
||||
{
|
||||
motion_state = 0;
|
||||
enable = 0;
|
||||
busy = 0;
|
||||
limit_positive = 0;
|
||||
limit_negative = 0;
|
||||
home_switch = 0;
|
||||
cmd_done = 0;
|
||||
reserve = new byte[9];
|
||||
position = 0;
|
||||
velocity = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public const byte MotionState_Idle = 0;
|
||||
public const byte MotionState_Moving = 1;
|
||||
public const byte MotionState_Homing = 2;
|
||||
public const byte MotionState_Jogging = 3;
|
||||
|
||||
public const int HomeMode_NegativeLimit = 1; //负限位查询
|
||||
public const int HomeMode_PositiveLimit = 2; //正限位查询
|
||||
public const int HomeMode_PositiveLimitHomeSw = 7; //正限位+零位查询
|
||||
public const int HomeMode_NegativeLimitHomeSw = 11; //负限位+零位查询
|
||||
public const int HomeMode_CurrentPos = 135; //当前位置值零位
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct Serial_Comm
|
||||
{
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
|
||||
public string portName; //填入串口号:"COMxx",xx为串口序号,如:"COM0","COM12","COM23"
|
||||
|
||||
public uint baudrate;
|
||||
public ushort dataBits; //7,8
|
||||
public ushort stopBits; //1,2
|
||||
public ushort parity; //0-N,1-O,2-E
|
||||
public ushort rts; //0-disable,1-enable
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct Enet_Comm
|
||||
{
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
|
||||
public string ip; //填入IP地址,如:"192.168.0.8"
|
||||
|
||||
public ushort port;
|
||||
}
|
||||
|
||||
public const ushort COMM_TYPE_NONE = 0;
|
||||
public const ushort COMM_TYPE_SER = 1;
|
||||
public const ushort COMM_TYPE_ENET = 2;
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct Comm_Config
|
||||
{
|
||||
public ushort type;
|
||||
public ushort timeOut; //ms
|
||||
public int c_id;
|
||||
|
||||
[MarshalAs(UnmanagedType.Struct)]
|
||||
public Serial_Comm serial;
|
||||
|
||||
[MarshalAs(UnmanagedType.Struct)]
|
||||
public Enet_Comm enet;
|
||||
}
|
||||
|
||||
//==== 通信
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_OpenComm", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_OpenComm(Comm_Config config, ref int c_id);
|
||||
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_CommSetSlave", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_CommSetSlave(int c_id, int slave);
|
||||
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_CloseComm", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_CloseComm(int c_id);
|
||||
|
||||
//==== 读位寄存器
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_ReadBits_X", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_ReadBits_X(int c_id, ushort start, ushort num, ref byte pData);
|
||||
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_ReadBits_Y", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_ReadBits_Y(int c_id, ushort start, ushort num, ref byte pData);
|
||||
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_ReadBits_M", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_ReadBits_M(int c_id, ushort start, ushort num, ref byte pData);
|
||||
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_ReadBits_S", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_ReadBits_S(int c_id, ushort start, ushort num, ref byte pData);
|
||||
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_ReadBits_T", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_ReadBits_T(int c_id, ushort start, ushort num, ref byte pData);
|
||||
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_ReadBits_C", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_ReadBits_C(int c_id, ushort start, ushort num, ref byte pData);
|
||||
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_ReadBits_F", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_ReadBits_F(int c_id, ushort start, ushort num, ref byte pData);
|
||||
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_ReadBits_B", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_ReadBits_B(int c_id, ushort start, ushort num, ref byte pData);
|
||||
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_ReadBits_L", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_ReadBits_L(int c_id, ushort start, ushort num, ref byte pData);
|
||||
|
||||
//==== 写位寄存器
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_WriteBits_Y", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_WriteBits_Y(int c_id, ushort start, ushort num, byte[] pData);
|
||||
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_WriteBits_M", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_WriteBits_M(int c_id, ushort start, ushort num, byte[] pData);
|
||||
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_WriteBits_S", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_WriteBits_S(int c_id, ushort start, ushort num, byte[] pData);
|
||||
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_WriteBits_F", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_WriteBits_F(int c_id, ushort start, ushort num, byte[] pData);
|
||||
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_WriteBits_B", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_WriteBits_B(int c_id, ushort start, ushort num, byte[] pData);
|
||||
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_WriteBits_L", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_WriteBits_L(int c_id, ushort start, ushort num, byte[] pData);
|
||||
|
||||
//==== 读字寄存器
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_ReadWord_D", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_ReadWord_D(int c_id, ushort start, ushort num, ref ushort pData);
|
||||
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_ReadWord_R", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_ReadWord_R(int c_id, ushort start, ushort num, ref ushort pData);
|
||||
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_ReadWord_VD", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_ReadWord_VD(int c_id, ushort start, ushort num, ref ushort pData);
|
||||
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_ReadWord_RD", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_ReadWord_RD(int c_id, ushort start, ushort num, ref ushort pData);
|
||||
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_ReadWord_T", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_ReadWord_T(int c_id, ushort start, ushort num, ref ushort pData);
|
||||
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_ReadWord_C16", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_ReadWord_C16(int c_id, ushort start, ushort num, ref ushort pData);
|
||||
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_ReadWord_C32", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_ReadWord_C32(int c_id, ushort start, ushort num, ref uint pData);
|
||||
|
||||
//==== 写字寄存器
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_WriteWord_D", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_WriteWord_D(int c_id, ushort start, ushort num, ushort[] pData);
|
||||
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_WriteWord_R", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_WriteWord_R(int c_id, ushort start, ushort num, ushort[] pData);
|
||||
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_WriteWord_VD", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_WriteWord_VD(int c_id, ushort start, ushort num, ushort[] pData);
|
||||
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_WriteWord_RD", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_WriteWord_RD(int c_id, ushort start, ushort num, ushort[] pData);
|
||||
|
||||
//==== 运动控制轴获取
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_MotionGetAxisCount", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_MotionGetAxisCount(int c_id, ref ushort axis_cnt);
|
||||
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_MotionGetAxisState", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_MotionGetAxisState(int c_id, int axis_idx, ref byte state);
|
||||
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_MotionGetAxisEnable", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_MotionGetAxisEnable(int c_id, int axis_idx, ref byte enable);
|
||||
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_MotionGetAxisBusy", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_MotionGetAxisBusy(int c_id, int axis_idx, ref byte busy);
|
||||
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_MotionGetAxisLimitPos", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_MotionGetAxisLimitPos(int c_id, int axis_idx, ref byte limit_pos);
|
||||
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_MotionGetAxisLimitNeg", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_MotionGetAxisLimitNeg(int c_id, int axis_idx, ref byte limit_neg);
|
||||
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_MotionGetAxisHomeSwitch", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_MotionGetAxisHomeSwitch(int c_id, int axis_idx, ref byte home_sw);
|
||||
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_MotionGetAxisCmdDone", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_MotionGetAxisCmdDone(int c_id, int axis_idx, ref byte cmd_done);
|
||||
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_MotionGetAxisPosition", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_MotionGetAxisPosition(int c_id, int axis_idx, ref int position);
|
||||
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_MotionGetAxisVelocity", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_MotionGetAxisVelocity(int c_id, int axis_idx, ref int velocity);
|
||||
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_MotionGetAxisInfo", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_MotionGetAxisInfo(int c_id, int axis_idx, ref MS_AIXS_INFO axis_info);
|
||||
|
||||
//==== 运动控制轴设置
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_MotionSetAxisEnable", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_MotionSetAxisEnable(int c_id, int axis_idx, byte enable);
|
||||
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_MotionSetAxisPosition", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_MotionSetAxisPosition(int c_id, int axis_idx, int position);
|
||||
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_MotionSetAxisMoveAbs", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_MotionSetAxisMoveAbs(int c_id, int axis_idx, int pos, int vel, int acc_ms, int dec_ms);
|
||||
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_MotionSetAxisMoveInc", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_MotionSetAxisMoveInc(int c_id, int axis_idx, int dis, int vel, int acc_ms, int dec_ms);
|
||||
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_MotionSetAxisMoveVel", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_MotionSetAxisMoveVel(int c_id, int axis_idx, int vel, int acc_ms, int dec_ms);
|
||||
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_MotionSetAxisHome", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_MotionSetAxisHome(int c_id, int axis_idx, int home_mode, int vel_fast, int vel_slow, int acc_ms, int dec_ms, int offset);
|
||||
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_MotionSetAxisJogging", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_MotionSetAxisJogging(int c_id, int axis_idx, int vel, int acc_ms, int dec_ms);
|
||||
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_MotionSetAxisStop", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_MotionSetAxisStop(int c_id, int axis_idx);
|
||||
|
||||
[DllImport("MS_ModbusApi.dll", EntryPoint = "MS_MotionSetAxisDirReverse", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int MS_MotionSetAxisDirReverse(int c_id, int axis_idx, byte reverse);
|
||||
|
||||
//错误码
|
||||
public const int MS_MB_ERR_NONE = 0;
|
||||
public const int MS_MB_ERR_CONFIG = 1000;
|
||||
public const int MS_MB_ERR_OPEN = 1001;
|
||||
public const int MS_MB_ERR_NODATA = 1002;
|
||||
public const int MS_MB_ERR_NOTFOUND = 1003;
|
||||
public const int MS_MB_ERR_MEM = 1004;
|
||||
public const int MS_MB_ERR_FUNCPARAM = 1005;
|
||||
public const int MS_MB_ERR_COMM = 1006;
|
||||
public const int MS_MB_ERR_AXIS_DISABLED = 1100;
|
||||
}
|
||||
}
|
||||
@ -103,11 +103,13 @@
|
||||
<Compile Include="MotionControl\TrajectoryCluster.cs" />
|
||||
<Compile Include="MotionControl\ZmotionCard.cs" />
|
||||
<Compile Include="MotionControl\ZmotionShaft.cs" />
|
||||
<Compile Include="MS_MB_API.cs" />
|
||||
<Compile Include="MyPlaneAlgorithm.cs" />
|
||||
<Compile Include="ProductModel.cs" />
|
||||
<Compile Include="Robot\RobotModel.cs" />
|
||||
<Compile Include="SerialComModel.cs" />
|
||||
<Compile Include="StandModel.cs" />
|
||||
<Compile Include="StationMessage.cs" />
|
||||
<Compile Include="VehicleModel.cs" />
|
||||
<Compile Include="Vision\BaslerCamera.cs" />
|
||||
<Compile Include="MotionControl\LeiSaiCard.cs" />
|
||||
|
||||
@ -198,4 +198,98 @@ namespace Model.MotionControl
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class LeiSaiMBCard : FeiYuCard
|
||||
{
|
||||
|
||||
|
||||
#region 获取轴数量
|
||||
/// <summary>
|
||||
/// 获取轴数量
|
||||
/// </summary>
|
||||
public override bool GetCradInfo()
|
||||
{
|
||||
|
||||
return false;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 连接控制器
|
||||
public static int s_link = 0;
|
||||
public static Int32 c_id = 0;
|
||||
MS_MB_API.Comm_Config config = new MS_MB_API.Comm_Config();
|
||||
/// <summary>
|
||||
/// 连接控制器
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override bool Connect()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (InterfaceType == 0)
|
||||
{
|
||||
config.serial.portName = PconnectString;
|
||||
config.serial.baudrate = 115200;
|
||||
config.serial.dataBits = 8;
|
||||
config.serial.parity = 0;
|
||||
config.serial.stopBits = 1;
|
||||
config.type = MS_MB_API.COMM_TYPE_SER;
|
||||
}
|
||||
else
|
||||
{
|
||||
config.enet.ip = PconnectString;
|
||||
config.enet.port = 502;
|
||||
config.type = MS_MB_API.COMM_TYPE_ENET;
|
||||
}
|
||||
|
||||
|
||||
if (MS_MB_API.MS_OpenComm(config, ref c_id) == MS_MB_API.MS_MB_ERR_NONE)
|
||||
{
|
||||
MS_MB_API.MS_CommSetSlave(c_id, 1);
|
||||
s_link = 1;
|
||||
|
||||
CardID = (ushort)c_id;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 关闭控制器
|
||||
/// <summary>
|
||||
/// 关闭控制器
|
||||
/// </summary>
|
||||
public override void close()
|
||||
{
|
||||
if (s_link == 0)
|
||||
return;
|
||||
MS_MB_API.MS_CloseComm(c_id);
|
||||
s_link = 0;
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 所有轴紧急停止
|
||||
/// <summary>
|
||||
/// 所有轴紧急停止
|
||||
/// </summary>
|
||||
/// <param name="cardid">卡ID</param>
|
||||
public override void MoveFunction_Estop()
|
||||
{
|
||||
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,6 +8,9 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Model
|
||||
{
|
||||
/// <summary>
|
||||
/// 输出信号类
|
||||
/// </summary>
|
||||
/// <summary>
|
||||
/// 输出信号类
|
||||
/// </summary>
|
||||
@ -40,11 +43,6 @@ namespace Model
|
||||
/// </summary>
|
||||
public ushort IoNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// IO打开的时间
|
||||
/// </summary>
|
||||
public DateTime SwitchsOpenTime { get; set; }
|
||||
|
||||
|
||||
private bool switchs;
|
||||
/// <summary>
|
||||
@ -57,47 +55,52 @@ namespace Model
|
||||
{
|
||||
switchs = value;
|
||||
|
||||
if (ToRunControlCard && MyCard != null)
|
||||
//if (ToRunControlCard && MyCard != null)
|
||||
//{
|
||||
// switch (MyCard.Brand)
|
||||
// {
|
||||
// case 1:
|
||||
// if (value)
|
||||
// {
|
||||
// LevelState = 0;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// LevelState = 1;
|
||||
// }
|
||||
// break;
|
||||
// case 2:
|
||||
// if (value)
|
||||
// {
|
||||
// LevelState = 0;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// LevelState = 1;
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// if (value)
|
||||
// {
|
||||
// LevelState = 1;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// LevelState = 0;
|
||||
// }
|
||||
|
||||
//}
|
||||
|
||||
if (value)
|
||||
{
|
||||
switch (MyCard.Brand)
|
||||
{
|
||||
case 1:
|
||||
if (value)
|
||||
{
|
||||
LevelState = 0;
|
||||
SwitchsOpenTime = DateTime.Now;
|
||||
}
|
||||
else
|
||||
{
|
||||
LevelState = 1;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (value)
|
||||
{
|
||||
LevelState = 0;
|
||||
SwitchsOpenTime = DateTime.Now;
|
||||
}
|
||||
else
|
||||
{
|
||||
LevelState = 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
LevelState = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
LevelState = 1;
|
||||
SwitchsOpenTime = DateTime.Now;
|
||||
}
|
||||
else
|
||||
{
|
||||
LevelState = 0;
|
||||
SwitchsOpenTime = DateTime.Now;
|
||||
}
|
||||
|
||||
LevelState = 0;
|
||||
}
|
||||
|
||||
this.RaisePropertyChanged("Switchs");
|
||||
@ -132,43 +135,52 @@ namespace Model
|
||||
{
|
||||
levelState = value;
|
||||
|
||||
if (ToRunControlCard && MyCard != null)
|
||||
//if (ToRunControlCard && MyCard != null)
|
||||
//{
|
||||
// switch (MyCard.Brand)
|
||||
// {
|
||||
// case 1:
|
||||
// if (value == 1)
|
||||
// {
|
||||
// this.OutputColor = ColorStr.Green;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// this.OutputColor = ColorStr.Red;
|
||||
// }
|
||||
// break;
|
||||
// case 2:
|
||||
// if (value == 0)
|
||||
// {
|
||||
// this.OutputColor = ColorStr.Red;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// this.OutputColor = ColorStr.Green;
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// if (value == 0)
|
||||
// {
|
||||
|
||||
// this.OutputColor = ColorStr.Green;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// this.OutputColor = ColorStr.Red;
|
||||
// }
|
||||
//}
|
||||
|
||||
if (value == 1)
|
||||
{
|
||||
switch (MyCard.Brand)
|
||||
{
|
||||
case 1:
|
||||
if (value == 1)
|
||||
{
|
||||
this.OutputColor = ColorStr.Green;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.OutputColor = ColorStr.Red;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (value == 0)
|
||||
{
|
||||
this.OutputColor = ColorStr.Red;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.OutputColor = ColorStr.Green;
|
||||
}
|
||||
break;
|
||||
}
|
||||
this.OutputColor = ColorStr.Red;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (value == 0)
|
||||
{
|
||||
|
||||
this.OutputColor = ColorStr.Green;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.OutputColor = ColorStr.Red;
|
||||
}
|
||||
this.OutputColor = ColorStr.Green;
|
||||
}
|
||||
|
||||
OutputSwitch(value);
|
||||
@ -185,6 +197,11 @@ namespace Model
|
||||
/// </summary>
|
||||
public bool ToRunControlCard { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 空信号
|
||||
/// </summary>
|
||||
public bool EmptySignal { get; set; }
|
||||
|
||||
private string outputColor;
|
||||
/// <summary>
|
||||
/// 表示显色
|
||||
@ -210,100 +227,89 @@ namespace Model
|
||||
#region 控制卡输出信号开关
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 控制卡输出信号开关
|
||||
/// </summary>
|
||||
public void OutputSwitch1(ushort onoff)
|
||||
{
|
||||
|
||||
if (ToRunControlCard && MyCard != null)
|
||||
{
|
||||
switch (MyCard.Brand)
|
||||
{
|
||||
case 1:
|
||||
if (MyCard.InterfaceType == 2)
|
||||
{
|
||||
LTSMC.smc_write_outbit(MyCard.CardID, IoNumber, onoff);
|
||||
}
|
||||
else
|
||||
{
|
||||
LTDMC.dmc_write_outbit(MyCard.CardID, IoNumber, onoff);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
onoff = onoff == (ushort)0 ? (ushort)1 : (ushort)0;
|
||||
if (MyCard.InterfaceType == 2)
|
||||
{
|
||||
zmcaux.ZAux_Direct_SetOp(g_handle, IoNumber, onoff);
|
||||
}
|
||||
else
|
||||
{
|
||||
ADTMC.adt_write_outbit(MyCard.CardID, IoNumber, onoff);
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//雷赛IO卡
|
||||
//IOC0640.ioc_write_outbit(CardID, IoNumber, onoff);
|
||||
//众为兴沙雕IO卡
|
||||
//adtIO3224.adtIO3224_write_bit(CardID, IoNumber, onoff);
|
||||
|
||||
//雷赛IO模块
|
||||
MS_MB_API.Outputs[IoNumber] = (byte)levelState;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 控制卡输出信号开关
|
||||
/// </summary>
|
||||
public void OutputSwitch(ushort onoff)
|
||||
{
|
||||
|
||||
if (ToRunControlCard && MyCard != null)
|
||||
if (ToRunControlCard)
|
||||
{
|
||||
switch (MyCard.Brand)
|
||||
{
|
||||
case 1:
|
||||
if (MyCard.InterfaceType == 2)
|
||||
{
|
||||
LTSMC.smc_write_outbit(MyCard.CardID, IoNumber, onoff);
|
||||
}
|
||||
else
|
||||
{
|
||||
LTDMC.dmc_write_outbit(MyCard.CardID, IoNumber, onoff);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
onoff = onoff == (ushort)0 ? (ushort)1 : (ushort)0;
|
||||
if (MyCard.InterfaceType == 2)
|
||||
{
|
||||
zmcaux.ZAux_Direct_SetOp(g_handle, IoNumber, onoff);
|
||||
}
|
||||
else if (MyCard.InterfaceType==0)
|
||||
{
|
||||
adt8949.adt8949_write_bit(MyCard.CardID, IoNumber, onoff);
|
||||
}
|
||||
else
|
||||
{
|
||||
ADTMC.adt_write_outbit(MyCard.CardID, IoNumber, onoff);
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// LTDMC.dmc_write_outbit(CardID, IoNumber, onoff);
|
||||
// LTSMC.smc_write_outbit(CardID, IoNumber, onoff);
|
||||
// zmcaux.ZAux_Direct_SetOp(g_handle, IoNumber, onoff);
|
||||
}
|
||||
else
|
||||
{
|
||||
//雷赛IO卡
|
||||
//IOC0640.ioc_write_outbit(CardID, IoNumber, onoff);
|
||||
//众为兴沙雕IO卡
|
||||
adtIO3224.adtIO3224_write_bit(CardID, IoNumber, onoff);
|
||||
}
|
||||
}
|
||||
|
||||
public void OutputSwitch(ushort IoNumber, ushort onoff)
|
||||
{
|
||||
|
||||
if (ToRunControlCard && MyCard != null)
|
||||
{
|
||||
switch (MyCard.Brand)
|
||||
{
|
||||
case 1:
|
||||
if (MyCard.InterfaceType == 2)
|
||||
{
|
||||
LTSMC.smc_write_outbit(MyCard.CardID, IoNumber, onoff);
|
||||
}
|
||||
else
|
||||
{
|
||||
LTDMC.dmc_write_outbit(MyCard.CardID, IoNumber, onoff);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
onoff = onoff == (ushort)0 ? (ushort)1 : (ushort)0;
|
||||
if (MyCard.InterfaceType == 2)
|
||||
{
|
||||
zmcaux.ZAux_Direct_SetOp(g_handle, IoNumber, onoff);
|
||||
}
|
||||
else
|
||||
{
|
||||
ADTMC.adt_write_outbit(MyCard.CardID, IoNumber, onoff);
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//雷赛IO卡
|
||||
//IOC0640.ioc_write_outbit(CardID, IoNumber, onoff);
|
||||
//众为兴沙雕IO卡
|
||||
adtIO3224.adtIO3224_write_bit(CardID, IoNumber, onoff);
|
||||
// IOC0640.ioc_write_outbit(CardID, IoNumber, onoff);
|
||||
}
|
||||
MS_MB_API.Outputs[IoNumber] = (byte)levelState;
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 将八进制整数转换为十进制整数
|
||||
/// </summary>
|
||||
/// <param name="octal">八进制整数</param>
|
||||
/// <returns>十进制整数</returns>
|
||||
public int OctalToDecimal(int octal)
|
||||
{
|
||||
int decimalValue = 0;
|
||||
int baseValue = 1;
|
||||
int temp = octal;
|
||||
while (temp > 0)
|
||||
{
|
||||
int lastDigit = temp % 10;
|
||||
decimalValue += lastDigit * baseValue;
|
||||
baseValue *= 8;
|
||||
temp /= 10;
|
||||
}
|
||||
return decimalValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
55
Model/StationMessage.cs
Normal file
55
Model/StationMessage.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Model
|
||||
{
|
||||
public class StationMessage
|
||||
{
|
||||
/// <summary>
|
||||
/// 安全互锁 false时表示正在占用公共区域
|
||||
/// </summary>
|
||||
public bool Safe { get; set; }
|
||||
/// <summary>
|
||||
/// 请求松手/拿好,
|
||||
/// 取上站被物料时, 请求松手
|
||||
/// 放到下站时,请求拿好
|
||||
/// </summary>
|
||||
public bool Request { get; set; }
|
||||
/// <summary>
|
||||
/// 确认松手/拿好
|
||||
/// 后站请求松手时,回应True
|
||||
/// 前站请求拿好时,回应True
|
||||
/// </summary>
|
||||
public bool Confirm { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 取料完成 当后站取走产品后,置位true,前站收到该信号后, 改变物料状态为ColorStr.White(无料),
|
||||
/// </summary>
|
||||
public bool GetDone { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 放料料完成 当产品放入后站后 ,置位true,后站收到该信号后, 改变物料状态为 ProductState ,
|
||||
/// </summary>
|
||||
public bool PutDone { get; set; }
|
||||
/// <summary>
|
||||
/// 产品数量
|
||||
/// </summary>
|
||||
public int ProductCount { get; set; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// 产品状态 ColorStr.White(无料) Blue(有料) Green(良品) Red(不良)
|
||||
/// 多个产品时,用;号分割
|
||||
/// </summary>
|
||||
public string ProductState { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 产品条码
|
||||
/// 多个产品时,用;号分割
|
||||
/// </summary>
|
||||
public string ProductSN { get; set; }
|
||||
}
|
||||
}
|
||||
175
ViewModel/HandModel.cs
Normal file
175
ViewModel/HandModel.cs
Normal file
@ -0,0 +1,175 @@
|
||||
using Community;
|
||||
using Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Data;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace ViewModel
|
||||
{
|
||||
public class HandModel : NotificationObject
|
||||
{
|
||||
/// <summary>
|
||||
/// 序号
|
||||
/// </summary>
|
||||
public int Number { get; set; }
|
||||
|
||||
public Label Labels { get; set; }
|
||||
|
||||
private ShowInfo state;
|
||||
/// <summary>
|
||||
/// 标签状态
|
||||
/// </summary>
|
||||
public ShowInfo State
|
||||
{
|
||||
get { return state; }
|
||||
set
|
||||
{
|
||||
state = value == null ? new ShowInfo() : value;
|
||||
RaisePropertyChanged("State");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 气缸
|
||||
/// </summary>
|
||||
public OutputSignal QiGang { get; set; }
|
||||
/// <summary>
|
||||
/// 气缸原位
|
||||
/// </summary>
|
||||
public InputSignal QiGangUp { get; set; }
|
||||
/// <summary>
|
||||
/// 气缸到位
|
||||
/// </summary>
|
||||
public InputSignal QiGangDown { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 顶升气缸原位
|
||||
/// </summary>
|
||||
public OutputSignal YDingShengQiGangYW { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 顶升气缸动位
|
||||
/// </summary>
|
||||
public OutputSignal YDingShengQiGangDW { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 顶升气缸原位检知
|
||||
/// </summary>
|
||||
public InputSignal XDingShengQigangYW { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 顶升气缸到位检知
|
||||
/// </summary>
|
||||
public InputSignal XDingShengQigangDW { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 伸缩气缸
|
||||
/// </summary>
|
||||
public OutputSignal YShenSuoQiGangYW { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 伸缩气缸
|
||||
/// </summary>
|
||||
public OutputSignal YShenSuoQiGangDW { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 伸缩气缸原位
|
||||
/// </summary>
|
||||
public InputSignal XShenSuoQigangYW { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 伸缩气缸到位
|
||||
/// </summary>
|
||||
public InputSignal XShenSuoQigangDW { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 真空开关
|
||||
/// </summary>
|
||||
public OutputSignal VacuumSwitch { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 真空破开关
|
||||
/// </summary>
|
||||
public OutputSignal VacuumPoSwitch { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 真空捡知
|
||||
/// </summary>
|
||||
public InputSignal VacuumCheck { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 吸嘴放料点位1
|
||||
/// </summary>
|
||||
public RobotPoint PutProPoint1 { get; set; }
|
||||
/// <summary>
|
||||
/// 吸嘴放料点位2
|
||||
/// </summary>
|
||||
public RobotPoint PutProPoint2 { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 吸嘴取料点位1
|
||||
/// </summary>
|
||||
public RobotPoint TakeProPoint1 { get; set; }
|
||||
/// <summary>
|
||||
/// 吸嘴取料点位2
|
||||
/// </summary>
|
||||
public RobotPoint TakeProPoint2 { get; set; }
|
||||
|
||||
public DateTime CheckVacuumTime { get; set; }
|
||||
|
||||
public double OfficeX { get; set; }
|
||||
public double OfficeY { get; set; }
|
||||
|
||||
public double OfficeU { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Label显示控件对象
|
||||
/// </summary>
|
||||
public HandModel()
|
||||
{
|
||||
State = new ShowInfo();
|
||||
Labels = new Label();
|
||||
//数据样式
|
||||
Labels.Style = (Style)MyMessageBox.MetroWin.FindResource("Mylabel1");//LabelStyle 这个样式是引用的资源文件中的样式名称
|
||||
//绑定背景颜色
|
||||
Labels.SetBinding(Label.BackgroundProperty, new Binding() { Source = this, Path = new PropertyPath("State.StatusBackground"), Mode = BindingMode.TwoWay });
|
||||
//绑定内容
|
||||
Labels.SetBinding(Label.ContentProperty, new Binding() { Source = this, Path = new PropertyPath("State.StatuInfo"), Mode = BindingMode.TwoWay });
|
||||
|
||||
Labels.MouseDoubleClick += Labels_MouseDoubleClick; //增加鼠标双击事件
|
||||
Labels.Margin = new Thickness(1); //设置边距
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Label的双击事件
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void Labels_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
|
||||
{
|
||||
//如果为绿色 则不允许改其他颜色
|
||||
if (State.StatusBackground == ColorStr.White)
|
||||
{
|
||||
State.StatusBackground = ColorStr.Blue;
|
||||
}
|
||||
else if (State.StatusBackground == ColorStr.Blue)
|
||||
{
|
||||
State.StatusBackground = ColorStr.Green;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
State.StatusBackground = ColorStr.White;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -50,8 +50,6 @@ namespace ViewModel.Robots
|
||||
/// </summary>
|
||||
public string RCVInfo { get; set; }
|
||||
|
||||
|
||||
|
||||
#region 机器人连接
|
||||
private bool robotConn;
|
||||
/// <summary>
|
||||
|
||||
@ -90,6 +90,7 @@
|
||||
<Compile Include="ChartVM.cs" />
|
||||
<Compile Include="CommunicationServerVM.cs" />
|
||||
<Compile Include="ERPManageVM.cs" />
|
||||
<Compile Include="HandModel.cs" />
|
||||
<Compile Include="MotionControl\MotionControlVM.cs" />
|
||||
<Compile Include="PLCVM.cs" />
|
||||
<Compile Include="Robots\EpsonRobotVM.cs" />
|
||||
|
||||
@ -553,9 +553,6 @@ namespace ViewModel.Vision
|
||||
ho_SymbolXLDs.Dispose();
|
||||
HOperatorSet.FindDataCode2d(ho_ROIImage, out ho_SymbolXLDs, hv_DataCodeHandleMaximum, ParamName, CodeCount, out hv_ResultHandles, out hv_DecodedDataStrings);
|
||||
|
||||
|
||||
|
||||
|
||||
//显示XLD轮廓
|
||||
SetColored(12);
|
||||
//ClearWindowAndData();
|
||||
|
||||
@ -21,7 +21,7 @@
|
||||
</Border>
|
||||
|
||||
<TabControl Grid.Row="1" Background="{x:Null}">
|
||||
<TabItem Header="资讯" >
|
||||
<TabItem Header="资讯" >
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition></RowDefinition>
|
||||
@ -31,12 +31,14 @@
|
||||
<RowDefinition></RowDefinition>
|
||||
<RowDefinition></RowDefinition>
|
||||
<RowDefinition></RowDefinition>
|
||||
<RowDefinition></RowDefinition>
|
||||
<RowDefinition></RowDefinition>
|
||||
<RowDefinition></RowDefinition>
|
||||
<RowDefinition></RowDefinition>
|
||||
<RowDefinition></RowDefinition>
|
||||
</Grid.RowDefinitions>
|
||||
<RowDefinition></RowDefinition>
|
||||
<RowDefinition></RowDefinition>
|
||||
<RowDefinition></RowDefinition>
|
||||
<RowDefinition></RowDefinition>
|
||||
<RowDefinition></RowDefinition>
|
||||
<RowDefinition></RowDefinition>
|
||||
<RowDefinition></RowDefinition>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition></ColumnDefinition>
|
||||
<ColumnDefinition></ColumnDefinition>
|
||||
@ -91,8 +93,7 @@
|
||||
Content="前站连接"
|
||||
Foreground="White"
|
||||
Background="{Binding StatusBackground}"></Label>
|
||||
<Label Grid.Row="5"
|
||||
Grid.Column="1"
|
||||
<Label Grid.Row="6"
|
||||
Margin="1"
|
||||
Style="{DynamicResource Mylabel1}"
|
||||
DataContext="{Binding NextStation.Showmsg}"
|
||||
@ -100,16 +101,26 @@
|
||||
Foreground="White"
|
||||
Background="{Binding StatusBackground}"></Label>
|
||||
|
||||
<GroupBox Grid.Row="6" Grid.RowSpan="6" Grid.ColumnSpan="2" DataContext="{Binding Tray1}" Header="{Binding TrayName}" Content="{Binding GridContent}" Padding="0"></GroupBox>
|
||||
<!--<GroupBox Header="缓存位状态" Grid.Row="7" Grid.RowSpan="2" Grid.ColumnSpan="2" Content="{Binding CacheBoxGrid}"></GroupBox>
|
||||
<GroupBox Header="吸嘴状态" Grid.Row="9" Grid.RowSpan="2" Grid.ColumnSpan="2" Content="{Binding XizuiLabelGrid}"></GroupBox>-->
|
||||
<GroupBox Header="前后机台物料状态" Padding="0" Grid.Row="5" Grid.RowSpan="2" Grid.Column="1" Content="{Binding StationProduceGrid}"></GroupBox>
|
||||
<GroupBox Header="测试平台状态" Padding="0" Grid.Row="10" Grid.RowSpan="2" Grid.ColumnSpan="2" Content="{Binding TestBenchGrid}"></GroupBox>
|
||||
<GroupBox Header="吸嘴状态" Padding="0" Grid.Row="12" Grid.RowSpan="2" Grid.ColumnSpan="2" Content="{Binding XizuiLabelGrid}"></GroupBox>
|
||||
<!--<Grid Grid.Row="12" Grid.RowSpan="2" Grid.ColumnSpan="2">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition></ColumnDefinition>
|
||||
<ColumnDefinition></ColumnDefinition>
|
||||
<ColumnDefinition></ColumnDefinition>
|
||||
</Grid.ColumnDefinitions>
|
||||
<GroupBox Header="进料平台" Padding="0" Grid.Row="12" Grid.RowSpan="2" Content="{Binding InCacheGrid}"></GroupBox>
|
||||
--><!--<GroupBox Header="缓存流线" Padding="0" Grid.Row="12" Grid.RowSpan="2" Grid.Column="1" Content="{Binding CacheLineGrid}"></GroupBox>
|
||||
<GroupBox Header="良品流线" Padding="0" Grid.Row="12" Grid.RowSpan="2" Grid.Column="2" Content="{Binding ProduceLineGrid}"></GroupBox>--><!--
|
||||
</Grid>-->
|
||||
</Grid>
|
||||
</TabItem>
|
||||
<TabItem Header="输入" Content="{Binding InputGrid}"></TabItem>
|
||||
<TabItem Header="输出" Content="{Binding OutputGrid}"></TabItem>
|
||||
<TabItem Header="轴状态" DataContext="{Binding MCVM}">
|
||||
<!--<TabItem Header="轴状态" DataContext="{Binding MCVM}">
|
||||
<Motion:ShaftState />
|
||||
</TabItem>
|
||||
</TabItem>-->
|
||||
</TabControl>
|
||||
<GroupBox Name="GBST" Header="控制按钮" Grid.Row="2" Margin="0">
|
||||
<Grid>
|
||||
|
||||
@ -10,8 +10,7 @@
|
||||
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="85*"></RowDefinition>
|
||||
<RowDefinition Height="15*"></RowDefinition>
|
||||
<RowDefinition></RowDefinition>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<!--<ColumnDefinition Width="40*"></ColumnDefinition>-->
|
||||
@ -23,15 +22,9 @@
|
||||
<ColumnDefinition></ColumnDefinition>
|
||||
<ColumnDefinition></ColumnDefinition>
|
||||
</Grid.ColumnDefinitions>
|
||||
<ContentControl DataContext="{Binding VisualA}" Margin="1" Content="{Binding HWindowWPF2}"></ContentControl>
|
||||
<ContentControl DataContext="{Binding VisualB}" Margin="1" Grid.Column="1" Content="{Binding HWindowWPF2}"></ContentControl>
|
||||
<!--<ContentControl DataContext="{Binding VisualA}" Content="{Binding HWindowWPF2}"></ContentControl>-->
|
||||
<ContentControl DataContext="{Binding VisualB}" Margin="1" Grid.ColumnSpan="2" Content="{Binding HWindowWPF2}"></ContentControl>
|
||||
</Grid>
|
||||
<!--<GroupBox Grid.Row="2" Grid.ColumnSpan="2" DataContext="{Binding Tray1}" Header="{Binding TrayName}" Content="{Binding GridContent}" Padding="0"></GroupBox>-->
|
||||
<!--<GroupBox Grid.Row="2" Grid.Column="1" DataContext="{Binding Tray2}" Header="{Binding TrayName}" Content="{Binding GridContent}" Padding="0"></GroupBox>-->
|
||||
|
||||
<!--<GroupBox Header="进料载具" Margin="0" Padding="0" Grid.Row="1" Content="{Binding BackFlowBoxGrid}"></GroupBox>-->
|
||||
<GroupBox Header="载具放料" Margin="0" Padding="0" Grid.Row="1" Grid.Column="0" Content="{Binding VehicleBoxGrid}"></GroupBox>
|
||||
<GroupBox Header="取料吸嘴" Margin="0" Padding="0" Grid.Row="1" Grid.Column="1" Content="{Binding XizuiLabelGrid}"></GroupBox>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
</UserControl>
|
||||
|
||||
@ -204,7 +204,7 @@
|
||||
<DataGridTextColumn Header="U坐标" Binding="{Binding PointU}" Width="*" IsReadOnly="True" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"></DataGridTextColumn>
|
||||
<DataGridTextColumn Header="V坐标" Binding="{Binding PointV}" Width="*" IsReadOnly="True" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"></DataGridTextColumn>
|
||||
<DataGridTextColumn Header="W坐标" Binding="{Binding PointW}" Width="*" IsReadOnly="True" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"></DataGridTextColumn>
|
||||
<!--<DataGridTextColumn Header="手势" Binding="{Binding HandRL}" Width="*" IsReadOnly="True" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"></DataGridTextColumn>-->
|
||||
<DataGridTextColumn Header="手势" Binding="{Binding HandRL}" Width="*" IsReadOnly="True" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"></DataGridTextColumn>
|
||||
<!--<DataGridTextColumn Header="镭射值" Binding="{Binding SpareField,Mode=TwoWay, UpdateSourceTrigger=LostFocus}" Width="*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"></DataGridTextColumn>-->
|
||||
<DataGridTextColumn Header="速度档位" Binding="{Binding SpeedGear,Mode=TwoWay, UpdateSourceTrigger=LostFocus}" Width="*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"></DataGridTextColumn>
|
||||
</DataGrid.Columns>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user