Пример #1
0
        private void DoWork_Toggle(object sender, DoWorkEventArgs e)
        {
            try
            {
                TCP_Write_Read TCP_WriteRead = new TCP_Write_Read(IP_address_ReadWriteTab, Port_ReadWriteTab);

                // if the button is checked, write true
                if (WriteVarBOOL_ObservableCollection[_tag].Value.ToString() != "")
                {
                    if (TCP_WriteRead.CheckConnection())
                    {
                        TCP_WriteRead.Write_VariableValueString(WriteVarBOOL_ObservableCollection[_tag].Value.ToString(), "TRUE");
                        Status_ReadWrite_ViewModel = "Writing: " + WriteVarBOOL_ObservableCollection[_tag].Value.ToString() + " : " + "TRUE";
                        TCP_WriteRead.Write_VariableValueString(WriteVarBOOL_ObservableCollection[_tag].Value.ToString(), "FALSE");
                        Status_ReadWrite_ViewModel = "Writing: " + WriteVarBOOL_ObservableCollection[_tag].Value.ToString() + " : " + "FALSE";
                    }
                    else
                    {
                        throw new ArgumentException("Cannot connect to the Server", "TCP Client  - ToggleButton");
                    }
                }
            }
            catch (Exception exc)
            {
                Exception_ReadWrite_ViewModel = exc.ToString();
            }
        }
Пример #2
0
        private void DoWork_ReadVar(object sender, DoWorkEventArgs e)
        {
            try
            {
                TCP_Write_Read TCP_WriteRead = new TCP_Write_Read(IP_address_ReadWriteTab, Port_ReadWriteTab);

                if (TCP_WriteRead.CheckConnection())
                {
                    for (int i = 0; i < ReadVar_ObservableCollection.Count; i++)
                    {
                        if (ReadVar_ObservableCollection[i].Value.ToString() != "")
                        {
                            ReadVal_ObservableCollection[i].Value = TCP_WriteRead.Read_VariableValueString(ReadVar_ObservableCollection[i].Value.ToString());
                            _readVarWorker.ReportProgress(i);
                        }
                    }
                }
                else
                {
                    throw new ArgumentException("Cannot connect to the Server", "TCP Client - ReadVarButton");
                }
            }

            catch (Exception exc)
            {
                Exception_ReadWrite_ViewModel = exc.ToString();
            }
        }
Пример #3
0
        private void DoWork_CheckConnection(object sender, DoWorkEventArgs e)
        {
            try
            {
                StatusText = "Trying to connect...    " + DateTime.Now.ToString();

                TCP_Write_Read TCP_WriteRead = new TCP_Write_Read(IP_Address, Port);

                if (TCP_WriteRead.CheckConnection())
                {
                    StatusText = "Connection works   " + DateTime.Now.ToString();
                }
                else
                {
                    StatusText = "Connection doesn't work   " + DateTime.Now.ToString();
                }
            }
            catch (Exception exc)
            {
                ExceptionText = exc.ToString() + "\n" + DateTime.Now.ToString();
            }
        }
        private void DoWork_Transfer(object sender, DoWorkEventArgs e)
        {
            _transferParameters_Worker.ReportProgress(0);
            {
                String reqDataKUKA = "";
                String ReqP        = "";
                String pointerInt  = "0";
                int    pointer;
                _transferParameters_BackgroundworkerDisposed = false;
                // string array to send to kuka, it is longer because the array on the kuka is longer than the one on the PLC
                String[] parametersToSend = new String[_transferFormatParameters_struc.FormatParametersCount_int + 2]; //( +2 is because KUKA array is longer than the PLCs array for 2 parameters)
                try
                {
                    TCP_Write_Read TCP_WriteRead = new TCP_Write_Read(IP_Address_ToFormatParViewModel, Port_ToFormatParViewModel);

                    if (TCP_WriteRead.CheckConnection())
                    {
                        reqDataKUKA = TCP_WriteRead.returnVarValue(TCP_WriteRead.Read_VariableValueString(_transferFormatParameters_struc.TransferReq_String), '=', ' ');

                        if (reqDataKUKA == "TRUE")
                        {
                            while (!(Convert.ToInt32(pointerInt) >= _transferFormatParameters_struc.FormatParametersCount_int))
                            {
                                //read reqdata value
                                reqDataKUKA = TCP_WriteRead.returnVarValue(TCP_WriteRead.Read_VariableValueString(_transferFormatParameters_struc.TransferReq_String), '=', ' ');

                                if (reqDataKUKA == "TRUE")
                                {
                                    //read pointer value
                                    pointerInt = TCP_WriteRead.returnVarValue(TCP_WriteRead.Read_VariableValueString(_transferFormatParameters_struc.ParameterPointer_String), '=', ' ');
                                    //report value of the pointer to update the progress bar
                                    pointer = Convert.ToInt32(pointerInt);
                                    _transferParameters_Worker.ReportProgress(pointer);

                                    //prepare parameters to send to KUKA
                                    for (int i = 0; i < parametersToSend.Length; i++)
                                    {
                                        parametersToSend[i] = _transferFormatParameters_struc.FormatValues_StringArray[i];
                                        if (i == _transferFormatParameters_struc.FormatParametersCount_int - 1)
                                        {
                                            // send the rest of the values as zeros
                                            for (int k = _transferFormatParameters_struc.FormatParametersCount_int; k < parametersToSend.Length; k++)
                                            {
                                                parametersToSend[k] = "0";
                                            }
                                            break;
                                        }
                                    }

                                    //write the variable of the "Parameter to send" text with the value "ParametersToSend" at position "pointerInt"
                                    TCP_WriteRead.Write_VariableValueString(_transferFormatParameters_struc.ParameterToSend_String, parametersToSend[Convert.ToInt32(pointerInt)]);
                                    //write par valid to the kuka
                                    TCP_WriteRead.Write_VariableValueString(_transferFormatParameters_struc.ParameterValid_String, "TRUE");
                                    ReqP = TCP_WriteRead.returnVarValue(TCP_WriteRead.Read_VariableValueString(_transferFormatParameters_struc.TransferReq_String), '=', ' ');

                                    if (ReqP == "FALSE")
                                    {
                                        TCP_WriteRead.Write_VariableValueString(_transferFormatParameters_struc.ParameterValid_String, "FALSE");
                                    }
                                }
                            }
                        }
                        else
                        {
                            Status_FormatParameters_Tab = "Format parameters are not requested, check if KUKA is in the loadparPal.src" + DateTime.Now;
                            _transferParameters_Worker.CancelAsync();
                            _transferParameters_Worker.Dispose();
                            _transferParameters_BackgroundworkerDisposed = true;
                        }
                    }
                    else
                    {
                        throw new ArgumentException("Cannot connect to the Server", "TCP Client  - Formar Parameters");
                    }
                }
                catch (Exception exc)
                {
                    Exception_FormatParameters_Tab = exc.ToString();
                }
            }
        }