예제 #1
0
        public CameraController(VM_MSConfig msConfig)
        {
            Config = msConfig;

            busRtuClient?.Close();
            busRtuClient = new ModbusRtu(Config.Station);
            busRtuClient.AddressStartWithZero = Config.DDFlag;
            busRtuClient.IsStringReverse      = Config.ComFlag;
            try
            {
                busRtuClient.SerialPortInni(sp =>
                {
                    sp.PortName = Config.Com;
                    sp.BaudRate = Config.BaudRate;
                    sp.DataBits = Config.DataBits;
                    sp.StopBits = Config.StopBits == 0 ? System.IO.Ports.StopBits.None : (Config.StopBits == 1 ? System.IO.Ports.StopBits.One : System.IO.Ports.StopBits.Two);
                    sp.Parity   = Config.Parity == 0 ? System.IO.Ports.Parity.None : (Config.Parity == 1 ? System.IO.Ports.Parity.Odd : System.IO.Ports.Parity.Even);
                });
                busRtuClient.Open();
                LogHelper.WriteInfoLog("busRtuClient Open  Succeed!");
            }
            catch (Exception ex)
            {
                LogHelper.WriteInfoLog(ex.Message);
            }
        }
예제 #2
0
        public static VM_MSConfig LoadConfig()
        {
            String     sConfigFile = ConfigHelper.GetConfigFile();
            Type       type        = typeof(VM_MSConfig);
            FileStream fs          = null;

            try
            {
                fs = new FileStream(sConfigFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                XmlSerializer serializer = new XmlSerializer(type);
                VM_MSConfig   cfg        = (VM_MSConfig)serializer.Deserialize(fs);
                if (cfg == null)
                {
                    return(null);
                }
                return(cfg);
            }
            catch (Exception ex)
            {
                return(null);
            }
            finally
            {
                if (fs != null)
                {
                    fs.Close();
                }
            }
        }
예제 #3
0
        private bool StartVoltageInfo(VM_MSConfig m_Config)
        {
            VoltageController vc = new VoltageController(m_Config);

            vc.OnVoltageValueChanges += new VoltageController.VoltageValueChanges(PrintVoltageValueChanged);
            vc.Start(1000);
            return(true);
        }
예제 #4
0
 public MSOutController(int deviceNumber, VM_MSConfig msConfig)
 {
     if (instantDoCtrl1 == null)
     {
         instantDoCtrl1 = new InstantDoCtrl();
     }
     instantDoCtrl1.SelectedDevice = new DeviceInformation(deviceNumber);
 }
예제 #5
0
 public MSController(int deviceNumber, VM_MSConfig msConfig)
 {
     if (instantDiCtrl1 == null)
     {
         instantDiCtrl1 = new InstantDiCtrl();
     }
     instantDiCtrl1.SelectedDevice = new DeviceInformation(deviceNumber);
     Config = msConfig;
     STSEventLogManage.Instance.Start();
 }
예제 #6
0
        /// <summary>
        /// 生成XML
        /// </summary>
        public void MakeXml()
        {
            VM_MSConfig vm = new VM_MSConfig();

            vm.AutoStart = "true";
            //vm.AutoStop = "false";
            vm.IP             = "127.0.0.1";
            vm.Port           = "8888";
            vm.SqlConnect     = "Data Source = 127.0.0.1; Initial Catalog = TRDSDB; Persist Security Info=True;User ID = sa; Password=nexadia";
            vm.TrainDirection = "入库方向";
            //vm.DDFlag =;
            //vm.ComIndex =;
            //vm.Com = "COM3";
            //vm.BaudRate = 9600;
            //vm.DataBits = 8;
            //vm.StopBits = "无";
            XMLSave(vm);
        }
예제 #7
0
        private bool StartSchedulers(VM_MSConfig m_Config)
        {
            if (m_Config == null)
            {
                return(false);
            }
            MSController ms = new MSController(0, m_Config);

            ms.Start(2);
            ms.OnIDIInputStatusChanges += new MSController.IDIInputStatusChanges(GetStatusChanged);
            m_HtDicPortToValue          = ms.m_HtDicPortToValue;
            if (MsOutController == null)
            {
                MsOutController = new MSOutController(0, m_Config);
            }
            TaskScheduleBase m_TaskSchedule = new TaskScheduleBase();

            return(m_TaskSchedule.Start());
        }
예제 #8
0
        /// <summary>
        /// 开启调度模块
        /// 1,连接TOSInterface
        /// 2,开启交互管理模块
        /// 3,开启各个QC的调度线程
        /// </summary>
        /// <param name="cfg">STSMS的配置信息</param>
        /// <returns>开启成功返回true,否则返回false,并在log中记录详细错误信息</returns>
        public bool Start(VM_MSConfig cfg)
        {
            if (cfg == null)
            {
                return(false);
            }
            m_Config = cfg;

            if (!StartSocketListen())
            {
                LogHelper.WriteInfoLog("Start Socket Listen failed!");
                OutPutMessage("Start Socket Listen failed!");
                return(false);
            }
            LogHelper.WriteInfoLog("Socket Listen connected.");
            OutPutMessage("Socket Listen connected.");

            if (!StartSchedulers(m_Config))
            {
                LogHelper.WriteInfoLog("Start scheduler failed!");
                OutPutMessage("Start scheduler failed!");
                return(false);
            }
            LogHelper.WriteInfoLog("Schedule modle started!");
            OutPutMessage("Schedule modle started!");
            base.Start(2);
            //if (StartListenOpenCameraInfo(m_Config))
            //{

            //}
            if (!StartVoltageInfo(m_Config))
            {
                LogHelper.WriteInfoLog("Start VoltageController failed!");
                OutPutMessage("Start VoltageController failed!");
                return(false);
            }
            LogHelper.WriteInfoLog("VoltageController modle started!");
            OutPutMessage("VoltageController modle started!");
            return(true);
        }
예제 #9
0
        public VoltageController(VM_MSConfig msConfig)
        {
            Config           = msConfig;
            m_iCom           = 3;                      // using COM4
            m_iAddr          = 1;                      // the slave address is 1
            m_iCount         = 0;                      // the counting start from 0
            m_bStart         = false;
            m_Adam4000Type   = Adam4000Type.Adam4019P; // the sample is for ADAM-4019P
            m_iChTotal       = AnalogInput.GetChannelTotal(m_Adam4000Type);
            m_byRange        = new byte[m_iChTotal];
            adamCom          = new AdamCom(m_iCom);
            adamCom.Checksum = false; // disbale checksum

            Module = m_Adam4000Type.ToString();

            if (adamCom.OpenComPort())
            {
                // set COM port state, 9600,N,8,1
                adamCom.SetComPortState(Baudrate.Baud_9600, Databits.Eight, Parity.None, Stopbits.One);
                // set COM port timeout
                adamCom.SetComPortTimeout(500, 500, 0, 500, 0);
                m_iCount = 0; // reset the reading counter
                              // get module config
                if (!adamCom.Configuration(m_iAddr).GetModuleConfig(out m_adamConfig))
                {
                    adamCom.CloseComPort();
                    LogHelper.WriteErrorLog("Failed to get module config!");
                    return;
                }
                //
                RefreshChannelEnable();
                RefreshChannelRange();
                //
                m_bStart = true; // starting flag
            }
            else
            {
                LogHelper.WriteErrorLog("Failed to open COM port!");
            }
        }
예제 #10
0
        public static void XMLSave(VM_MSConfig msConfig)
        {
            String sConfigFile = ConfigHelper.GetConfigFile();

            msConfig.Save(sConfigFile);
        }