Commit 0eb61213 几米阳光

增加盘尺寸错误检测。增加压紧轴点动

1 个父辈 474ee95a
......@@ -49,6 +49,11 @@
this.label5 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.txtComPosition = new System.Windows.Forms.TextBox();
this.btnComMovej = new System.Windows.Forms.Button();
this.btnComMove = new System.Windows.Forms.Button();
this.txtComSpeed = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
......@@ -167,7 +172,7 @@
//
// button1
//
this.button1.Location = new System.Drawing.Point(402, 253);
this.button1.Location = new System.Drawing.Point(401, 336);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(126, 37);
this.button1.TabIndex = 16;
......@@ -219,11 +224,61 @@
this.timer1.Interval = 2000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// txtComPosition
//
this.txtComPosition.Location = new System.Drawing.Point(551, 240);
this.txtComPosition.Name = "txtComPosition";
this.txtComPosition.Size = new System.Drawing.Size(108, 23);
this.txtComPosition.TabIndex = 26;
//
// btnComMovej
//
this.btnComMovej.Location = new System.Drawing.Point(401, 235);
this.btnComMovej.Name = "btnComMovej";
this.btnComMovej.Size = new System.Drawing.Size(131, 36);
this.btnComMovej.TabIndex = 25;
this.btnComMovej.Text = "压紧轴-(向下)";
this.btnComMovej.UseVisualStyleBackColor = true;
this.btnComMovej.MouseDown += new System.Windows.Forms.MouseEventHandler(this.btnComMovej_MouseDown);
this.btnComMovej.MouseUp += new System.Windows.Forms.MouseEventHandler(this.btnComMovej_MouseUp);
//
// btnComMove
//
this.btnComMove.Location = new System.Drawing.Point(266, 235);
this.btnComMove.Name = "btnComMove";
this.btnComMove.Size = new System.Drawing.Size(131, 36);
this.btnComMove.TabIndex = 24;
this.btnComMove.Text = "压紧轴+(向上)";
this.btnComMove.UseVisualStyleBackColor = true;
this.btnComMove.MouseDown += new System.Windows.Forms.MouseEventHandler(this.btnComMove_MouseDown);
this.btnComMove.MouseUp += new System.Windows.Forms.MouseEventHandler(this.btnComMove_MouseUp);
//
// txtComSpeed
//
this.txtComSpeed.Location = new System.Drawing.Point(150, 240);
this.txtComSpeed.Name = "txtComSpeed";
this.txtComSpeed.Size = new System.Drawing.Size(108, 23);
this.txtComSpeed.TabIndex = 23;
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(39, 242);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(92, 17);
this.label4.TabIndex = 22;
this.label4.Text = "(轴四)压紧轴";
//
// FrmAxisDebug
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(707, 318);
this.ClientSize = new System.Drawing.Size(707, 413);
this.Controls.Add(this.txtComPosition);
this.Controls.Add(this.btnComMovej);
this.Controls.Add(this.btnComMove);
this.Controls.Add(this.txtComSpeed);
this.Controls.Add(this.label4);
this.Controls.Add(this.label6);
this.Controls.Add(this.label5);
this.Controls.Add(this.txtInOutPosition);
......@@ -275,5 +330,10 @@
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.TextBox txtComPosition;
private System.Windows.Forms.Button btnComMovej;
private System.Windows.Forms.Button btnComMove;
private System.Windows.Forms.TextBox txtComSpeed;
private System.Windows.Forms.Label label4;
}
}
\ No newline at end of file
......@@ -30,11 +30,10 @@ namespace OnlineStore.ACSingleStore
{
middle = boxBean.Config.Middle_Axis;
updown = boxBean.Config.UpDown_Axis;
//compress_Slv = boxBean.Config.CompressAxis_Slv;
compress_Slv = boxBean.Config.CompressAxis_Slv;
inout = boxBean.Config.InOut_Axis;
InitializeComponent();
//txtComSpeed.Text = boxBean.Config.CompressAxis_EndSpeed.ToString();
txtComSpeed.Text = boxBean.Config.CompressAxis_EndSpeed.ToString();
this.Text = boxBean.StoreName + "_轴点动调试";
}
......@@ -49,6 +48,7 @@ namespace OnlineStore.ACSingleStore
txtMiddleSpeed.Text = middle.TargetSpeed.ToString();
txtInOutSpeed.Text = inout.TargetSpeed.ToString();
txtUpDownSpeed.Text = updown.TargetSpeed.ToString();
txtComSpeed.Text = ACStoreManager.store.Config.CompressAxis_EndSpeed.ToString();
timer1.Start();
}
......@@ -123,30 +123,7 @@ namespace OnlineStore.ACSingleStore
}
}
//private void btnComMove_MouseDown(object sender, MouseEventArgs e)
//{
// int speed = FormUtil.GetIntValue(txtComSpeed);
// if (speed <= 0)
// {
// MessageBox.Show("提示", "请先输入正确的速度");
// return;
// }
// this.btnComMove.BackColor = Color.Green;
// ShuoKeControls.SetSpeed(compress_Slv, ShuoKeCMD.SetEndSpeed, speed);
// ShuoKeControls.SetSpeed(compress_Slv, ShuoKeCMD.SetMaxSpeed, speed);
// ShuoKeControls.VolMove(compress_Slv, speed);
//}
//private void btnComMove_MouseUp(object sender, MouseEventArgs e)
//{
// if (this.btnComMove.BackColor == Color.Green)
// {
// btnComMove.BackColor = System.Drawing.SystemColors.Control;
// //ACServerManager.SuddenStop(compress.DeviceName, compress.GetAxisValue());
// ShuoKeControls.SuddownStop(compress_Slv);
// }
//}
private void btnMiddleMovej_MouseDown(object sender, MouseEventArgs e)
{
......@@ -218,30 +195,53 @@ namespace OnlineStore.ACSingleStore
UpdateInOutPosition();
}
}
private void btnComMove_MouseDown(object sender, MouseEventArgs e)
{
int speed = FormUtil.GetIntValue(txtComSpeed);
if (speed <= 0)
{
MessageBox.Show("提示", "请先输入正确的速度");
return;
}
this.btnComMove.BackColor = Color.Green;
//private void btnComMovej_MouseDown(object sender, MouseEventArgs e)
//{
// int speed = FormUtil.GetIntValue(txtComSpeed);
// if (speed <= 0)
// {
// MessageBox.Show("提示", "请先输入正确的速度");
// return;
// }
// this.btnComMovej.BackColor = Color.Green;
// //AxisMove(compress, -speed);
// ShuoKeControls.SetSpeed(compress_Slv, ShuoKeCMD.SetEndSpeed, speed);
// ShuoKeControls.SetSpeed(compress_Slv, ShuoKeCMD.SetMaxSpeed, speed);
// ShuoKeControls.VolMove(compress_Slv, speed);
//}
ShuoKeControls.SetSpeed(compress_Slv, ShuoKeCMD.SetEndSpeed, speed);
ShuoKeControls.SetSpeed(compress_Slv, ShuoKeCMD.SetMaxSpeed, speed);
ShuoKeControls.VolMove(compress_Slv, speed);
}
//private void btnComMovej_MouseUp(object sender, MouseEventArgs e)
//{
// if (btnComMovej.BackColor.Equals(Color.Green))
// {
// btnComMovej.BackColor = System.Drawing.SystemColors.Control;
// ShuoKeControls.SuddownStop(compress_Slv);
// }
//}
private void btnComMove_MouseUp(object sender, MouseEventArgs e)
{
if (this.btnComMove.BackColor == Color.Green)
{
btnComMove.BackColor = System.Drawing.SystemColors.Control;
ShuoKeControls.SuddownStop(compress_Slv);
ShuoKeControls.GetABSPosition(compress_Slv);
}
}
private void btnComMovej_MouseDown(object sender, MouseEventArgs e)
{
int speed = FormUtil.GetIntValue(txtComSpeed);
if (speed <= 0)
{
MessageBox.Show("提示", "请先输入正确的速度");
return;
}
this.btnComMovej.BackColor = Color.Green;
ShuoKeControls.SetSpeed(compress_Slv, ShuoKeCMD.SetEndSpeed, speed);
ShuoKeControls.SetSpeed(compress_Slv, ShuoKeCMD.SetMaxSpeed, speed);
ShuoKeControls.VolMove(compress_Slv,-speed);
}
private void btnComMovej_MouseUp(object sender, MouseEventArgs e)
{
if (btnComMovej.BackColor.Equals(Color.Green))
{
btnComMovej.BackColor = System.Drawing.SystemColors.Control;
ShuoKeControls.SuddownStop(compress_Slv);
ShuoKeControls.GetABSPosition(compress_Slv);
}
}
private void button1_Click(object sender, EventArgs e)
{
......@@ -261,6 +261,7 @@ namespace OnlineStore.ACSingleStore
UpdateMiddlePosition();
UpdateInOutPosition();
UpdateUpdownPosition();
txtComPosition.Text = ShuoKeControls.GetLastPosition(compress_Slv).ToString();
}
}
......
......@@ -931,13 +931,14 @@ namespace OnlineStore.ACSingleStore
{
store.KNDIOMove(IO_Type.CameraLight_Power, IO_VALUE.HIGH);
string message = "";
List<string> codeList = HDevelopExport.CameraScan();
string outMsg = "";
List<string> codeList = HDevelopExport.CameraScan(out outMsg);
foreach (string str in codeList)
{
string code = HDevelopExport.SubStrCode(str);
message = message + code + "##";
}
LogUtil.info("扫码测试收到二维码:" + message);
LogUtil.info("扫码测试收到二维码【"+outMsg+"】:" + message);
store.KNDIOMove(IO_Type.CameraLight_Power, IO_VALUE.LOW);
}
......@@ -1227,11 +1228,13 @@ namespace OnlineStore.ACSingleStore
private void 学习二维码ToolStripMenuItem_Click(object sender, EventArgs e)
{
store.KNDIOMove(IO_Type.CameraLight_Power, IO_VALUE.HIGH);
string nameStr = ConfigAppSettings.GetValue(Setting_Init.CameraName);
string codeStr = ConfigAppSettings.GetValue(Setting_Init.CodeType);
HDCodeLearnHelper.LoadConfig(nameStr, codeStr);
FrmCodeLearn learn = new FrmCodeLearn();
learn.ShowDialog();
store.KNDIOMove(IO_Type.CameraLight_Power, IO_VALUE.LOW);
}
private void btnReadHomeSingle_Click(object sender, EventArgs e)
......
......@@ -137,6 +137,7 @@ namespace OnlineStore.DeviceLibrary
ShuoKeInfo info = new ShuoKeInfo(isInMove, slvAddr, isLLimit, isOrg, isRLimit, isEn);
if (shuokeMap.ContainsKey(slvAddr))
{
info.LastPosition = shuokeMap[slvAddr].LastPosition;
shuokeMap.Remove(slvAddr);
}
shuokeMap.Add(slvAddr, info);
......@@ -154,8 +155,28 @@ namespace OnlineStore.DeviceLibrary
string a = SerialBean.byteToHexStr(positionData);
int absValue = Convert.ToInt32(a, 16);
LogUtil.info(LOGGER, "收到驱动器【" + slvAddr + "】绝对位置【" + absValue + "】");
if (shuokeMap.ContainsKey(slvAddr))
{
shuokeMap[slvAddr].LastPosition=absValue;
}
else
{
ShuoKeInfo info = new ShuoKeInfo(slvAddr, absValue);
shuokeMap.Add(slvAddr, info);
}
}
}
public static int GetLastPosition(int slvAddr)
{
if (shuokeMap.ContainsKey(slvAddr))
{
ShuoKeInfo info = shuokeMap[slvAddr];
return info.LastPosition;
}
return -1;
}
#endregion
#region 流水线逻辑判断
......@@ -414,6 +435,17 @@ namespace OnlineStore.DeviceLibrary
public class ShuoKeInfo
{
public ShuoKeInfo(int slv,int position)
{
this.IsInMove = 0 ;
this.SlvAddr = slv;
this.LLimit = 0;
this.RLimit = 0;
this.Org = 0;
this.En = 0;
UpdateTime = DateTime.Now;
LastPosition = position;
}
public ShuoKeInfo(int ismove, int slv, int ll, int org, int rl, int en)
{
this.IsInMove = ismove;
......@@ -423,7 +455,9 @@ namespace OnlineStore.DeviceLibrary
this.Org=org;
this.En=en;
UpdateTime=DateTime.Now;
LastPosition = 0;
}
public int LastPosition { get; set; }
/// <summary>
/// 驱动器地址
/// </summary>
......
......@@ -1321,17 +1321,22 @@ namespace OnlineStore.DeviceLibrary
DateTime date = DateTime.Now;
scanTimer.Enabled = false;
KNDIOMove(IO_Type.CameraLight_Power, IO_VALUE.HIGH);
string outMsg = "";
string message = "";
List<string> codeList = HDevelopExport.CameraScan();
List<string> codeList = HDevelopExport.CameraScan(out outMsg);
//= 1 + 123.4x100.5 - 7x12 = CODE
foreach (string str in codeList)
{
string code = HDevelopExport.SubStrCode(str);
code = "=7X"+height+" =" + code;
code = "=7X" + height + " =" + code;
message = message + code + spiltStr;
}
if (!outMsg.Equals(""))
{
LogUtil.error("盘尺寸错误,清理二维码【"+message+"】");
message = "";
}
KNDIOMove(IO_Type.CameraLight_Power, IO_VALUE.LOW);
onCodeReceived(message);
......
......@@ -2,10 +2,13 @@
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace OnlineStore.DeviceLibrary
......@@ -56,10 +59,10 @@ namespace OnlineStore.DeviceLibrary
/// 扫取二维码,会打开摄像机,正常情况下不关闭摄像机
/// </summary>
/// <returns></returns>
public static List<string> CameraScan()
public static List<string> CameraScan(out string msg)
{
List<string> allCodeList = new List<string>();
msg = "";
try
{
//HDevelopExport.CloseAllCamera();
......@@ -70,6 +73,24 @@ namespace OnlineStore.DeviceLibrary
{
HObject ho_Image = HDevelopExport.GrabImage(cameraName);
List<string> codeList = HDevelopExport.GetCode(ho_Image);
if (codeList.Count > 0)
{
Bitmap bitmap = HObject2Bpp24(ho_Image);
//DateTime time = DateTime.Now;
//try
//{
// string name = time.Hour.ToString() + time.Minute.ToString() + time.Second.ToString() + time.Millisecond.ToString() + ".jpg";
// bitmap.Save(name);
//}
//catch(Exception ex)
//{
//}
if (Exist(bitmap))
{
msg = "盘尺寸错误";
LogUtil.error("盘尺寸错误!");
}
}
allCodeList.AddRange(codeList);
}
}
......@@ -81,7 +102,76 @@ namespace OnlineStore.DeviceLibrary
}
return allCodeList;
}
/// <summary>
/// 料盘是否存在,true在,false不在
/// </summary>
/// <param name="bmp"></param>
/// <returns></returns>
private static bool Exist(Bitmap bmp)
{
//8个点,距离边界1/10
Point[] pt = new Point[8];
int w = bmp.Width / 10;
int h = bmp.Height / 10;
pt[0] = new Point(10, 20); //左上1
pt[1] = new Point(20, 10); //左上2
pt[2] = new Point(bmp.Width - 10, 20); //右上1
pt[3] = new Point(bmp.Width - 20, 10); //右上2
pt[4] = new Point(10, bmp.Height - 20); //左下1
pt[5] = new Point(20, bmp.Height - 10); //左下2
pt[6] = new Point(bmp.Width - 10, bmp.Height - 20); //右下1
pt[7] = new Point(bmp.Width - 20, bmp.Height - 10); //右下2
//数量
int count = 0;
//颜色的范围,小于即不存在
Color range = Color.FromArgb(50, 50, 50);
for (int i = 0; i < pt.Length; i++)
{
Color cc = bmp.GetPixel(pt[i].X, pt[i].Y);
if (cc.R < range.R && cc.G < range.G && cc.B < range.B)
count++;
}
if (count >= 7) //满7个即可
return false;
else
return true;
}
public static Bitmap HObject2Bpp24(HObject image)
{
Bitmap res = null;
try
{
HTuple hred, hgreen, hblue, type, width, height;
HOperatorSet.GetImagePointer3(image, out hred, out hgreen, out hblue, out type, out width, out height);
res = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
Rectangle rect = new Rectangle(0, 0, width, height);
BitmapData bitmapData = res.LockBits(rect, ImageLockMode.ReadWrite, PixelFormat.Format32bppRgb);
unsafe
{
byte* bptr = (byte*)bitmapData.Scan0;
byte* r = ((byte*)hred.I);
byte* g = ((byte*)hgreen.I);
byte* b = ((byte*)hblue.I);
for (int i = 0; i < width * height; i++)
{
bptr[i * 4] = (b)[i];
bptr[i * 4 + 1] = (g)[i];
bptr[i * 4 + 2] = (r)[i];
bptr[i * 4 + 3] = 255;
}
}
res.UnlockBits(bitmapData);
}catch(Exception ex)
{
LogUtil.info("Hobject to BitMap 出错"+ex.ToString());
}
return res;
}
public static List<string> GetCode(HObject ho_Image, string symbolType)
{
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!