Ejemplo n.º 1
0
        private VirtualIo(int channel)
        {
            Names     = new string[] { "DI", "DO", };
            Labels    = new string[] { "输入", "输出" };
            Values    = new int[] { 0, 0 };
            TrigCount = 0;
            Channel   = channel;

            DoFailCount = 0;

            var db      = DbScheme.Connections["Main"];
            var diQuery = db.Query <CcdDi>("select * from CcdDi where ccdId = ?", Id);
            var doQuery = db.Query <CcdDo>("select * from CcdDo where ccdId = ?", Id);

            DiPorts = new Dictionary <string, int>();
            foreach (var qurey in diQuery)
            {
                DiPorts[qurey.Name] = qurey.Port;
            }

            DoPorts = new Dictionary <string, int>();
            foreach (var qurey in doQuery)
            {
                DoPorts[qurey.Name] = qurey.Port;
            }

            int    comPort  = db.ExecuteScalar <int>("select comPort from CcdSerial where ccdId = ?", Id);
            string portName = "COM" + comPort;

            Device = new SyDevice(Id, portName);

            DiChanged += VirtualIo_DiChanged;
            DoChanged += VirtualIo_DoChanged;
            Grab      += VirtualIo_Grab;
        }
Ejemplo n.º 2
0
        public static bool Connect(this SyDevice device)
        {
            bool result  = true;
            bool isAvail = false;

            SyInfo sy = device.Device;

            int    connectNum = sy.GetConnectNum();
            string portName   = sy.GetPortName();
            int    portNum    = sy.GetPortNum();

            sy.IsAvail = false;

            isAvail = sy.Check();
            if (!isAvail)
            {
                result = false;
            }


            isAvail = sy.Config();
            if (!isAvail)
            {
                result = false;
            }

            sy.Connect();
            if (!isAvail)
            {
                result = false;
            }

            sy.Init();
            if (!isAvail)
            {
                result = false;
            }

            if (result)
            {
                sy.IsAvail = true;
            }
            LogStatusMessage(string.Format("连接串口{0}", portName), sy.IsAvail);
            return(result);
        }
Ejemplo n.º 3
0
 public static bool Disconnect(this SyDevice device)
 {
     return(Disconnect(device.ConnectNum));
 }