Commit 2a98a472 张东亮

1

1 个父辈 e8101af2
......@@ -21,7 +21,8 @@ namespace OnlineStore
public static readonly ILog LOG = LogManager.GetLogger("LngResource");
public static bool OpenResourceLog = false;
public static string China = "zh-CN";
public static string Japan = "ja-JP";
public static string English = "en-US";
private static Dictionary<string,Dictionary<string, string>> LangMap = new Dictionary<string, Dictionary<string, string>>();
public delegate string GetLanguageDelegate();
......
此文件类型无法预览
......@@ -8,6 +8,7 @@ using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Management;
namespace DeviceLibrary
{
......@@ -104,6 +105,12 @@ namespace DeviceLibrary
return "";
}
/// <summary>
/// 入库请求
/// </summary>
/// <param name="codelist"></param>
/// <param name="reel"></param>
/// <param name="printlog"></param>
public void SendInStoreRequest(string[] codelist, ReelParam reel, bool printlog = false)
{
......@@ -137,15 +144,18 @@ namespace DeviceLibrary
}
public bool SendStoreState(string posid, StoreStatus storeStatus)
{
lock (serverclock)
if (Monitor.TryEnter(serverclock, 300))
{
try
{
Operation operation = getLineBoxStatus();
if (!string.IsNullOrEmpty(posid))
operation.boxStatus[StoreID].data.Add(ParamDefine.posId, posid);
operation.boxStatus[StoreID].status = (int)storeStatus;
LogUtil.info(JsonHelper.SerializeObject(operation));
LogUtil.info($"SendStoreState 【{posid}】【{storeStatus}】【{JsonHelper.SerializeObject(operation)}】");
if (RobotManage.InoutDebugMode)
return true;
Operation resultOperation = HttpHelper.Post(GetPostApi(), operation, 5000, true);
......@@ -170,9 +180,19 @@ namespace DeviceLibrary
{
this.storeStatus = StoreStatus.StoreOnline;
}
}
finally
{
Monitor.Exit(serverclock);
}
return true;
}
else
{
return false;
}
}
public string spiltStr = "##";
private string ProcessCode(string[] codeList, int reelw, int reelh)
{
......@@ -293,8 +313,9 @@ namespace DeviceLibrary
{
if (RobotManage.InoutDebugMode)
return;
lock (serverclock)
if (Monitor.TryEnter(serverclock, 50))
{
try
{
bool printlog = false;
DateTime time = DateTime.Now;
......@@ -330,6 +351,11 @@ namespace DeviceLibrary
}
ServerCommStr = $"Send:{JsonHelper.SerializeObject(lineOperation)}\r\n Recv:{JsonHelper.SerializeObject(resultOperation)}";
}
finally
{
Monitor.Exit(serverclock);
}
}
}
public int queueTaskCount = -1;
ConcurrentQueue<string> commandResultMsg = new ConcurrentQueue<string>();
......
......@@ -36,7 +36,7 @@ namespace DeviceLibrary
ProcessMsgEvent?.Invoke(Msg.get());
//暂停时按下reaet按钮
if (RobotManage.isRunning && RobotManage.mainMachine.UserPause)
if (RobotManage.isRunning && UserPause)
{
RobotManage.UserPause("Reset_BTN", false);
}
......
......@@ -341,6 +341,7 @@ namespace DeviceLibrary
}
}
RobotManage.isRunning = false;
RobotManage.UserPause($"isRunning = false", false);
LogUtil.info("主线程已退出.");
}
public void Start()
......@@ -359,8 +360,7 @@ namespace DeviceLibrary
StopMove(true);
IOMove(IO_Type.LineRun, IO_VALUE.LOW);
LedProcess(null);
LogUtil.info("开始停止系统3.");
}
public void BeginHomeReset(bool firstRun = false)
{
......
......@@ -66,7 +66,7 @@ namespace DeviceLibrary
}
else
{
RobotManage.UserPause("", false);
RobotManage.UserPause("单口料盘已取走", false);
}
}
LogUtil.info($"取料机构当前没有在等待单盘入库:{ClampMoveInfo.MoveStep}");
......
......@@ -20,18 +20,25 @@ namespace DeviceLibrary
public static bool IsLoadOk = true;
public static bool IsConfigMode = false;
public static bool InoutDebugMode = false;
public static bool DisableUpdownProtect {
public static bool DisableUpdownProtect
{
get => ConfigHelper.Config.Get("Device_DisableUpdownProtect", false);
}
public delegate void LoadFinish(bool state,string msg);
public delegate void LoadFinish(bool state, string msg);
public static event LoadFinish LoadFinishEvent;
public static event EventHandler<bool> UserPauseSet;
/// <summary>
/// 系统是否运行的标志
/// </summary>
public static bool isRunning = false;
public static Dictionary<string, ACStorePosition> allPositionMap { get => CSVPositionReader<ACStorePosition>.allPositionMap; }
static List<string> _positionNumList=null;
public static List<string> PositionNumList { get {
static List<string> _positionNumList = null;
public static List<string> PositionNumList
{
get
{
if (_positionNumList == null)
_positionNumList = CSVPositionReader<ACStorePosition>.allPositionMap.Keys.ToList();
return _positionNumList;
......@@ -39,11 +46,12 @@ namespace DeviceLibrary
}
static string baseDir = Application.StartupPath;
static Thread mainThread;
public static bool haveFixpos=false;
public static bool haveFixpos = false;
public static HIKCamera CameraA=new HIKCamera();
public static void Init(params object[] param) {
public static HIKCamera CameraA = new HIKCamera();
public static void Init(params object[] param)
{
string msg = "";
try
{
......@@ -59,9 +67,10 @@ namespace DeviceLibrary
LogUtil.info("加载位置文件:" + positionConfigFile);
CSVPositionReader<ACStorePosition>.AddCSVFile(positionConfigFile);
}
else {
else
{
IsLoadOk = false;
msg += crc.GetString(L.cant_find_storeposfile, "找不到库位配置文件")+ "\n";
msg += crc.GetString(L.cant_find_storeposfile, "找不到库位配置文件") + "\n";
}
string fixpositionConfigFile = Path.Combine(baseDir, "StoreConfig\\fixPositions.csv");
if (File.Exists(fixpositionConfigFile))
......@@ -77,7 +86,7 @@ namespace DeviceLibrary
if (!IOManager.ConnectionIOList(new List<string>()))
{
IsLoadOk = false;
msg += crc.GetString(L.iocard_init_fail, "IO板卡初始化失败")+ "\n";
msg += crc.GetString(L.iocard_init_fail, "IO板卡初始化失败") + "\n";
}
// IOManager.CloseAllConnection();
//if (!CameraA.LoadCameraConfig(out string errmsg, param[0]))
......@@ -85,9 +94,10 @@ namespace DeviceLibrary
// IsLoadOk = false;
// msg += errmsg + "\r\n";
//}
if (!HumitureController.Init(ConfigHelper.Config.Get("Device_Humiture_Port"))) {
if (!HumitureController.Init(ConfigHelper.Config.Get("Device_Humiture_Port")))
{
IsLoadOk = false;
msg += crc.GetString(L.tempnhum_sensor_init_fail, $"温湿度传感器初始化失败,端口:")+ $"{ConfigHelper.Config.Get("Device_Humiture_Port")}\n";
msg += crc.GetString(L.tempnhum_sensor_init_fail, $"温湿度传感器初始化失败,端口:") + $"{ConfigHelper.Config.Get("Device_Humiture_Port")}\n";
}
//Thread.Sleep(1000);
//if (!IOManager.ConnectionIOList(new List<string>()))
......@@ -99,17 +109,20 @@ namespace DeviceLibrary
IOManager.IOMove(IO_Type.Camera_Led, IO_VALUE.HIGH);
}
catch (Exception ex) {
catch (Exception ex)
{
LogUtil.error("Init ", ex);
LoadFinishEvent?.Invoke(false, ex.Message);
return;
}
LoadFinishEvent?.Invoke(IsConfigMode ? IsConfigMode : IsLoadOk, msg);
}
public static void LoadDebug() {
LoadFinishEvent?.Invoke(true, crc.GetString(L.open_debug_mode,"打开调试模式"));
public static void LoadDebug()
{
LoadFinishEvent?.Invoke(true, crc.GetString(L.open_debug_mode, "打开调试模式"));
}
public static void Start() {
public static void Start()
{
if (!IsLoadOk)
{
......@@ -125,13 +138,15 @@ namespace DeviceLibrary
return;
}
isRunning = true;
UserPause($"isRunning = true", false);
mainThread = new Thread(new ThreadStart(mainMachine.Start));
mainThread.Start();
CameraA.startCamera();
}
GC.KeepAlive(mainThread);
Task.Run(()=> {
Task.Run(() =>
{
Task.Delay(1000).Wait();
if (mainMachine.DeviceCheck())
mainMachine.BeginHomeReset(true);
......@@ -142,12 +157,7 @@ namespace DeviceLibrary
public static void Stop()
{
LogUtil.info("开始停止系统.");
if (mainMachine != null)
{
mainMachine.Stop();
mainMachine.UserPause = false;
}
mainMachine?.Stop();
}
public static void ShutDown()
{
......@@ -155,22 +165,31 @@ namespace DeviceLibrary
IOManager.CloseAllConnection();
CameraA.stopCamera();
}
public static void UserPause(bool userpause)
public static bool IsUserPause
{
UserPause("", userpause);
get { return mainMachine.UserPause; }
}
public static void UserPause(string msg="",bool userpause=true) {
/// <summary>
/// 用户暂停
/// </summary>
/// <param name="msg"></param>
/// <param name="userpause"></param>
public static void UserPause(string msg = "", bool userpause = true)
{
UserPauseSet?.Invoke(null, userpause);
mainMachine.UserPause = userpause;
if (userpause != mainMachine.UserPause)
{
if (userpause)
{
if(string.IsNullOrEmpty(msg))
if (string.IsNullOrEmpty(msg))
LogUtil.info("用户暂停");
else
LogUtil.info("系统暂停: "+msg);
LogUtil.info("系统暂停: " + msg);
}
else
LogUtil.info("用户取消暂停:"+ msg);
LogUtil.info("用户取消暂停:" + msg);
}
mainMachine.UserPause = userpause;
}
public static void IgnoreSafecheck(bool s)
{
......@@ -194,32 +213,33 @@ namespace DeviceLibrary
reelParam = null;
try
{
string fix = ConfigHelper.Config.Get(Setting_Init.FixBuffInfo,"");
if(!string.IsNullOrEmpty(fix))
string fix = ConfigHelper.Config.Get(Setting_Init.FixBuffInfo, "");
if (!string.IsNullOrEmpty(fix))
{
reelParam=JsonHelper.DeserializeJsonToObject<ReelParam>(fix);
reelParam = JsonHelper.DeserializeJsonToObject<ReelParam>(fix);
return true;
}
}
catch (Exception e)
{
LogUtil.error("解析校准库位缓存异常",e);
LogUtil.error("解析校准库位缓存异常", e);
}
return false;
}
public static void PutReelInFixPos(ReelParam reelParam)
{
if (mainMachine.AutoInOutTest) return;
ConfigHelper.Config.Set(Setting_Init.FixBuffInfo,JsonHelper.SerializeObject(reelParam));
ConfigHelper.Config.Set(Setting_Init.FixBuffInfo, JsonHelper.SerializeObject(reelParam));
}
public static void ClearReelInFixPos()
{
ConfigHelper.Config.Set(Setting_Init.FixBuffInfo,"");
ConfigHelper.Config.Set(Setting_Init.FixBuffInfo, "");
}
#endregion
}
public enum StoreType {
TypeA,TypeB
public enum StoreType
{
TypeA, TypeB
}
}
......@@ -39,16 +39,6 @@
<conversionPattern value="%m%n"/>
</layout>
</appender>
<appender name="HIK.IPCamera" type="log4net.Appender.RollingFileAppender">
<file value="logs/HIKIPCamera.log"/>
<param name="Encoding" value="UTF-8"/>
<appendToFile value="true"/>
<rollingStyle value="Date"/>
<datePattern value="yyyy-MM-dd"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="[%date][%t][%C:%L]%-5p %m%n"/>
</layout>
</appender>
<logger name="RollingLogFileAppender">
<level value="ALL"/>
<appender-ref ref="RollingLogFileAppender"/>
......@@ -61,10 +51,6 @@
<level value="ALL"/>
<appender-ref ref="LngResource"/>
</logger>
<logger name="HIK.IPCamera" additivity="false">
<level value="ALL"/>
<appender-ref ref="HIK.IPCamera"/>
</logger>
<!--<root>
<level value="Info" />
<appender-ref ref="RollingLogFileAppender" />
......
......@@ -14,6 +14,7 @@ using System.Runtime.Serialization.Formatters.Binary;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;
namespace TheMachine
{
......@@ -331,7 +332,7 @@ namespace TheMachine
// });
// return;
//}
if(Monitor.TryEnter(showMsgLoc))
if (Monitor.TryEnter(showMsgLoc))
{
try
{
......@@ -390,8 +391,6 @@ namespace TheMachine
}
}
bool userpause = false;
private void btn_run_Click(object sender, EventArgs e)
{
......@@ -403,25 +402,17 @@ namespace TheMachine
MainMachine_ProcessMsgEvent(Msg.get());
return;
}
btn_run.Enabled = false;
LogUtil.info("用户按下启动按钮");
RobotManage.Start();
userpause = false;
if (RobotManage.isRunning)
{
btn_stop.Enabled = true;
RobotManage_UserPauseSet(this, false);
}
}
else if (!userpause)
else if (!RobotManage.IsUserPause)
{
userpause = true;
RobotManage.UserPause(userpause);
RobotManage.UserPause("用户按下启动按钮", true);
}
else if (userpause)
else if (RobotManage.IsUserPause)
{
userpause = false;
RobotManage.UserPause(userpause);
RobotManage.UserPause("用户按下启动按钮", false);
}
}
private void RobotManage_UserPauseSet(object sender, bool e)
......@@ -434,17 +425,27 @@ namespace TheMachine
}, sender, e);
return;
}
btn_run.Enabled = true;
if (RobotManage.isRunning)
{
btn_stop.Enabled = true;
}
else
{
btn_stop.Enabled = false;
btn_run.Text = crc.GetString(L.start, "启动");
btn_run.BackColor = Color.Transparent;
cb_IgnoreSafecheck.Enabled = true;
return;
}
if (e)
{
userpause = true;
(btn_run as Button).Text = crc.GetString(L.device_resume, "恢复运行");
(btn_run as Button).BackColor = Color.LightGreen;
cb_IgnoreSafecheck.Enabled = true;
}
else
{
userpause = false;
(btn_run as Button).Text = crc.GetString(L.device_pause, "暂停运行");
(btn_run as Button).BackColor = Color.Yellow;
cb_IgnoreSafecheck.Enabled = false;
......@@ -461,17 +462,15 @@ namespace TheMachine
}, sender, e);
return;
}
if (!btn_stop.Enabled)
if (!btn_stop.Enabled)//已经停止,无需重复调用停止
return;
btn_stop.Enabled = false;
LogUtil.info("用户按下停止按钮");
RobotManage.UserPause(false);
userpause = false;
Task.Run(() => { RobotManage.Stop(); });
btn_run.Text = crc.GetString(L.start, "启动");
btn_run.BackColor = Color.Transparent;
cb_IgnoreSafecheck.Enabled = true;
//btn_run.Text = crc.GetString(L.start, "启动");
//btn_run.BackColor = Color.Transparent;
//cb_IgnoreSafecheck.Enabled = true;
}
private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
......@@ -670,28 +669,25 @@ namespace TheMachine
if (RobotManage.isRunning)
{
if (userpause)
(btn_run as Button).Text = crc.GetString(L.device_resume, "恢复运行");
else
(btn_run as Button).Text = crc.GetString(L.device_pause, "暂停运行");
RobotManage_UserPauseSet(null, RobotManage.IsUserPause);
}
}
private void 简体中文ToolStripMenuItem_Click(object sender, EventArgs e)
{
Config.Set("Device_Default_Language", "zh-CN");
Config.Set("Device_Default_Language", crc.China);
crc.LanguageChange();
}
private void 日本语ToolStripMenuItem_Click(object sender, EventArgs e)
{
Config.Set("Device_Default_Language", "ja-JP");
Config.Set("Device_Default_Language", crc.Japan);
crc.LanguageChange();
}
private void englishToolStripMenuItem_Click(object sender, EventArgs e)
{
Config.Set("Device_Default_Language", "en-US");
Config.Set("Device_Default_Language", crc.English);
crc.LanguageChange();
}
#region 窗口管理
......
......@@ -98,7 +98,7 @@ namespace TheMachine
}
else
{
FrmPositionTool frmPositionTool = new FrmPositionTool(RobotManage.mainMachine.UpDown_Axis, IO_Type.Laser_Location);
FrmPositionTool frmPositionTool = new FrmPositionTool(RobotManage.mainMachine.UpDown_Axis, IO_Type.TrayCheck_Fixture);
frmPositionTool.ShowDialog();
}
}
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!