Commit 413b0ee4 刘韬

添加超声波测高

1 个父辈 9271efd9
......@@ -162,7 +162,7 @@
this.txtDOIndex.Location = new System.Drawing.Point(82, 53);
this.txtDOIndex.MaxLength = 10;
this.txtDOIndex.Name = "txtDOIndex";
this.txtDOIndex.Size = new System.Drawing.Size(66, 27);
this.txtDOIndex.Size = new System.Drawing.Size(66, 23);
this.txtDOIndex.TabIndex = 242;
this.txtDOIndex.Text = "0";
//
......@@ -183,7 +183,7 @@
this.txtWriteTime.Location = new System.Drawing.Point(240, 52);
this.txtWriteTime.MaxLength = 10;
this.txtWriteTime.Name = "txtWriteTime";
this.txtWriteTime.Size = new System.Drawing.Size(66, 27);
this.txtWriteTime.Size = new System.Drawing.Size(66, 23);
this.txtWriteTime.TabIndex = 238;
this.txtWriteTime.Text = "0";
//
......@@ -207,7 +207,7 @@
this.cmbWriteIO.FormattingEnabled = true;
this.cmbWriteIO.Location = new System.Drawing.Point(16, 19);
this.cmbWriteIO.Name = "cmbWriteIO";
this.cmbWriteIO.Size = new System.Drawing.Size(296, 28);
this.cmbWriteIO.Size = new System.Drawing.Size(296, 24);
this.cmbWriteIO.TabIndex = 234;
this.cmbWriteIO.ValueMember = "ProName";
this.cmbWriteIO.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.cmbWriteIO_DrawItem);
......@@ -242,6 +242,7 @@
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(144, 34);
this.button1.TabIndex = 254;
this.button1.Tag = "关闭";
this.button1.Text = "关闭";
this.button1.UseVisualStyleBackColor = true;
this.button1.Visible = false;
......@@ -254,10 +255,11 @@
this.chbAutoRead.Checked = true;
this.chbAutoRead.CheckState = System.Windows.Forms.CheckState.Checked;
this.chbAutoRead.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.chbAutoRead.Location = new System.Drawing.Point(498, 598);
this.chbAutoRead.Location = new System.Drawing.Point(742, 601);
this.chbAutoRead.Name = "chbAutoRead";
this.chbAutoRead.Size = new System.Drawing.Size(91, 24);
this.chbAutoRead.Size = new System.Drawing.Size(75, 21);
this.chbAutoRead.TabIndex = 244;
this.chbAutoRead.Tag = "自动读取";
this.chbAutoRead.Text = "自动读取";
this.chbAutoRead.UseVisualStyleBackColor = true;
this.chbAutoRead.Visible = false;
......@@ -349,7 +351,7 @@
this.txtAIResult4.Location = new System.Drawing.Point(203, 112);
this.txtAIResult4.MaxLength = 10;
this.txtAIResult4.Name = "txtAIResult4";
this.txtAIResult4.Size = new System.Drawing.Size(121, 27);
this.txtAIResult4.Size = new System.Drawing.Size(121, 23);
this.txtAIResult4.TabIndex = 259;
this.txtAIResult4.Text = "0";
//
......@@ -360,7 +362,7 @@
this.txtAI4.Location = new System.Drawing.Point(39, 112);
this.txtAI4.MaxLength = 10;
this.txtAI4.Name = "txtAI4";
this.txtAI4.Size = new System.Drawing.Size(121, 27);
this.txtAI4.Size = new System.Drawing.Size(121, 23);
this.txtAI4.TabIndex = 258;
this.txtAI4.Text = "0";
//
......@@ -371,7 +373,7 @@
this.label_s4.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
this.label_s4.Location = new System.Drawing.Point(15, 115);
this.label_s4.Name = "label_s4";
this.label_s4.Size = new System.Drawing.Size(33, 20);
this.label_s4.Size = new System.Drawing.Size(27, 17);
this.label_s4.TabIndex = 257;
this.label_s4.Text = "4:";
this.label_s4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
......@@ -383,7 +385,7 @@
this.txtSize.Location = new System.Drawing.Point(263, 156);
this.txtSize.MaxLength = 10;
this.txtSize.Name = "txtSize";
this.txtSize.Size = new System.Drawing.Size(59, 27);
this.txtSize.Size = new System.Drawing.Size(59, 23);
this.txtSize.TabIndex = 256;
this.txtSize.Text = "0";
//
......@@ -405,7 +407,7 @@
this.txtHeight.Location = new System.Drawing.Point(99, 156);
this.txtHeight.MaxLength = 10;
this.txtHeight.Name = "txtHeight";
this.txtHeight.Size = new System.Drawing.Size(59, 27);
this.txtHeight.Size = new System.Drawing.Size(59, 23);
this.txtHeight.TabIndex = 254;
this.txtHeight.Text = "0";
//
......@@ -427,7 +429,7 @@
this.label8arr.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
this.label8arr.Location = new System.Drawing.Point(170, 56);
this.label8arr.Name = "label8arr";
this.label8arr.Size = new System.Drawing.Size(26, 20);
this.label8arr.Size = new System.Drawing.Size(22, 17);
this.label8arr.TabIndex = 252;
this.label8arr.Text = "->";
this.label8arr.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
......@@ -439,7 +441,7 @@
this.txtAIResult3.Location = new System.Drawing.Point(203, 82);
this.txtAIResult3.MaxLength = 10;
this.txtAIResult3.Name = "txtAIResult3";
this.txtAIResult3.Size = new System.Drawing.Size(121, 27);
this.txtAIResult3.Size = new System.Drawing.Size(121, 23);
this.txtAIResult3.TabIndex = 251;
this.txtAIResult3.Text = "0";
//
......@@ -450,7 +452,7 @@
this.txtAIResult2.Location = new System.Drawing.Point(203, 53);
this.txtAIResult2.MaxLength = 10;
this.txtAIResult2.Name = "txtAIResult2";
this.txtAIResult2.Size = new System.Drawing.Size(121, 27);
this.txtAIResult2.Size = new System.Drawing.Size(121, 23);
this.txtAIResult2.TabIndex = 250;
this.txtAIResult2.Text = "0";
//
......@@ -461,7 +463,7 @@
this.txtAIResult1.Location = new System.Drawing.Point(203, 24);
this.txtAIResult1.MaxLength = 10;
this.txtAIResult1.Name = "txtAIResult1";
this.txtAIResult1.Size = new System.Drawing.Size(121, 27);
this.txtAIResult1.Size = new System.Drawing.Size(121, 23);
this.txtAIResult1.TabIndex = 249;
this.txtAIResult1.Text = "0";
//
......@@ -472,7 +474,7 @@
this.txtAI3.Location = new System.Drawing.Point(39, 82);
this.txtAI3.MaxLength = 10;
this.txtAI3.Name = "txtAI3";
this.txtAI3.Size = new System.Drawing.Size(121, 27);
this.txtAI3.Size = new System.Drawing.Size(121, 23);
this.txtAI3.TabIndex = 248;
this.txtAI3.Text = "0";
//
......@@ -483,7 +485,7 @@
this.label_s3.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
this.label_s3.Location = new System.Drawing.Point(15, 85);
this.label_s3.Name = "label_s3";
this.label_s3.Size = new System.Drawing.Size(33, 20);
this.label_s3.Size = new System.Drawing.Size(27, 17);
this.label_s3.TabIndex = 247;
this.label_s3.Text = "3:";
this.label_s3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
......@@ -495,7 +497,7 @@
this.txtAI2.Location = new System.Drawing.Point(39, 53);
this.txtAI2.MaxLength = 10;
this.txtAI2.Name = "txtAI2";
this.txtAI2.Size = new System.Drawing.Size(121, 27);
this.txtAI2.Size = new System.Drawing.Size(121, 23);
this.txtAI2.TabIndex = 246;
this.txtAI2.Text = "0";
//
......@@ -506,7 +508,7 @@
this.label_s2.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
this.label_s2.Location = new System.Drawing.Point(15, 56);
this.label_s2.Name = "label_s2";
this.label_s2.Size = new System.Drawing.Size(33, 20);
this.label_s2.Size = new System.Drawing.Size(27, 17);
this.label_s2.TabIndex = 245;
this.label_s2.Text = "2:";
this.label_s2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
......@@ -518,7 +520,7 @@
this.txtAI1.Location = new System.Drawing.Point(39, 24);
this.txtAI1.MaxLength = 10;
this.txtAI1.Name = "txtAI1";
this.txtAI1.Size = new System.Drawing.Size(121, 27);
this.txtAI1.Size = new System.Drawing.Size(121, 23);
this.txtAI1.TabIndex = 244;
this.txtAI1.Text = "0";
//
......@@ -529,16 +531,16 @@
this.label_s1.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
this.label_s1.Location = new System.Drawing.Point(15, 27);
this.label_s1.Name = "label_s1";
this.label_s1.Size = new System.Drawing.Size(33, 20);
this.label_s1.Size = new System.Drawing.Size(27, 17);
this.label_s1.TabIndex = 243;
this.label_s1.Text = "1:";
this.label_s1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// FrmIOStatus
//
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(708, 525);
this.ClientSize = new System.Drawing.Size(936, 525);
this.Controls.Add(this.button1);
this.Controls.Add(this.groupBoxHighState);
this.Controls.Add(this.groupBoxDowrite);
......
......@@ -217,10 +217,10 @@ namespace OnlineStore.ACSingleStore
}
}
double ai1Value = IOManager.GetADIOValue(StoreManager.Config.AIDI1_Addr);
double ai2Value = IOManager.GetADIOValue(StoreManager.Config.AIDI2_Addr);
double ai3Value = IOManager.GetADIOValue(StoreManager.Config.AIDI3_Addr);
double ai4Value = IOManager.GetADIOValue(StoreManager.Config.AIDI4_Addr);
double ai1Value = StoreManager.Store.GetADIO(1);
double ai2Value = StoreManager.Store.GetADIO(2);
double ai3Value = StoreManager.Store.GetADIO(3);
double ai4Value = StoreManager.Store.GetADIO(4);
//double ai3Value = AIManager.Instance.GetAIValue(boxBean.Config.AIDevice_IP, 3);
txtAI1.Text = ai1Value.ToString();
......
......@@ -9,7 +9,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SO951-HC-ACSingleStore 84085011622eb8df3361eb4caec4c3cefe70c3dd")]
[assembly: AssemblyProduct("SO951-HC-ACSingleStore 9271efd95f69f82cbe1d3a623766be8cb61e7974")]
[assembly: AssemblyCopyright("Copyright ? 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
......
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
public class DauxiKS107Controller
{
private static int baudRate =9600;//波特率
private static Parity parity = Parity.None;//校验位
private static int dataBits = 8;//数据位
private static StopBits stopBits = StopBits.One; //停止位
private SerialPort _serialPort = null;
string comPortName;
System.Timers.Timer timer;
public int Distance;
public bool IsRunning { get => timer.Enabled; }
public DauxiKS107Controller(int Elapsms=5000)
{
timer = new System.Timers.Timer(Elapsms);
timer.Elapsed += Timer_Elapsed;
timer.AutoReset = true;
timer.Enabled = false;
}
~DauxiKS107Controller() {
LogUtil.info($"液位传感器退出");
timer.Enabled = false;
if (_serialPort != null) {
_serialPort.Close();
}
}
private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
bool readok = true;
for (int i = 0; i < 5; i++)
{
if (Quary(out int value, out string errmsg))
{
Debug.WriteLine($"读取到液位:{value}mm,err:{errmsg}");
readok = true;
if (value > 0)
{
Distance = value;
return;
}
}
else {
readok = false;
}
}
if (!readok)
{
LogUtil.info($"液位传感器读取失败,重新打开");
if (!OpenPort(comPortName, out string errmsg)) {
LogUtil.info($"液位传感器打开失败:"+ errmsg);
}
}
}
/// <summary>
/// 打开串口资源
/// <returns>返回bool类型</returns>
/// </summary>
public bool OpenPort(string _comport,out string errmsg)
{
comPortName = _comport;
//如果串口是打开的,先关闭
if (_serialPort == null)
{
_serialPort = new SerialPort(comPortName, baudRate, parity, dataBits, stopBits);
_serialPort.RtsEnable = true; //自动请求
_serialPort.ReadTimeout = 100;//超时
}
if (_serialPort.IsOpen)
_serialPort.Close();
errmsg = "";
bool ok = false;
try
{
//打开串口
_serialPort.Open();
for (int i = 1; i < 10; i++) {
Thread.Sleep(100);
Quary(out int value, out _);
if (value > 0)
{
timer.Enabled = true;
ok = true;
break;
}
}
}
catch (Exception Ex)
{
errmsg = Ex.ToString();
//throw Ex;
}
return ok;
}
static byte[] quarycommand = new byte[] { 0xe8, 0x02, 0xb0 };
public bool Quary(out int value, out string errmsg) {
errmsg = "";
byte[] buf = new byte[8];
value = 0;
try
{
_serialPort.Write(quarycommand, 0, quarycommand.Length);
Thread.Sleep(10);
var readlen = _serialPort.Read(buf, 0, buf.Length);
if (readlen >= 2)
{
var c = new byte[] { buf[1], buf[0] };
value = (int)BitConverter.ToUInt16(c, 0);
}
else
{
errmsg = "返回数据不正确:"+BitConverter.ToString(buf);
return false;
}
}
catch (Exception ex){
errmsg = ex.ToString();
return false;
}
return true;
}
}
......@@ -70,10 +70,12 @@
</ItemGroup>
<ItemGroup>
<Compile Include="acSingleStore\AC_SA_BoxBean.cs" />
<Compile Include="acSingleStore\AC_SA_BoxBean_ADIO.cs" />
<Compile Include="acSingleStore\AC_SA_BoxBean_Partial.cs" />
<Compile Include="acSingleStore\DoorControl.cs" />
<Compile Include="acSingleStore\StoreManager.cs" />
<Compile Include="dataLogic\DLScanSocket.cs" />
<Compile Include="DauxiKS107Controller.cs" />
<Compile Include="halcon\CodeManager.cs" />
<Compile Include="IO\HCIOManager.cs" />
<Compile Include="IO\IOManager.cs" />
......
......@@ -125,6 +125,8 @@ PRO,模拟信号4的地址(15寸高度),AIDI4_Addr,3,,,,,,
,,,,,,,,,
PRO,模拟转换系数,AI_ConvertPosition,62,,,,,,
,,,,,,,,,
PRO,超声波测距1端口,Ultrasonic1_Port,COM3,,,,,,
,,,,,,,,,
PRO,默认的料盘宽度(多种尺寸为0),Default_TrayWidth,0,,,,,,
PRO,特殊二维码尺寸配置,CodeSizeConfig,XA=13x48#XB=13x32,,,,,,
PRO,扫码枪IP,Scanner_Ip,0,,,,,,
......
......@@ -52,7 +52,7 @@ namespace OnlineStore.DeviceLibrary
private System.Timers.Timer IoCheckTimer = new System.Timers.Timer();
private int OutStoreWaitSeconds = ConfigAppSettings.GetIntValue(Setting_Init.OutStoreWaitSeconds);
public static DauxiKS107Controller Ultrasonic1 = new DauxiKS107Controller(300);
public AC_SA_BoxBean(AC_SA_Config config)
{
......@@ -111,7 +111,16 @@ namespace OnlineStore.DeviceLibrary
if (!IOManager.instance.ConnectionIOList(Config.DIODeviceNameList))
{
SetWarnMsg(ResourceControl.CustAlarm,"EtherCat PCI Card Open Fail.");
LogUtil.error(StoreName + "EtherCat PCI Card Open Fail.");
return;
}
LogUtil.info(StoreName + "Ultrasonic1_Port:"+ Config.Ultrasonic1_Port);
if (!string.IsNullOrWhiteSpace(Config.Ultrasonic1_Port) && !Ultrasonic1.OpenPort(Config.Ultrasonic1_Port, out string errmsg)){
SetWarnMsg(ResourceControl.CustAlarm, errmsg);
LogUtil.error(StoreName + errmsg);
return;
}
mainTimer.Enabled = false;
......@@ -1810,8 +1819,8 @@ namespace OnlineStore.DeviceLibrary
{
return result;
}
double ai1Value = ConvertAI(IOManager.GetADIOValue(Config.AIDI1_Addr), Config.AIDI1_DefaultPosition);
double ai2Value = ConvertAI(IOManager.GetADIOValue(Config.AIDI2_Addr), Config.AIDI2_DefaultPosition);
double ai1Value = ConvertAI(StoreManager.Store.GetADIO(1), Config.AIDI1_DefaultPosition);
double ai2Value = ConvertAI(StoreManager.Store.GetADIO(2), Config.AIDI2_DefaultPosition);
double Value = 0;
if (ai1Value > 5 && ai2Value > 5)
Value=Math.Round((ai1Value + ai2Value) / 2, 1);
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OnlineStore.DeviceLibrary
{
partial class AC_SA_BoxBean
{
public double GetADIO(int index) {
switch (index)
{
case 1:
if (Ultrasonic1.IsRunning)
return Ultrasonic1.Distance;
else
return IOManager.GetADIOValue(StoreManager.Config.AIDI1_Addr);
case 2:
return IOManager.GetADIOValue(StoreManager.Config.AIDI2_Addr);
case 3:
return IOManager.GetADIOValue(StoreManager.Config.AIDI3_Addr);
case 4:
return IOManager.GetADIOValue(StoreManager.Config.AIDI4_Addr);
default:
return -1;
}
}
}
}
......@@ -557,6 +557,11 @@ namespace OnlineStore.LoadCSVLibrary
/// </summary>
[ConfigProAttribute("MiddleAxis_Reverse_Offset")]
public int MiddleAxis_Reverse_Offset { get; set; }
/// <summary>
/// PRO 超声波测距1端口 Ultrasonic1_Port
/// </summary>
[ConfigProAttribute("Ultrasonic1_Port")]
public string Ultrasonic1_Port { get; set; }
/// <summary>
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!