Commit 0bb8f3ac LN

折叠门增加提示音

1 个父辈 0fae4079
...@@ -180,6 +180,8 @@ namespace OnlineStore.Common ...@@ -180,6 +180,8 @@ namespace OnlineStore.Common
[MyConfigComment("启用上传监控图像给SMF")] [MyConfigComment("启用上传监控图像给SMF")]
public static MyConfig<bool> Enable_UploadVideo = false; public static MyConfig<bool> Enable_UploadVideo = false;
[MyConfigComment("启用折叠门提示音")]
public static MyConfig<bool> Enable_DoorSound = true;
[MyConfigComment("压紧轴回原失败重试最大次数")] [MyConfigComment("压紧轴回原失败重试最大次数")]
public static MyConfig<int> Comp_Axis_HomeResetTimes = 999; public static MyConfig<int> Comp_Axis_HomeResetTimes = 999;
......
...@@ -118,6 +118,7 @@ ...@@ -118,6 +118,7 @@
<Compile Include="DeviceLibrary\I_IOManager.cs" /> <Compile Include="DeviceLibrary\I_IOManager.cs" />
<Compile Include="DeviceLibrary\IOManager.cs" /> <Compile Include="DeviceLibrary\IOManager.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="theMachine\SoundsController.cs" />
<Compile Include="userControl\AxisMoveControl.cs"> <Compile Include="userControl\AxisMoveControl.cs">
<SubType>UserControl</SubType> <SubType>UserControl</SubType>
</Compile> </Compile>
......
...@@ -28,7 +28,8 @@ namespace DeviceLibrary ...@@ -28,7 +28,8 @@ namespace DeviceLibrary
int StrokeLength = 270000; int StrokeLength = 270000;
MoveInfo moveInfo1; MoveInfo moveInfo1;
bool paused = false; bool paused = false;
public LiftMonitor(string _up, string _down, string _saftylight, string _break, AxisBean _axisBean, int _StrokeLength, int _upspeed, int _downspeed = 0,string name= "升降机构") private bool needPlaySound = false;
public LiftMonitor(string _up, string _down, string _saftylight, string _break, AxisBean _axisBean, int _StrokeLength, int _upspeed, int _downspeed = 0,string name= "升降机构",bool needSound=false )
{ {
moveInfo1 = new MoveInfo(name, false); moveInfo1 = new MoveInfo(name, false);
up = _up; up = _up;
...@@ -43,6 +44,7 @@ namespace DeviceLibrary ...@@ -43,6 +44,7 @@ namespace DeviceLibrary
{ {
downspeed = upspeed; downspeed = upspeed;
} }
this.needPlaySound = needSound;
SafetyDevice.AddDevice(this); SafetyDevice.AddDevice(this);
} }
public void ClearAlarm() public void ClearAlarm()
...@@ -92,6 +94,11 @@ namespace DeviceLibrary ...@@ -92,6 +94,11 @@ namespace DeviceLibrary
IOManager.IOMove(axisbreak, IO_VALUE.HIGH); IOManager.IOMove(axisbreak, IO_VALUE.HIGH);
Thread.Sleep(200); Thread.Sleep(200);
} }
if (needPlaySound)
{
SoundsController.StartOpen();
}
axisBean.RelMove(StrokeLength, speed); axisBean.RelMove(StrokeLength, speed);
DateTime d = DateTime.Now; DateTime d = DateTime.Now;
moveInfo.log($"{axisBean.AxisName},LiftUp"); moveInfo.log($"{axisBean.AxisName},LiftUp");
...@@ -132,6 +139,10 @@ namespace DeviceLibrary ...@@ -132,6 +139,10 @@ namespace DeviceLibrary
axisBean.ServoOff(); axisBean.ServoOff();
} }
if (needPlaySound)
{
SoundsController.StopPlay();
}
var t = (DateTime.Now - d).TotalSeconds; var t = (DateTime.Now - d).TotalSeconds;
moveInfo.log($"{axisBean.AxisName},上升到位,s:{t}"); moveInfo.log($"{axisBean.AxisName},上升到位,s:{t}");
}); });
...@@ -151,6 +162,11 @@ namespace DeviceLibrary ...@@ -151,6 +162,11 @@ namespace DeviceLibrary
IOManager.IOMove(axisbreak, IO_VALUE.LOW); IOManager.IOMove(axisbreak, IO_VALUE.LOW);
axisBean.ServoOff(); axisBean.ServoOff();
} }
if (needPlaySound)
{
SoundsController.StopPlay();
}
return true; return true;
} }
...@@ -189,13 +205,17 @@ namespace DeviceLibrary ...@@ -189,13 +205,17 @@ namespace DeviceLibrary
IOManager.IOMove(axisbreak, IO_VALUE.HIGH); IOManager.IOMove(axisbreak, IO_VALUE.HIGH);
Thread.Sleep(200); Thread.Sleep(200);
} }
if (needPlaySound)
{
SoundsController.StartClose();
}
axisBean.RelMove(-StrokeLength, speed); axisBean.RelMove(-StrokeLength, speed);
DateTime d = DateTime.Now; DateTime d = DateTime.Now;
moveInfo.log($"{axisBean.AxisName},LiftDown"); moveInfo.log($"{axisBean.AxisName},LiftDown");
var wr = WaitResultInfo.WaitAction(new Func<WaitResultInfo, bool>(WaitDown), $"等待顶升[{axisBean.Config.Explain}]机构下降"); var wr = WaitResultInfo.WaitAction(new Func<WaitResultInfo, bool>(WaitDown), $"等待顶升[{axisBean.Config.Explain}]机构下降");
if (moveInfo != null) if (moveInfo != null)
moveInfo.WaitList.Add(wr); moveInfo.WaitList.Add(wr);
Task.Run(() => Task.Run(() =>
{ {
while (!IOManager.IOValue(down.ToString()).Equals(IO_VALUE.HIGH)) while (!IOManager.IOValue(down.ToString()).Equals(IO_VALUE.HIGH))
...@@ -230,6 +250,11 @@ namespace DeviceLibrary ...@@ -230,6 +250,11 @@ namespace DeviceLibrary
IOManager.IOMove(axisbreak, IO_VALUE.LOW); IOManager.IOMove(axisbreak, IO_VALUE.LOW);
axisBean.ServoOff(); axisBean.ServoOff();
} }
if (needPlaySound)
{
SoundsController.StopPlay();
}
var t = (DateTime.Now - d).TotalSeconds; var t = (DateTime.Now - d).TotalSeconds;
moveInfo.log($"{axisBean.AxisName},下降到位,s:{t}"); moveInfo.log($"{axisBean.AxisName},下降到位,s:{t}");
}); });
...@@ -249,6 +274,11 @@ namespace DeviceLibrary ...@@ -249,6 +274,11 @@ namespace DeviceLibrary
IOManager.IOMove(axisbreak, IO_VALUE.LOW); IOManager.IOMove(axisbreak, IO_VALUE.LOW);
axisBean.ServoOff(); axisBean.ServoOff();
} }
if (needPlaySound)
{
SoundsController.StopPlay();
}
return true; return true;
} }
...@@ -272,6 +302,10 @@ namespace DeviceLibrary ...@@ -272,6 +302,10 @@ namespace DeviceLibrary
IOManager.IOMove(axisbreak, IO_VALUE.LOW); IOManager.IOMove(axisbreak, IO_VALUE.LOW);
axisBean.ServoOff(); axisBean.ServoOff();
} }
if (needPlaySound)
{
SoundsController.StopPlay();
}
} }
public void Pause() public void Pause()
{ {
...@@ -284,6 +318,10 @@ namespace DeviceLibrary ...@@ -284,6 +318,10 @@ namespace DeviceLibrary
IOManager.IOMove(axisbreak, IO_VALUE.LOW); IOManager.IOMove(axisbreak, IO_VALUE.LOW);
axisBean.ServoOff(); axisBean.ServoOff();
} }
if (needPlaySound)
{
SoundsController.StopPlay();
}
} }
} }
DateTime LastResumeTime = DateTime.Now; DateTime LastResumeTime = DateTime.Now;
......
...@@ -148,7 +148,7 @@ namespace DeviceLibrary ...@@ -148,7 +148,7 @@ namespace DeviceLibrary
var sf = ""; var sf = "";
if (Setting_Init.StringDoor_X08IsStringDoor_SafetyLightCurtains) if (Setting_Init.StringDoor_X08IsStringDoor_SafetyLightCurtains)
sf = IO_Type.AGV_OnPosition; sf = IO_Type.AGV_OnPosition;
StringDoor = new LiftMonitor(IO_Type.StringDoor_Open, IO_Type.StringDoor_Close, sf, IO_Type.StringDoor_Axis_Break, new AxisBean(Config.StringDoor_Axis, Name), Config.StringDoorLength, Config.StringDoorLength_speed, 0, "折叠门"); StringDoor = new LiftMonitor(IO_Type.StringDoor_Open, IO_Type.StringDoor_Close, sf, IO_Type.StringDoor_Axis_Break, new AxisBean(Config.StringDoor_Axis, Name), Config.StringDoorLength, Config.StringDoorLength_speed, 0, "折叠门",true);
StringDoor.DownOverTimeMS = Setting_Init.StringDoor_DownOverTimeMS; StringDoor.DownOverTimeMS = Setting_Init.StringDoor_DownOverTimeMS;
StringDoor.UpOverTimeMS = Setting_Init.StringDoor_UpOverTimeMS; StringDoor.UpOverTimeMS = Setting_Init.StringDoor_UpOverTimeMS;
StringDoor.ResumeWaitTimeSec = 5; StringDoor.ResumeWaitTimeSec = 5;
...@@ -354,6 +354,7 @@ namespace DeviceLibrary ...@@ -354,6 +354,7 @@ namespace DeviceLibrary
StopMove(true); StopMove(true);
IOMove(IO_Type.LineRun, IO_VALUE.LOW); IOMove(IO_Type.LineRun, IO_VALUE.LOW);
LedProcess(null); LedProcess(null);
SoundsController.StopPlay();
LogUtil.info("开始停止系统3."); LogUtil.info("开始停止系统3.");
} }
public void BeginHomeReset(bool firstRun = false) public void BeginHomeReset(bool firstRun = false)
......
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Media;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DeviceLibrary
{
/// <summary>
/// 声音控制类
/// </summary>
public class SoundsController
{
private static string openDoorFile = @"\sounds\doorOpen.wav";
private static string closeDoorFile = @"\sounds\doorClose.wav";
private static SoundPlayer alarmPlayer = new SoundPlayer();
private static bool InPlay = false;
private static string currFile = "";
public static void StartOpen()
{
StartPlay(openDoorFile);
}
public static void StartClose() {
StartPlay(closeDoorFile);
}
private static void StartPlay(string fileName)
{
if (!Setting_Init.Enable_DoorSound)
{
return;
}
if (InPlay)
{
if (currFile == fileName)
{
return;
}
else
{
StopPlay();
}
}
// 音频文件路径
string audioFilePath = Application.StartupPath + fileName;
currFile = fileName;
LogUtil.info("开始播放:" + currFile);
try
{
if (File.Exists(audioFilePath))
{
// 设置要播放的音频文件路径
alarmPlayer.SoundLocation = audioFilePath;
// 播放音频
alarmPlayer.PlayLooping();
}
else
{
LogUtil.error("未找到音频文件:" + audioFilePath);
}
InPlay = true;
}
catch (Exception ex)
{
LogUtil.error("发生错误:" + ex.Message);
}
}
public static void StopPlay()
{
InPlay = false;
LogUtil.info("停止播放音频:"+currFile);
// 停止播放音频
alarmPlayer.Stop();
}
public static void PlayFile(string filename)
{
if (!Setting_Init.Enable_DoorSound)
{
return;
}
if (InPlay)
{
//报警中不播放。
return;
}
// 音频文件路径
string audioFilePath = Application.StartupPath + filename;
try
{
if (File.Exists(audioFilePath))
{
// 设置要播放的音频文件路径
alarmPlayer.SoundLocation = audioFilePath;
// 播放音频
alarmPlayer.Play();
}
else
{
LogUtil.error("未找到音频文件:" + audioFilePath);
}
}
catch (Exception ex)
{
LogUtil.error("发生错误:" + ex.Message);
}
}
}
}
此文件类型无法预览
此文件类型无法预览
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!