Commit 2334bd87 顾剑亮

更新

1 个父辈 e90b5c6c
此文件类型无法预览
......@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.1.0")]
[assembly: AssemblyFileVersion("1.0.1.0")]
......@@ -13,6 +13,8 @@ namespace Neotel
public class Rmaxis
{
private RMAxis device;
private string portName;
private ushort axisNo;
private readonly log4net.ILog LOG;
private readonly bool initOK;
public readonly string[] ErrorString = new string[] { "正常", "通用错误", "电机失相", "位置超差", "速度超差", "电机堵转", "初相励磁错误" };
......@@ -86,8 +88,11 @@ namespace Neotel
{
try
{
this.portName = portName;
this.axisNo = axisNo;
device = RMAxis.CreateModbus("\\\\.\\" + portName.ToUpper(), 115200, axisNo);
LOG.Info("OpenPort OK");
LOG.Info(string.Format("OpenPort {0}:{1} OK", portName, axisNo));
//device.ServoOnOff = true;
IsPortOpen = true;
}
catch (Exception ex)
......@@ -114,9 +119,10 @@ namespace Neotel
try
{
//device.ServoOnOff = false;
RMAxis.Destroy(device);
device = null;
LOG.Info("ClosePort OK");
LOG.Info(string.Format("ClosePort {0}:{1} OK", portName, axisNo));
}
catch (Exception ex)
{
......@@ -216,7 +222,7 @@ namespace Neotel
try
{
n = device.Torque;
LOG.Info("GetTorque OK");
LOG.Debug("GetTorque OK");
}
catch (Exception ex)
{
......@@ -226,26 +232,26 @@ namespace Neotel
return n;
}
///// <summary>
///// 获取电机运动中的出力
///// </summary>
///// <returns>出力,%</returns>
//public float GetForce()
//{
// float n = -1;
// if (!IsPortOpen) return n;
// try
// {
// n = device.ForceSensor;
// LOG.Info("GetForce OK");
// }
// catch (Exception ex)
// {
// n = -1;
// LOG.Error("GetForce", ex);
// }
// return n;
//}
/// <summary>
/// 获取当前力传感器读数
/// </summary>
/// <returns>出力,%</returns>
public float GetForceSensor()
{
float n = -1;
if (!IsPortOpen) return n;
try
{
n = device.ForceSensor;
LOG.Info("GetForce OK");
}
catch (Exception ex)
{
n = -1;
LOG.Error("GetForce", ex);
}
return n;
}
/// <summary>
/// 获取当前电机速度
......@@ -258,7 +264,7 @@ namespace Neotel
try
{
n = device.Velocity;
LOG.Info("GetVelocity OK");
LOG.Debug("GetVelocity OK");
}
catch (Exception ex)
{
......@@ -279,7 +285,7 @@ namespace Neotel
try
{
n = device.Position;
LOG.Info("GetPosition OK");
LOG.Debug("GetPosition OK");
}
catch (Exception ex)
{
......@@ -315,7 +321,7 @@ namespace Neotel
/// <param name="force">出力,%</param>
/// <param name="distance">距离,mm</param>
/// <param name="velocity">速度,mm/s</param>
public void Push(float force, float distance, float velocity)
public void Push(float force = 30, float distance = 7, float velocity = 500)
{
if (!IsPortOpen) return;
LOG.Info("Push Start");
......@@ -339,7 +345,7 @@ namespace Neotel
/// <param name="acceleration">加速度,mm/s^2</param>
/// <param name="deacceleration">减速度,mm/s^2</param>
/// <param name="band">定位范围,mm</param>
public void MoveAbsolute(float position, float velocity, float acceleration, float deacceleration, float band)
public void MoveAbsolute(float position = 7, float velocity = 500, float acceleration = 500, float deacceleration = 500, float band = 0.1f)
{
if (!IsPortOpen) return;
LOG.Info("MoveAbsolute Start");
......@@ -529,9 +535,9 @@ namespace Neotel
private bool Wait(int timeout)
{
int n = 0;
int mm = 10;
int msec = 5;
bool result = true;
System.Threading.Thread.Sleep(mm);
System.Threading.Thread.Sleep(msec);
while (!device.IsReached())
{
......@@ -540,8 +546,8 @@ namespace Neotel
result = false;
break;
}
n += mm;
System.Threading.Thread.Sleep(mm);
n += msec;
System.Threading.Thread.Sleep(msec);
System.Windows.Forms.Application.DoEvents();
}
return result;
......
......@@ -75,6 +75,12 @@
</summary>
<returns>出力,%</returns>
</member>
<member name="M:Neotel.Rmaxis.GetForceSensor">
<summary>
获取当前力传感器读数
</summary>
<returns>出力,%</returns>
</member>
<member name="M:Neotel.Rmaxis.GetVelocity">
<summary>
获取当前电机速度
......
c9564820a79ee9ecf18d331729e43a9bc2a948d1
adfa69f216c5b3ebd55063cc7b2c7f636a6b704c
......@@ -8,3 +8,13 @@ C:\Neotel\Program_Beta\Rmaxis\Rmaxis\obj\Debug\Neotel.Rmaxis.dll
C:\Neotel\Program_Beta\Rmaxis\Rmaxis\obj\Debug\Neotel.Rmaxis.pdb
C:\Neotel\Program_Beta\Rmaxis\Rmaxis\bin\Debug\Neotel.Rmaxis.xml
C:\Neotel\Program_Beta\Rmaxis\Rmaxis\obj\Debug\Rmaxis.csprojAssemblyReference.cache
C:\Neotel\Program\Rmaxis\Rmaxis\bin\Debug\Neotel.Rmaxis.xml
C:\Neotel\Program\Rmaxis\Rmaxis\bin\Debug\Neotel.Rmaxis.dll
C:\Neotel\Program\Rmaxis\Rmaxis\bin\Debug\Neotel.Rmaxis.pdb
C:\Neotel\Program\Rmaxis\Rmaxis\bin\Debug\log4net.dll
C:\Neotel\Program\Rmaxis\Rmaxis\bin\Debug\log4net.xml
C:\Neotel\Program\Rmaxis\Rmaxis\obj\Debug\Rmaxis.csproj.CoreCompileInputs.cache
C:\Neotel\Program\Rmaxis\Rmaxis\obj\Debug\Rmaxis.csproj.CopyComplete
C:\Neotel\Program\Rmaxis\Rmaxis\obj\Debug\Neotel.Rmaxis.dll
C:\Neotel\Program\Rmaxis\Rmaxis\obj\Debug\Neotel.Rmaxis.pdb
C:\Neotel\Program\Rmaxis\Rmaxis\obj\Debug\Rmaxis.csprojAssemblyReference.cache
......@@ -15,6 +15,7 @@ namespace Test
private readonly log4net.ILog LOG;
private Neotel.Rmaxis axis;
private bool testLoop;
private FrmMain frmSecond;
private System.Threading.Thread tStatus;
private System.Threading.Thread tTest;
......@@ -24,16 +25,52 @@ namespace Test
LOG = log4net.LogManager.GetLogger("Test");
}
public FrmMain(bool sameTime) : this()
{
BtnNewWindow.Visible = !sameTime;
BtnSameTime.Visible = !sameTime;
}
public void LoopTestTrigger()
{
if (testLoop)
{
StopTest();
return;
}
testLoop = true;
BtnStability.Text = "停止";
int[] param = new int[5];
param[0] = Convert.ToInt32(NudForce2.Value);
param[1] = Convert.ToInt32(NudDistance2.Value);
param[2] = Convert.ToInt32(NudVelocity3.Value);
param[3] = Convert.ToInt32(NudTimes.Value);
param[4] = Convert.ToInt32(NudInterval.Value);
tTest = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(PushTest));
tTest.Start(param);
}
private void ReadStatus()
{
while (true)
{
if (!axis.IsPortOpen) break;
float t = axis.GetTorque();
System.Threading.Thread.Sleep(20);
float v = axis.GetVelocity();
System.Threading.Thread.Sleep(20);
float p = axis.GetPosition();
System.Threading.Thread.Sleep(20);
LblStatus.Invoke(new Action(() =>
{
LblStatus.Text = "出力:" + axis.GetTorque() + "\r\n速度:" + axis.GetVelocity() + "\r\n位置:" + axis.GetPosition() + "\r\n错误代码:" + axis.ErrorCode;
LblStatus.Text = string.Format("出力:{0}\r\n速度:{1}\r\n位置:{2}\r\n错误代码:{3}", t, v, p, axis.ErrorCode);
}));
System.Threading.Thread.Sleep(50);
System.Threading.Thread.Sleep(200);
}
}
......@@ -86,6 +123,10 @@ namespace Test
{
for (int i = 1; i <= 30; i++)
CboPort.Items.Add("COM" + i);
CboPort.SelectedIndex = 0;
for (int i = 0; i < 10; i++)
CboAxisNo.Items.Add(i.ToString());
CboAxisNo.SelectedIndex = 0;
axis = new Neotel.Rmaxis();
}
......@@ -97,7 +138,7 @@ namespace Test
private void BtnOpenPort_Click(object sender, EventArgs e)
{
bool rtn = axis.OpenPort(CboPort.Text);
bool rtn = axis.OpenPort(CboPort.Text, Convert.ToUInt16(CboAxisNo.Text));
TsslStatus.Text = BtnOpenPort.Text + " " + rtn;
if (rtn)
{
......@@ -142,22 +183,19 @@ namespace Test
private void BtnStability_Click(object sender, EventArgs e)
{
if (testLoop)
{
StopTest();
return;
}
LoopTestTrigger();
}
testLoop = true;
BtnStability.Text = "停止";
int[] param = new int[5];
param[0] = Convert.ToInt32(NudForce2.Value);
param[1] = Convert.ToInt32(NudDistance2.Value);
param[2] = Convert.ToInt32(NudVelocity3.Value);
param[3] = Convert.ToInt32(NudTimes.Value);
param[4] = Convert.ToInt32(NudInterval.Value);
tTest = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(PushTest));
tTest.Start(param);
private void BtnNewWindow_Click(object sender, EventArgs e)
{
frmSecond = new FrmMain(true);
frmSecond.Show();
}
private void BtnSameTime_Click(object sender, EventArgs e)
{
LoopTestTrigger();
frmSecond.LoopTestTrigger();
}
}
}
......@@ -32,7 +32,7 @@ using System.Runtime.InteropServices;
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]
\ No newline at end of file
此文件的差异太大,无法显示。
[2021-03-17 10:15:12,158][1][Rmaxis:35]INFO Rmaxis Init OK
[2021-03-18 15:51:17,562][1][Rmaxis:35]INFO Rmaxis Init OK

\ No newline at end of file
......@@ -75,6 +75,12 @@
</summary>
<returns>出力,%</returns>
</member>
<member name="M:Neotel.Rmaxis.GetForceSensor">
<summary>
获取当前力传感器读数
</summary>
<returns>出力,%</returns>
</member>
<member name="M:Neotel.Rmaxis.GetVelocity">
<summary>
获取当前电机速度
......
2ae0cbbcb54252e6c6a2315981efabe3ced705a1
541b02af5647151dc4ab4cd2a95ce05d8d992950
......@@ -15,3 +15,20 @@ C:\Neotel\Program_Beta\Rmaxis\Test\bin\Debug\log4net.dll
C:\Neotel\Program_Beta\Rmaxis\Test\bin\Debug\log4net.xml
C:\Neotel\Program_Beta\Rmaxis\Test\bin\Debug\log4net.config
C:\Neotel\Program_Beta\Rmaxis\Test\bin\Debug\Neotel.Rmaxis.xml
C:\Neotel\Program\Rmaxis\Test\bin\Debug\log4net.config
C:\Neotel\Program\Rmaxis\Test\bin\Debug\Test.exe.config
C:\Neotel\Program\Rmaxis\Test\bin\Debug\Test.exe
C:\Neotel\Program\Rmaxis\Test\bin\Debug\Test.pdb
C:\Neotel\Program\Rmaxis\Test\bin\Debug\log4net.dll
C:\Neotel\Program\Rmaxis\Test\bin\Debug\Neotel.Rmaxis.dll
C:\Neotel\Program\Rmaxis\Test\bin\Debug\Neotel.Rmaxis.pdb
C:\Neotel\Program\Rmaxis\Test\bin\Debug\Neotel.Rmaxis.xml
C:\Neotel\Program\Rmaxis\Test\bin\Debug\log4net.xml
C:\Neotel\Program\Rmaxis\Test\obj\Debug\Test.csprojAssemblyReference.cache
C:\Neotel\Program\Rmaxis\Test\obj\Debug\Test.FrmMain.resources
C:\Neotel\Program\Rmaxis\Test\obj\Debug\Test.Properties.Resources.resources
C:\Neotel\Program\Rmaxis\Test\obj\Debug\Test.csproj.GenerateResource.cache
C:\Neotel\Program\Rmaxis\Test\obj\Debug\Test.csproj.CoreCompileInputs.cache
C:\Neotel\Program\Rmaxis\Test\obj\Debug\Test.csproj.CopyComplete
C:\Neotel\Program\Rmaxis\Test\obj\Debug\Test.exe
C:\Neotel\Program\Rmaxis\Test\obj\Debug\Test.pdb
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!