public int SendMessage(byte[] btArySenderData)
        {
            try
            {
                if (m_nType == 0)
                {
                    if (!iSerialPort.IsOpen)
                    {
                        return(-1);
                    }

                    iSerialPort.Write(btArySenderData, 0, btArySenderData.Length);

                    if (SendCallback != null)
                    {
                        SendCallback(btArySenderData);
                    }

                    return(0);
                }
                else if (m_nType == 1)
                {
                    if (!italker.IsConnect())
                    {
                        return(-1);
                    }

                    if (italker.SendMessage(btArySenderData))
                    {
                        if (SendCallback != null)
                        {
                            SendCallback(btArySenderData);
                        }

                        return(0);
                    }
                }
            }
            catch (Exception p)
            {
            }

            return(-1);
        }
示例#2
0
        public int SendMessage(byte[] btArySenderData)
        {
            //串口连接方式
            if (m_nType == 0)
            {
                if (!iSerialPort.IsOpen)
                {
                    return(-1);
                }

                iSerialPort.Write(btArySenderData, 0, btArySenderData.Length);

                if (SendCallback != null)
                {
                    SendCallback(btArySenderData);
                }

                return(0);
            }
            //Tcp连接方式
            else if (m_nType == 1)
            {
                if (!italker.IsConnect())
                {
                    return(-1);
                }

                if (italker.SendMessage(btArySenderData))
                {
                    if (SendCallback != null)
                    {
                        SendCallback(btArySenderData);
                    }

                    return(0);
                }
            }

            return(-1);
        }
示例#3
0
        // Envío mensaje una vez codificado
        public int SendMessage(byte[] btArySenderData)
        {
            //Lectura mediante USB
            if (m_nType == 0)
            {
                if (!iSerialPort.IsOpen)
                {
                    return(-1);
                }
                // Envía por iSerialPort: array con objeto, que hacer, word y length en bytes
                iSerialPort.Write(btArySenderData, 0, btArySenderData.Length);

                if (SendCallback != null)
                {
                    SendCallback(btArySenderData);
                }

                return(0);
            }
            //Tcp (para IP)
            else if (m_nType == 1)
            {
                if (!italker.IsConnect())
                {
                    return(-1);
                }

                if (italker.SendMessage(btArySenderData))
                {
                    if (SendCallback != null)
                    {
                        SendCallback(btArySenderData);
                    }

                    return(0);
                }
            }

            return(-1);
        }