private void NewInstanciaHijo1_NewConnection(ref CConnectionData connectionData)
 {
     if (NewConnectionEvent != null)
     {
         NewConnectionEvent(ref connectionData);
     }
 }
 private void StationSearcherTCP_NewConnection(ref CConnectionData connectionData)
 {
     if (NewConnectionEvent != null)
     {
         NewConnectionEvent(ref connectionData);
     }
 }
Beispiel #3
0
 private void Event_Detected_SubStation(CConnectionData connectionData)
 {
     if (Detected_SubStationEvent != null)
     {
         Detected_SubStationEvent(UUID, connectionData);
     }
 }
Beispiel #4
0
        protected override void RaiseNewConnection(CStationBase.Protocol commandProtocol, string sStationModel, string SoftwareVersion, string HardwareVersion)
        {
            // Cambia de referencia al puerto porque la anterior ya ha sido asignada
            RoutinesLibrary.Net.Protocols.TCP.TCP WinSock_Connected = WinSockIn;
            WinSockIn = null;

            //Cuando una estacion con un k60 esta apagada pero el usb esta conectado, sigue alimentandose.
            if (CheckStationModel(sStationModel))
            {
                //Genera el evento Nueva conexion, de protocolo de conexión/trama 02
                CConnectionData connectionData = new CConnectionData();
                connectionData.Mode             = SearchMode.ETH;
                connectionData.pWinSock         = WinSock_Connected;
                connectionData.PCNumDevice      = m_pcNumDevice;
                connectionData.StationNumDevice = m_stationNumDevice;
                connectionData.FrameProtocol    = m_Conection_FrameProtocol;
                connectionData.CommandProtocol  = commandProtocol;
                connectionData.StationModel     = sStationModel;
                connectionData.SoftwareVersion  = SoftwareVersion;
                connectionData.HardwareVersion  = HardwareVersion;

                if (NewConnectionEvent != null)
                {
                    NewConnectionEvent(ref connectionData);
                }
            }
            else
            {
                CloseWinSock(ref WinSock_Connected);
                m_Timer_Search.Stop();
                m_Timer_Search.Interval = MS_NEW_SEARCH;
                m_Timer_Search.Start();
            }
        }
Beispiel #5
0
        private void Event_NewConnection(ref CConnectionData connectionData)
        {
            // marca como conectado
            //Debug.Print("SearchTCP - NuevaConexion evento propio de SearchTCP")
            int idx = discoveredStations.ExistsStation(connectionData.pWinSock.HostEndPoint);

            if (idx >= 0)
            {
                discoveredStations.set_Connected(idx, true);
            }
        }
        public CCommunicationChannel(CConnectionData connectionData)
        {
            m_mode          = connectionData.Mode;
            m_sourceAddress = connectionData.PCNumDevice;

            if (m_mode == SearchMode.USB)
            {
                m_pSerialPort = connectionData.pSerialPort;
            }
            else if (m_mode == SearchMode.ETH)
            {
                m_pWinSock = connectionData.pWinSock;
            }

            m_frameProtocol = connectionData.FrameProtocol;
        }
Beispiel #7
0
        protected override void RaiseNewConnection(CStationBase.Protocol commandProtocol, string sStationModel, string SoftwareVersion, string HardwareVersion)
        {
            //Cuando una estacion con un k60 esta apagada pero el usb esta conectado, sigue alimentandose.
            if (CheckStationModel(sStationModel))
            {
                //Genera el evento Nueva conexion, de protocolo de conexión/trama 02
                CConnectionData connectionData = new CConnectionData();
                connectionData.Mode             = SearchMode.USB;
                connectionData.pSerialPort      = m_SerialPort_Int;
                connectionData.PCNumDevice      = m_pcNumDevice;
                connectionData.StationNumDevice = m_stationNumDevice;
                connectionData.FrameProtocol    = m_Conection_FrameProtocol;
                connectionData.CommandProtocol  = commandProtocol;
                connectionData.StationModel     = sStationModel;
                connectionData.SoftwareVersion  = SoftwareVersion;
                connectionData.HardwareVersion  = HardwareVersion;

                //Cambia de referencia al puerto porque la anterior ya ha sido asignada
                //m_SerialPort_Int.DataReceived -= new RoutinesLibrary.IO.SerialPort.DataReceivedEventHandler(SerialPort_Int_DataReceived);
                m_SerialPort_Int.Dispose(false);
                m_SerialPort_Int = null;

                if (NewConnectionEvent != null)
                {
                    NewConnectionEvent(ref connectionData);
                }
            }
            else
            {
                //Conexion no válida
                //m_SerialPort_Int.DataReceived -= new RoutinesLibrary.IO.SerialPort.DataReceivedEventHandler(SerialPort_Int_DataReceived);
                m_SerialPort_Int.Dispose();
                m_Timer_Search.Stop();
                m_Timer_Search.Interval = MS_NEW_SEARCH;
                m_Timer_Search.Start();
            }
        }
Beispiel #8
0
        public void ProcessMessageResponse(uint Numstream, byte[] Datos, byte Command, byte Origen)
        {
            //
            //Check source address
            //
            if (Origen != m_StationNumDevice)
            {
                //Para las sub estaciones sólo escuchamos a la siguiente dirección (DME(0x10) -> PSE(0x20) -> PSE (0x30))
                if (m_StationData.Info.Features.SubStations && (m_StationNumDevice + (int)EnumAddress.NEXT_SUBSTATION_ADDRESS) == Origen)
                {
                    //Las direcciones que vengan del mismo bloque de estación
                }
                else if ((Origen & (byte)EnumAddress.MASK_STATION_ADDRESS) == m_StationNumDevice)
                {
                }
                else
                {
                    return;
                }
            }


            //
            //Sent message
            //
            MessageHashtable.Message MessageInt = new MessageHashtable.Message();
            int Puerto = 0;
            //Dim Tool As Integer
            string sDatos = "";

            string[] aDatos = null;
            string   sTemp  = "";

            //Recuperar mensaje
            if (m_MessagesSentManager.ReadMessage(Numstream, ref MessageInt))
            {
                m_MessagesSentManager.RemoveMessage(Numstream);

                //La estación SF solo tiene un puerto y no viene especificado en el protocolo
                Puerto = 0;

                //Mensajes recibidos sin petición. (Firmware -> sub estación)
                //Para la DME touch enviamos las peticiones del modo continuo al dspic33 en vez de a la estación
            }
            else if (Command != (byte)EnumCommandFrame_02_SF.M_HS &
                     Command != (byte)EnumCommandFrame_02_SF.M_NACK &
                     Command != (byte)EnumCommandFrame_02_SF.M_FIRMWARE)
            {
                return;
            }


            //
            //Command
            //
            if (Command == (byte)EnumCommandFrame_02_SF.M_HS)
            {
                //Si se recibe una trama de handshake de otra dirección, es posible que se trate de otra estación
                if (Origen != m_StationNumDevice)
                {
                    ReadDeviceVersions(Origen);
                }
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_EOT)
            {
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_ACK)
            {
                if (EndedTransactionEvent != null)
                {
                    EndedTransactionEvent(Numstream);
                }
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_NACK)
            {
                Debug.Print("NACK Error: {0} Sent opcode: H{1:X2}", (Datos[0]).ToString(), Datos[1]);
                if (NACKTransactionEvent != null)
                {
                    NACKTransactionEvent(Numstream);
                }
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_SYN)
            {
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_R_DEVICEID)
            {
                clsStationUID stationUUID = new clsStationUID(Datos);
                m_StationData.Info.UUID = stationUUID.UID;
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_W_DEVICEID)
            {
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_RESET)
            {
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_FIRMWARE)
            {
                if (Datos.Length == 0)
                {
                }

                string   datosVersions = Encoding.UTF8.GetString(Datos);
                string[] arrayVersions = datosVersions.Split(':');
                if (arrayVersions.Length < 4)
                {
                }

                //protocolo
                string protocolo = arrayVersions[0];

                //modelo
                string   model          = arrayVersions[1];
                string[] arrayModelData = arrayVersions[1].Split('_');
                string   modelModel     = arrayModelData[0];

                string modelType = "";
                if (arrayModelData.Length > 1)
                {
                    modelType = arrayModelData[1];
                }

                int modelVersion = -1;
                if (arrayModelData.Length > 2)
                {
                    if (Information.IsNumeric(arrayModelData[2]))
                    {
                        modelVersion = int.Parse(arrayModelData[2]);
                    }
                }

                //soft y hard versions
                string versionSw = arrayVersions[2];
                string versionHw = arrayVersions[3];

                //La trama viene del micro principal
                if (Origen == m_StationNumDevice)
                {
                    m_StationData.Info.Protocol         = protocolo;
                    m_StationData.Info.Model            = modelModel;
                    m_StationData.Info.ModelType        = modelType;
                    m_StationData.Info.ModelVersion     = modelVersion;
                    m_StationData.Info.Version_Software = versionSw;
                    m_StationData.Info.Version_Hardware = versionHw;

                    //La trama viene de una estación conectada a otra estación (p.e. DME -> PSE -> PSE -> PSE)
                }
                else if (((Origen & (byte)EnumAddress.MASK_STATION_ADDRESS) == Origen) && CheckStationModel(model))
                {
                    CConnectionData connectionData = new CConnectionData();
                    //connectionData.Mode -> no es necesario por que será el mismo que el padre
                    //connectionData.pSerialPort -> no es necesario por que será el mismo que el padre
                    //connectionData.PCNumDevice -> no es necesario por que será el mismo que el padre
                    connectionData.StationNumDevice = Origen;
                    //connectionData.FrameProtocol = -> no es necesario por que será el mismo que el padre
                    //connectionData.CommandProtocol -> no es necesario por que será el mismo que el padre
                    connectionData.StationModel    = model;
                    connectionData.SoftwareVersion = versionSw;
                    connectionData.HardwareVersion = versionHw;

                    if (Detected_SubStationEvent != null)
                    {
                        Detected_SubStationEvent(connectionData);
                    }
                }


                //Guardamos la información del micro
                if ((Origen & (byte)EnumAddress.MASK_STATION_ADDRESS) == m_StationNumDevice)
                {
                    //Guardar información del micro
                    if (!m_StationData.Info.StationMicros.Contains(Origen))
                    {
                        CFirmwareStation micro = new CFirmwareStation();
                        micro.Model           = m_StationData.Info.Model;
                        micro.HardwareVersion = versionHw;
                        micro.SoftwareVersion = versionSw;
                        m_StationData.Info.StationMicros.Add(Origen, micro);
                    }
                }
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_CLEARMEMFLASH)
            {
                if (ClearingFlashFinishedEvent != null)
                {
                    ClearingFlashFinishedEvent();
                }
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_SENDMEMADDRESS)
            {
                if (AddressMemoryFlashFinishedEvent != null)
                {
                    AddressMemoryFlashFinishedEvent();
                }
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_SENDMEMDATA)
            {
                if (DataMemoryFlashFinishedEvent != null)
                {
                    DataMemoryFlashFinishedEvent();
                }
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_ENDPROGR)
            {
                if (EndProgFinishedEvent != null)
                {
                    EndProgFinishedEvent();
                }
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_R_DISPENSERMODE)
            {
                if (Datos.Length != 2)
                {
                    return;
                }

                m_PortData[Puerto].ToolStatus.DispenserMode = (DispenserMode_SF)Datos[0];
                if (m_PortData[Puerto].ToolStatus.DispenserMode == DispenserMode_SF.PROGRAM)
                {
                    m_StationData.Settings.SelectedProgram = (Datos[1]);
                }
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_W_DISPENSERMODE)
            {
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_R_PROGRAM)
            {
                if (Datos.Length != 21)
                {
                    return;
                }

                byte program = System.Convert.ToByte(Datos[0] - 1);                 //indexado 1-35
                m_StationData.Settings.Programs[program].Name     = Encoding.ASCII.GetString(Datos, 1, 8).Trim();
                m_StationData.Settings.Programs[program].Length_1 = BitConverter.ToUInt16(Datos, 9);
                m_StationData.Settings.Programs[program].Speed_1  = BitConverter.ToUInt16(Datos, 11);
                m_StationData.Settings.Programs[program].Length_2 = BitConverter.ToUInt16(Datos, 13);
                m_StationData.Settings.Programs[program].Speed_2  = BitConverter.ToUInt16(Datos, 15);
                m_StationData.Settings.Programs[program].Length_3 = BitConverter.ToUInt16(Datos, 17);
                m_StationData.Settings.Programs[program].Speed_3  = BitConverter.ToUInt16(Datos, 19);

                if (m_StationData.Settings.Programs[program].Name == "--------" &&
                    m_StationData.Settings.Programs[program].Length_1 == 0 &&
                    m_StationData.Settings.Programs[program].Speed_1 == 0 &&
                    m_StationData.Settings.Programs[program].Length_2 == 0 &&
                    m_StationData.Settings.Programs[program].Speed_2 == 0 &&
                    m_StationData.Settings.Programs[program].Length_3 == 0 &&
                    m_StationData.Settings.Programs[program].Speed_3 == 0)
                {
                    m_StationData.Settings.Programs[program].Enabled = OnOff._OFF;
                }
                else
                {
                    m_StationData.Settings.Programs[program].Enabled = OnOff._ON;
                }
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_W_PROGRAM)
            {
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_R_PROGRAMLIST)
            {
                if (Datos.Length != 35)
                {
                    return;
                }

                Array.Copy(Datos, m_StationData.Settings.ConcatenateProgramList, Datos.Length);
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_W_PROGRAMLIST)
            {
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_R_SPEED)
            {
                if (Datos.Length != 2)
                {
                    return;
                }

                //decimas de milimetro
                m_PortData[Puerto].ToolStatus.Speed.InMillimetersPerSecond(System.Convert.ToDouble((double)BitConverter.ToUInt16(Datos, 0) / 10));
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_W_SPEED)
            {
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_R_LENGTH)
            {
                if (Datos.Length != 2)
                {
                    return;
                }

                //decimas de milimetro
                m_PortData[Puerto].ToolStatus.Length.InMillimeters(System.Convert.ToDouble((double)BitConverter.ToUInt16(Datos, 0) / 10));
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_W_LENGTH)
            {
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_R_STARTFEEDING)
            {
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_R_STOPTFEEDING)
            {
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_R_FEEDING)
            {
                if (Datos.Length != 5)
                {
                    return;
                }

                m_PortData[Puerto].ToolStatus.FeedingState = (OnOff)(Datos[0]);

                if (m_PortData[Puerto].ToolStatus.DispenserMode == DispenserMode_SF.CONTINUOUS)
                {
                    m_PortData[Puerto].ToolStatus.FeedingPercent = System.Convert.ToUInt16(0);
                    m_PortData[Puerto].ToolStatus.FeedingLength.InMillimeters(BitConverter.ToUInt16(Datos, 1));
                }
                else if (m_PortData[Puerto].ToolStatus.DispenserMode == DispenserMode_SF.DISCONTINUOUS)
                {
                    m_PortData[Puerto].ToolStatus.FeedingPercent = BitConverter.ToUInt16(Datos, 1);
                    m_PortData[Puerto].ToolStatus.FeedingLength.InMillimeters(0);
                }
                else if (m_PortData[Puerto].ToolStatus.DispenserMode == DispenserMode_SF.PROGRAM)
                {
                    m_PortData[Puerto].ToolStatus.FeedingPercent = BitConverter.ToUInt16(Datos, 1);
                    m_PortData[Puerto].ToolStatus.FeedingLength.InMillimeters(0);
                    m_StationData.Settings.SelectedProgram = (Datos[3]);
                }
                else if (m_PortData[Puerto].ToolStatus.DispenserMode == DispenserMode_SF.CONCATENATION)
                {
                    m_PortData[Puerto].ToolStatus.FeedingPercent = BitConverter.ToUInt16(Datos, 1);
                    m_PortData[Puerto].ToolStatus.FeedingLength.InMillimeters(0);
                    m_StationData.Settings.SelectedProgram = (Datos[3]);
                }

                m_PortData[Puerto].ToolStatus.CurrentProgramStep = Datos[0];
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_R_BACKWARDMODE)
            {
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_W_BACKWARDMODE)
            {
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_RESETSTATION)
            {
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_R_PIN)
            {
                if (Datos.Length != 4)
                {
                    return;
                }

                m_StationData.Settings.PIN = Encoding.UTF8.GetString(Datos);
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_W_PIN)
            {
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_R_STATIONLOCKED)
            {
                if (Datos.Length != 1)
                {
                    return;
                }

                m_StationData.Settings.StationLocked = (OnOff)(Datos[0]);
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_W_STATIONLOCKED)
            {
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_R_BEEP)
            {
                if (Datos.Length != 1)
                {
                    return;
                }

                m_StationData.Settings.Beep = (OnOff)(Datos[0]);
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_W_BEEP)
            {
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_R_LENGTHUNIT)
            {
                if (Datos.Length != 1)
                {
                    return;
                }

                m_StationData.Settings.LengthUnit = (CLength.LengthUnit)(Datos[0]);
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_W_LENGTHUNIT)
            {
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_R_STATERROR)
            {
                if (Datos.Length != 1)
                {
                    return;
                }

                m_StationData.Status.ErrorStation = (StationError)(Datos[0]);
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_R_RESETERROR)
            {
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_R_DEVICENAME)
            {
                string TextoName = Encoding.UTF8.GetString(Datos);
                m_StationData.Settings.Name = TextoName;
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_W_DEVICENAME)
            {
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_R_COUNTERS)
            {
                if (Datos.Length != 20)
                {
                    return;
                }

                m_PortData[Puerto].Counters.ContTinLength   = (long)(BitConverter.ToUInt64(Datos, 0));
                m_PortData[Puerto].Counters.ContPlugMinutes = BitConverter.ToInt32(Datos, 8);
                m_PortData[Puerto].Counters.ContWorkMinutes = BitConverter.ToInt32(Datos, 12);
                m_PortData[Puerto].Counters.ContWorkCycles  = BitConverter.ToInt32(Datos, 16);
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_R_RESETCOUNTERS)
            {
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_R_COUNTERSP)
            {
                if (Datos.Length != 20)
                {
                    return;
                }

                m_PortData[Puerto].PartialCounters.ContTinLength   = (long)(BitConverter.ToUInt64(Datos, 0));
                m_PortData[Puerto].PartialCounters.ContPlugMinutes = BitConverter.ToInt32(Datos, 8);
                m_PortData[Puerto].PartialCounters.ContWorkMinutes = BitConverter.ToInt32(Datos, 12);
                m_PortData[Puerto].PartialCounters.ContWorkCycles  = BitConverter.ToInt32(Datos, 16);
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_R_RESETCOUNTERSP)
            {
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_R_USB_CONNECTSTATUS)
            {
                if (Datos.Length == 0)
                {
                    return;
                }

                sDatos = Encoding.UTF8.GetString(Datos);
                if (sDatos.IndexOf(':') >= 0)
                {
                    aDatos = sDatos.Split(':');
                    sTemp  = aDatos[1].Trim();
                }
                else
                {
                    sTemp = sDatos.Trim();
                }

                if (sTemp.ToUpper() == "C")
                {
                    m_StationData.Status.ControlMode = ControlModeConnection.CONTROL;
                }
                else
                {
                    m_StationData.Status.ControlMode = ControlModeConnection.MONITOR;
                }
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_W_USB_CONNECTSTATUS)
            {
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_R_RBT_CONNCONFIG)
            {
                if (Datos.Length != 7)
                {
                    return;
                }

                sDatos = Encoding.UTF8.GetString(Datos);

                m_StationData.Settings.Robot.Speed = (CRobotData.RobotSpeed)Datos[0];

                //Data bits in ASCII or number
                if (Datos[1] >= 0 && Datos[1] <= 9)
                {
                    m_StationData.Settings.Robot.DataBits = System.Convert.ToUInt16(Datos[1]);
                }
                else
                {
                    m_StationData.Settings.Robot.DataBits = System.Convert.ToUInt16(System.Convert.ToUInt16(Datos[1] - 48));
                }

                switch (sDatos.Substring(2, 1))
                {
                case "E":
                case "e":
                    m_StationData.Settings.Robot.Parity = CRobotData.RobotParity.Even;
                    break;

                case "O":
                case "o":
                    m_StationData.Settings.Robot.Parity = CRobotData.RobotParity.Odd;
                    break;

                default:
                    m_StationData.Settings.Robot.Parity = CRobotData.RobotParity.None;
                    break;
                }

                if (Datos[3] == 2 || sDatos.Substring(3, 1) == "2")
                {
                    m_StationData.Settings.Robot.StopBits = CRobotData.RobotStop.bits_2;
                }
                else
                {
                    m_StationData.Settings.Robot.StopBits = CRobotData.RobotStop.bits_1;
                }

                if (Datos[4] == 1 || sDatos.Substring(4, 1) == "1")
                {
                    m_StationData.Settings.Robot.Protocol = CRobotData.RobotProtocol.RS485;
                }
                else
                {
                    m_StationData.Settings.Robot.Protocol = CRobotData.RobotProtocol.RS232;
                }

                //big endian
                ushort nID = default(ushort);
                //ID in ASCII or number
                if (Datos[5] >= 0 && Datos[5] <= 9)
                {
                    nID  = System.Convert.ToUInt16(System.Convert.ToUInt16(Datos[5] * 10));
                    nID += System.Convert.ToUInt16(Datos[6]);
                }
                else
                {
                    nID  = System.Convert.ToUInt16(System.Convert.ToUInt16((Datos[5] - 48) * 10));
                    nID += System.Convert.ToUInt16(System.Convert.ToUInt16(Datos[6] - 48));
                }
                //UInt16.TryParse(sDatos.Substring(5, 2), nID)
                m_StationData.Settings.Robot.Address = nID;
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_W_RBT_CONNCONFIG)
            {
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_R_RBT_CONNECTSTATUS)
            {
                if (Datos.Length != 1)
                {
                    return;
                }

                sDatos = Encoding.UTF8.GetString(Datos);

                switch (sDatos)
                {
                case "C":
                case "c":
                    m_StationData.Settings.Robot.Status = OnOff._ON;
                    break;

                default:
                    m_StationData.Settings.Robot.Status = OnOff._OFF;
                    break;
                }
            }
            else if (Command == (byte)EnumCommandFrame_02_SF.M_W_RBT_CONNECTSTATUS)
            {
            }
            else
            {
                //No hacer nada
            }
        }
Beispiel #9
0
        public void ProcessMessageResponse(uint Numstream, byte[] Datos, byte Command, byte Origen)
        {
            //
            //Check source address
            //
            if (Origen != m_StationNumDevice)
            {
                //Para las sub estaciones sólo escuchamos a la siguiente dirección (DME(0x10) -> PSE(0x20) -> PSE (0x30))
                if (m_StationData.Info.Features.SubStations && (m_StationNumDevice + (int)EnumAddress.NEXT_SUBSTATION_ADDRESS) == Origen)
                {
                    //Las direcciones que vengan del mismo bloque de estación
                }
                else if ((Origen & (byte)EnumAddress.MASK_STATION_ADDRESS) == m_StationNumDevice)
                {
                }
                else
                {
                    return;
                }
            }


            //
            //Sent message
            //
            MessageHashtable.Message MessageInt = new MessageHashtable.Message();
            int    Puerto = 0;
            int    Intake = 0;
            string sDatos = "";

            string[] aDatos = null;
            string   sTemp  = "";

            //Recuperar mensaje
            if (m_MessagesSentManager.ReadMessage(Numstream, ref MessageInt))
            {
                m_MessagesSentManager.RemoveMessage(Numstream);

                //Mensajes recibidos sin petición. (Firmware -> sub estación)
                //Para la DME touch enviamos las peticiones del modo continuo al dspic33 en vez de a la estación
            }
            else if (Command != (byte)EnumCommandFrame_02_FE.M_HS &
                     Command != (byte)EnumCommandFrame_02_FE.M_NACK &
                     Command != (byte)EnumCommandFrame_02_FE.M_FIRMWARE)
            {
                return;
            }


            //
            //Command
            //
            if (Command == (byte)EnumCommandFrame_02_FE.M_HS)
            {
                //Si se recibe una trama de handshake de otra dirección, es posible que se trate de otra estación
                if (Origen != m_StationNumDevice)
                {
                    ReadDeviceVersions(Origen);
                }
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_EOT)
            {
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_ACK)
            {
                if (EndedTransactionEvent != null)
                {
                    EndedTransactionEvent(Numstream);
                }
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_NACK)
            {
                Debug.Print("NACK Error: {0} Sent opcode: H{1:X2}", (Datos[0]).ToString(), Datos[1]);
                if (NACKTransactionEvent != null)
                {
                    NACKTransactionEvent(Numstream);
                }
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_SYN)
            {
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_R_DEVICEID)
            {
                clsStationUID stationUUID = new clsStationUID(Datos);
                m_StationData.Info.UUID = stationUUID.UID;
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_W_DEVICEID)
            {
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_RESET)
            {
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_FIRMWARE)
            {
                if (Datos.Length == 0)
                {
                }

                string   datosVersions = Encoding.UTF8.GetString(Datos);
                string[] arrayVersions = datosVersions.Split(':');
                if (arrayVersions.Length < 4)
                {
                }

                //protocolo
                string protocolo = arrayVersions[0];

                //modelo
                string   model          = arrayVersions[1];
                string[] arrayModelData = arrayVersions[1].Split('_');
                string   modelModel     = arrayModelData[0];

                string modelType = "";
                if (arrayModelData.Length > 1)
                {
                    modelType = arrayModelData[1];
                }

                int modelVersion = -1;
                if (arrayModelData.Length > 2)
                {
                    if (Information.IsNumeric(arrayModelData[2]))
                    {
                        modelVersion = int.Parse(arrayModelData[2]);
                    }
                }

                //soft y hard versions
                string versionSw = arrayVersions[2];
                string versionHw = arrayVersions[3];

                //La trama viene del micro principal
                if (Origen == m_StationNumDevice)
                {
                    m_StationData.Info.Protocol         = protocolo;
                    m_StationData.Info.Model            = modelModel;
                    m_StationData.Info.ModelType        = modelType;
                    m_StationData.Info.ModelVersion     = modelVersion;
                    m_StationData.Info.Version_Software = versionSw;
                    m_StationData.Info.Version_Hardware = versionHw;

                    //La trama viene de una estación conectada a otra estación (p.e. DME -> PSE -> PSE -> PSE)
                }
                else if (((Origen & (byte)EnumAddress.MASK_STATION_ADDRESS) == Origen) && CheckStationModel(model))
                {
                    CConnectionData connectionData = new CConnectionData();
                    //connectionData.Mode -> no es necesario por que será el mismo que el padre
                    //connectionData.pSerialPort -> no es necesario por que será el mismo que el padre
                    //connectionData.PCNumDevice -> no es necesario por que será el mismo que el padre
                    connectionData.StationNumDevice = Origen;
                    //connectionData.FrameProtocol = -> no es necesario por que será el mismo que el padre
                    //connectionData.CommandProtocol -> no es necesario por que será el mismo que el padre
                    connectionData.StationModel    = model;
                    connectionData.SoftwareVersion = versionSw;
                    connectionData.HardwareVersion = versionHw;

                    if (Detected_SubStationEvent != null)
                    {
                        Detected_SubStationEvent(connectionData);
                    }
                }


                //Guardamos la información del micro
                if ((Origen & (byte)EnumAddress.MASK_STATION_ADDRESS) == m_StationNumDevice)
                {
                    //Guardar información del micro
                    if (!m_StationData.Info.StationMicros.Contains(Origen))
                    {
                        CFirmwareStation micro = new CFirmwareStation();
                        micro.Model           = m_StationData.Info.Model;
                        micro.HardwareVersion = versionHw;
                        micro.SoftwareVersion = versionSw;
                        m_StationData.Info.StationMicros.Add(Origen, micro);
                    }
                }
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_CLEARMEMFLASH)
            {
                if (ClearingFlashFinishedEvent != null)
                {
                    ClearingFlashFinishedEvent();
                }
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_SENDMEMADDRESS)
            {
                if (AddressMemoryFlashFinishedEvent != null)
                {
                    AddressMemoryFlashFinishedEvent();
                }
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_SENDMEMDATA)
            {
                if (DataMemoryFlashFinishedEvent != null)
                {
                    DataMemoryFlashFinishedEvent();
                }
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_ENDPROGR)
            {
                if (EndProgFinishedEvent != null)
                {
                    EndProgFinishedEvent();
                }
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_R_SUCTIONLEVEL)
            {
                if (Datos.Length != 1)
                {
                    return;
                }

                //valor común para todos los puertos
                for (int i = 0; i <= m_PortData.Length - 1; i++)
                {
                    m_PortData[i].ToolStatus.SuctionLevel = (SuctionLevel_FE)(Datos[0]);
                }
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_W_SUCTIONLEVEL)
            {
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_R_FLOW)
            {
                if (Datos.Length != 2)
                {
                    return;
                }

                //valor común para todos los puertos
                for (int i = 0; i <= m_PortData.Length - 1; i++)
                {
                    m_PortData[i].ToolStatus.Flow = BitConverter.ToUInt16(Datos, 0);
                }
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_R_SPEED)
            {
                if (Datos.Length != 2)
                {
                    return;
                }

                //valor común para todos los puertos
                for (int i = 0; i <= m_PortData.Length - 1; i++)
                {
                    m_PortData[i].ToolStatus.Speed = BitConverter.ToUInt16(Datos, 0);
                }
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_R_SELECTFLOW)
            {
                if (Datos.Length != 2)
                {
                    return;
                }

                //valor común para todos los puertos
                for (int i = 0; i <= m_PortData.Length - 1; i++)
                {
                    m_PortData[i].ToolStatus.SelectedFlow_x_Mil = BitConverter.ToUInt16(Datos, 0);
                }
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_W_SELECTFLOW)
            {
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_R_STANDINTAKES)
            {
                if (Datos.Length != 1)
                {
                    return;
                }

                m_PortData[Puerto].ToolStatus.StandIntakes = Datos[0];
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_W_STANDINTAKES)
            {
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_R_INTAKEACTIVATION)
            {
                if (Datos.Length != 1)
                {
                    return;
                }

                if (Intake == (int)ToolStatus_FE.WORK)
                {
                    m_PortData[Puerto].ToolStatus.IntakeActivationWork = (OnOff)(Datos[0]);
                }
                else if (Intake == (int)ToolStatus_FE.STAND)
                {
                    m_PortData[Puerto].ToolStatus.IntakeActivationStand = (OnOff)(Datos[0]);
                }
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_W_INTAKEACTIVATION)
            {
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_R_SUCTIONDELAY)
            {
                if (Datos.Length != 4)
                {
                    return;
                }

                if (Intake == (int)ToolStatus_FE.WORK)
                {
                    m_PortData[Puerto].ToolStatus.SuctionDelayWork = BitConverter.ToUInt16(Datos, 0);
                }
                else if (Intake == (int)ToolStatus_FE.STAND)
                {
                    m_PortData[Puerto].ToolStatus.SuctionDelayStand = BitConverter.ToUInt16(Datos, 0);
                }
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_W_SUCTIONDELAY)
            {
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_R_DELAYTIME)
            {
                if (Datos.Length != 4)
                {
                    return;
                }

                if (Intake == (int)ToolStatus_FE.WORK)
                {
                    m_PortData[Puerto].ToolStatus.TimeToStopSuctionWork = BitConverter.ToUInt16(Datos, 0);
                }
                else if (Intake == (int)ToolStatus_FE.STAND)
                {
                    m_PortData[Puerto].ToolStatus.TimeToStopSuctionStand = BitConverter.ToUInt16(Datos, 0);
                }
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_R_ACTIVATIONPEDAL)
            {
                if (Datos.Length != 2)
                {
                    return;
                }

                if (Datos[0] == 0)
                {
                    m_PortData[Puerto].ToolStatus.PedalActivation = PedalAction.HOLD_DOWN;
                }
                else if (Datos[0] == 1)
                {
                    m_PortData[Puerto].ToolStatus.PedalActivation = PedalAction.PULSE;
                }
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_W_ACTIVATIONPEDAL)
            {
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_R_PEDALMODE)
            {
                if (Datos.Length != 2)
                {
                    return;
                }

                m_PortData[Puerto].ToolStatus.PedalMode = (PedalMode)(Datos[0]);
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_W_PEDALMODE)
            {
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_R_FILTERSTATUS)
            {
                if (Datos.Length != 2)
                {
                    return;
                }

                //valor común para todos los puertos
                for (int i = 0; i <= m_PortData.Length - 1; i++)
                {
                    m_PortData[i].ToolStatus.FilterStatus = BitConverter.ToUInt16(Datos, 0);
                }
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_R_RESETFILTER)
            {
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_RESETSTATION)
            {
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_R_PIN)
            {
                if (Datos.Length != 4)
                {
                    return;
                }

                m_StationData.Settings.PIN = Encoding.UTF8.GetString(Datos);
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_W_PIN)
            {
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_R_BEEP)
            {
                if (Datos.Length != 1)
                {
                    return;
                }

                m_StationData.Settings.Beep = (OnOff)(Datos[0]);
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_W_BEEP)
            {
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_R_CONTINUOUSSUCTION)
            {
                if (Datos.Length != 1)
                {
                    return;
                }

                m_StationData.Settings.ContinuousSuction = (OnOff)(Datos[0]);
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_W_CONTINUOUSSUCTION)
            {
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_R_STATERROR)
            {
                if (Datos.Length != 2)
                {
                    return;
                }

                m_StationData.Status.ErrorStation = (StationError)(BitConverter.ToInt16(Datos, 0));
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_R_DEVICENAME)
            {
                string TextoName = Encoding.UTF8.GetString(Datos);
                m_StationData.Settings.Name = TextoName;
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_W_DEVICENAME)
            {
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_R_COUNTERS)
            {
                if (Datos.Length != 40)
                {
                    return;
                }

                m_PortData[0].Counters.ContPlugMinutes        = BitConverter.ToInt32(Datos, 0);
                m_PortData[1].Counters.ContPlugMinutes        = BitConverter.ToInt32(Datos, 4);
                m_PortData[0].Counters.ContIdleMinutes        = BitConverter.ToInt32(Datos, 8);
                m_PortData[1].Counters.ContIdleMinutes        = BitConverter.ToInt32(Datos, 12);
                m_PortData[0].Counters.ContWorkIntakeMinutes  = BitConverter.ToInt32(Datos, 16);
                m_PortData[1].Counters.ContWorkIntakeMinutes  = BitConverter.ToInt32(Datos, 20);
                m_PortData[0].Counters.ContStandIntakeMinutes = BitConverter.ToInt32(Datos, 24);
                m_PortData[1].Counters.ContStandIntakeMinutes = BitConverter.ToInt32(Datos, 28);
                m_PortData[0].Counters.ContWorkCycles         = BitConverter.ToInt32(Datos, 32);
                m_PortData[1].Counters.ContWorkCycles         = BitConverter.ToInt32(Datos, 36);
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_R_RESETCOUNTERS)
            {
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_R_COUNTERSP)
            {
                if (Datos.Length != 40)
                {
                    return;
                }

                m_PortData[0].PartialCounters.ContPlugMinutes        = BitConverter.ToInt32(Datos, 0);
                m_PortData[1].PartialCounters.ContPlugMinutes        = BitConverter.ToInt32(Datos, 4);
                m_PortData[0].PartialCounters.ContIdleMinutes        = BitConverter.ToInt32(Datos, 8);
                m_PortData[1].PartialCounters.ContIdleMinutes        = BitConverter.ToInt32(Datos, 12);
                m_PortData[0].PartialCounters.ContWorkIntakeMinutes  = BitConverter.ToInt32(Datos, 16);
                m_PortData[1].PartialCounters.ContWorkIntakeMinutes  = BitConverter.ToInt32(Datos, 20);
                m_PortData[0].PartialCounters.ContStandIntakeMinutes = BitConverter.ToInt32(Datos, 24);
                m_PortData[1].PartialCounters.ContStandIntakeMinutes = BitConverter.ToInt32(Datos, 28);
                m_PortData[0].PartialCounters.ContWorkCycles         = BitConverter.ToInt32(Datos, 32);
                m_PortData[1].PartialCounters.ContWorkCycles         = BitConverter.ToInt32(Datos, 36);
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_R_RESETCOUNTERSP)
            {
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_R_USB_CONNECTSTATUS)
            {
                if (Datos.Length == 0)
                {
                    return;
                }

                sDatos = Encoding.UTF8.GetString(Datos);
                if (sDatos.IndexOf(':') >= 0)
                {
                    aDatos = sDatos.Split(':');
                    sTemp  = aDatos[1].Trim();
                }
                else
                {
                    sTemp = sDatos.Trim();
                }

                if (sTemp.ToUpper() == "C")
                {
                    m_StationData.Status.ControlMode = ControlModeConnection.CONTROL;
                }
                else
                {
                    m_StationData.Status.ControlMode = ControlModeConnection.MONITOR;
                }
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_W_USB_CONNECTSTATUS)
            {
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_R_RBT_CONNCONFIG)
            {
                if (Datos.Length != 7)
                {
                    return;
                }

                sDatos = Encoding.UTF8.GetString(Datos);

                m_StationData.Settings.Robot.Speed = ((CRobotData.RobotSpeed)(Datos[0]));

                //Data bits in ASCII or number
                if (Datos[1] >= 0 && Datos[1] <= 9)
                {
                    m_StationData.Settings.Robot.DataBits = System.Convert.ToUInt16(Datos[1]);
                }
                else
                {
                    m_StationData.Settings.Robot.DataBits = System.Convert.ToUInt16(System.Convert.ToUInt16(Datos[1] - 48));
                }

                switch (sDatos.Substring(2, 1))
                {
                case "E":
                case "e":
                    m_StationData.Settings.Robot.Parity = CRobotData.RobotParity.Even;
                    break;

                case "O":
                case "o":
                    m_StationData.Settings.Robot.Parity = CRobotData.RobotParity.Odd;
                    break;

                default:
                    m_StationData.Settings.Robot.Parity = CRobotData.RobotParity.None;
                    break;
                }

                if (Datos[3] == 2 || sDatos.Substring(3, 1) == "2")
                {
                    m_StationData.Settings.Robot.StopBits = CRobotData.RobotStop.bits_2;
                }
                else
                {
                    m_StationData.Settings.Robot.StopBits = CRobotData.RobotStop.bits_1;
                }

                if (Datos[4] == 1 || sDatos.Substring(4, 1) == "1")
                {
                    m_StationData.Settings.Robot.Protocol = CRobotData.RobotProtocol.RS485;
                }
                else
                {
                    m_StationData.Settings.Robot.Protocol = CRobotData.RobotProtocol.RS232;
                }

                //big endian
                ushort nID = default(ushort);
                //ID in ASCII or number
                if (Datos[5] >= 0 && Datos[5] <= 9)
                {
                    nID  = System.Convert.ToUInt16(System.Convert.ToUInt16(Datos[5] * 10));
                    nID += System.Convert.ToUInt16(Datos[6]);
                }
                else
                {
                    nID  = System.Convert.ToUInt16(System.Convert.ToUInt16((Datos[5] - 48) * 10));
                    nID += System.Convert.ToUInt16(System.Convert.ToUInt16(Datos[6] - 48));
                }
                //UInt16.TryParse(sDatos.Substring(5, 2), nID)
                m_StationData.Settings.Robot.Address = nID;
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_W_RBT_CONNCONFIG)
            {
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_R_RBT_CONNECTSTATUS)
            {
                if (Datos.Length != 1)
                {
                    return;
                }

                sDatos = Encoding.UTF8.GetString(Datos);

                switch (sDatos)
                {
                case "C":
                case "c":
                    m_StationData.Settings.Robot.Status = OnOff._ON;
                    break;

                default:
                    m_StationData.Settings.Robot.Status = OnOff._OFF;
                    break;
                }
            }
            else if (Command == (byte)EnumCommandFrame_02_FE.M_W_RBT_CONNECTSTATUS)
            {
            }
            else
            {
                //No hacer nada
            }
        }