Beispiel #1
0
        public int GetDI(int index, out bool isON)
        {
            if (index < 0 || index >= DICount)
            {
                throw new Exception(string.Format("GetDI(index = {0}, isON) index is out of range:0~{1}", index, DICount - 1));
            }
            isON = false;
            if (!IsOpen)
            {
                return((int)ErrorDef.NotOpen);
            }


            //lock (asynLocker)
            {
                if (!IsOpen)
                {
                    return((int)ErrorDef.NotOpen);
                }
                ushort diVals = 0;
                if (0 != DASK.DI_ReadLine(_devHandle, (ushort)(index / 32), (ushort)(index % 32), out diVals))
                {
                    return((int)ErrorDef.InvokeFailed);
                }

                isON = diVals != 0;
            }

            return((int)ErrorDef.Success);
        }
Beispiel #2
0
        /* Read Node */
        public static void ReadPin(ushort port, ushort pin, out bool state, out short code, out string message)
        {
            if (Testing)
            {
                state = true; code = 0; message = "Testing"; return;
            }

            ushort logic;

            code  = DASK.DI_ReadLine((ushort)m_device, port, pin, out logic);
            state = (logic == 1) ? true : false;
            if (code < 0)
            {
                message = "อ่านพอร์ต DIO7432 ผิดพลาด";
                logText = "Read PIN [" + port.ToString() + "." + pin.ToString() + " = " + state.ToString() + "]: " + message;
                log.AppendText(logText);
                //System.Diagnostics.Debug.WriteLine(logText);
            }
            else
            {
                message = "";
                logText = "Read PIN [" + port.ToString() + "." + pin.ToString() + " = " + state.ToString() + "]: OK";
                log.AppendText(logText);
                //System.Diagnostics.Debug.WriteLine(logText);
            }
        }
Beispiel #3
0
        private void button2_Click(object sender, EventArgs e)
        {
            short  ret;
            uint   int_value;
            ushort s_value;

            //ret = DASK.DI_ReadPort((ushort)m_dev, 0, out int_value); /* INPUT */
            ret = DASK.DI_ReadLine((ushort)m_dev, 0, 0, out s_value); /* INPUT */
            if (ret < 0)
            {
                MessageBox.Show("D2K_DI_ReadPort error!");
                return;
            }
            //textBox2.Text = String.Format("{0}", int_value);
            textBox2.Text = String.Format("{0}", s_value);
        }
Beispiel #4
0
        public bool GetInputBit(int iBit)
        {
            bool   ret       = false;
            ushort int_value = 0;

            try
            {
                lock (lockObj)
                {
                    DASK.DI_ReadLine(usCardNo, 0, (ushort)iBit, out int_value);
                    ret = int_value == 0 ? false : true;
                }
            }
            catch (Exception)
            {
                return(false);
            }
            return(ret);
        }
Beispiel #5
0
        public bool Read(IoPoint ioPoint)
        {
            var    device = _devices[ioPoint.BoardNo];
            ushort value  = 0;
            var    ret    = 0;

            if ((ioPoint.IoMode & IoModes.Responser) == 0)
            {
                ret = DASK.DI_ReadLine((ushort)device, 0, (ushort)ioPoint.PortNo, out value);
            }
            else
            {
                ret = DASK.DO_ReadLine((ushort)device, 0, (ushort)ioPoint.PortNo, out value);
            }
            if (ret != DASK.NoError)
            {
                switch (ret)
                {
                case DASK.ErrorInvalidCardNumber:
                    throw new DaskException(string.Format("The CardNumber argument {0} is out of range (larger than 31).", device));

                case DASK.ErrorCardNotRegistered:
                    throw new DaskException(string.Format("No card registered as {0} CardNumber.", device));

                case DASK.ErrorFuncNotSupport:
                    throw new DaskException(string.Format("The {0} function called is not supported by this type of card.", "DO_WriteLine"));

                case DASK.ErrorInvalidIoChannel:
                    throw new DaskException(string.Format("The specified Channel or Port argument {0} is out of range.", ioPoint.PortNo));

                default:
                    throw new DaskException("Unknown error.");
                }
            }
            return(value > 0);
        }