예제 #1
0
        private bool CheckReaPiLibrary()
        {
            string log     = "";
            bool   library = true;

            try
            {
                log  = "Informacja o bibliotece ReaPi.dll" + Environment.NewLine;
                log += "ReaPi Info: " + ReaPi.GetLibInfo() + Environment.NewLine;
                log += "Revision: " + ReaPi.GetRevision();
            }
            catch (Exception e)
            {
                log = "Brak bibliotek ReaPi.dll";
                AppLogger.GetLogger().Fatal(log, e);

                library = false;
            }
            finally
            {
                SendToDashboard(MessageType.LOG, log, null, null);
            }

            return(library);
        }
예제 #2
0
        private void CmdGetOutputLevelResponse(ReaPi.ResponseHandle response, GetIOOutputLevelResponseEventArgs getIOOutputLevelResponseEventArgs)
        {
            int error = 0;
            List <GetIOOutputLevelResponseEventArgs.IOOutput> listIOOutputs = new List <GetIOOutputLevelResponseEventArgs.IOOutput>();
            int count = ReaPi.GetNumberOfOutputs(response, out error);

            for (int i = 1; i <= count; i++)
            {
                GetIOOutputLevelResponseEventArgs.IOOutput ioOutput = new GetIOOutputLevelResponseEventArgs.IOOutput();
                ioOutput.Index = i;
                ioOutput.Level = ReaPi.GetIOOutputLevelValue(response, i, out error);

                listIOOutputs.Add(ioOutput);
            }

            List <bool> outputsState = new List <bool>();

            for (int i = 0; i < getIOOutputLevelResponseEventArgs.IOOutputs.Count; i++)
            {
                outputsState.Add((bool)getIOOutputLevelResponseEventArgs.IOOutputs[i].Level);
            }
            try
            {
                _view.UpdateOutputsState(outputsState);
            }
            catch (Exception) { }
        }
예제 #3
0
        public void RJSetIOConfiguration(string fileName)
        {
            if (rjConnection.ConnectionID <= 0)
            {
                return;
            }

            ReaPi.SetIOConfiguration(rjConnection.ConnectionID, rjConnection.Job.JobId, fileName);
        }
예제 #4
0
        public void RJClearJob()
        {
            if (rjConnection.ConnectionID <= 0)
            {
                return;
            }

            ReaPi.ClearJob(rjConnection.ConnectionID, 1);
        }
예제 #5
0
 public RJConnect(ReaPi.ConnectionIdentifier connectionID, Version protocolVersion)
 {
     ConnectionID    = connectionID;
     ProtocolVersion = protocolVersion;
     //Job = (RJJob)null;
     Job                = new RJJob();
     IOConfiguration    = "";
     LabelContentHandle = ReaPi.CreateLabelContent();
 }
예제 #6
0
        private void SetLabelContent(List <DTOVariableContent> dtoVC)
        {
            try
            {
                if (rjConnection.ConnectionID <= 0)
                {
                    return;
                }

                ReaPi.EErrorCode         error = ReaPi.RemoveLabelContent(rjConnection.LabelContentHandle);
                ReaPi.LabelContentHandle labelContentHandle = ReaPi.CreateLabelContent();

                rjConnection.LabelContentHandle = labelContentHandle;

                if (labelContentHandle >= (ReaPi.LabelContentHandle) 0)
                {
                    foreach (var lp in dtoVC)
                    {
                        error = ReaPi.PrepareLabelContent(labelContentHandle, 1, lp.GroupName, lp.ObjectName, lp.ContentName, lp.ContentValue);

                        if (error != ReaPi.EErrorCode.OK)
                        {
                            SendToDashboard(MessageType.LOG, "Error: Nie można przygotować danych dla pola: {lp.ContentName}", error.ToString(), null);
                        }
                    }

                    ReaPi.ResponseHandle response = ReaPi.SetLabelContent(rjConnection.ConnectionID, labelContentHandle);

                    if (response < 0)
                    {
                        SendToDashboard(MessageType.LOG, "Error: Nie można wysłać danych dla etykiety", null, null);
                    }
                    else
                    {
                        SendToDashboard(MessageType.LOG, $"Wysłano zawartość rekordu: {database.ActualRecord.ToString()}", null, null);

                        Record record = new Record();
                        record.Id      = database.ActualRecord;
                        record.IsError = false;

                        _queueRecords.Enqueue(record);
                    }
                }
                else
                {
                    SendToDashboard(MessageType.LOG, "Error: Nie można przygotować danych dla etykiety", null, null);
                }
            }
            catch (FormatException ex)
            {
                SendToDashboard(MessageType.ERROR, "Function SetLabelContent()", ex.ToString(), ex.Message.ToString());
            }
        }
예제 #7
0
 public void RJConnect(string ipAddress)
 {
     if (rjConnection == null || rjConnection.ConnectionID <= 0)
     {
         try
         {
             ReaPi.Connect("TCP://" + ipAddress);
         }
         catch (Exception e) {
             AppLogger.GetLogger().Error($"Błąd połączenia z IP: {ipAddress}", e);
         }
     }
 }
예제 #8
0
        private void RegisterConnection()
        {
            _connectionCallback = new ReaPi.connectionCallbackPtr(OnConnectionCallback);
            ReaPi.EErrorCode tmpError = ReaPi.RegisterConnectionCallback(_connectionCallback, new IntPtr(0));

            if (tmpError == ReaPi.EErrorCode.OK)
            {
                SendToDashboard(MessageType.LOG, "RegisterConnectionCallback() - Status.OK", "", "");
            }
            else
            {
                SendToDashboard(MessageType.LOG, "RegisterConnectionCallback() - Status.Error", tmpError.ToString(), "");
            }
        }
예제 #9
0
        private void OnConnectionCallback(
            ReaPi.ConnectionIdentifier connectionId,
            ReaPi.EConnState state,
            ReaPi.EErrorCode errorCode,
            IntPtr context)
        {
            if (state == ReaPi.EConnState.CONNECT)
            {
                if (connectionId > 0)
                {
                    if (errorCode != ReaPi.EErrorCode.OK)
                    {
                        SendToDashboard(MessageType.ERROR, "Błąd podczas połączenia ze sterownikiem!", errorCode.ToString(), "OnConnectionCallback");
                        return;
                    }

                    rjConnection = new RJConnect(connectionId, null);

                    _responseCallback = new ReaPi.responseCallbackPtr(OnResponseCallback);
                    ReaPi.RegisterResponseCallback(connectionId, _responseCallback, context);

                    _eventCallback = new ReaPi.eventCallbackPtr(OnEventCallback);
                    ReaPi.RegisterEventCallback(connectionId, _eventCallback, context);

                    OnConnect(connectionId);
                }
                else
                {
                    SendToDashboard(MessageType.ERROR, $"Nieprawidłowy IdConnection: <{connectionId}>.", null, "OnConnectionCallback");
                    _view.ShowProblemSolution(ErrorType.errorConnection);
                }
            }
            else if (state == ReaPi.EConnState.DISCONNECT)
            {
                if (errorCode != ReaPi.EErrorCode.OK)
                {
                    SendToDashboard(MessageType.ERROR, "Błąd podczas rozłączenia ze sterownikiem!", errorCode.ToString(), "OnConnectionCallback");
                }

                OnDisconnect(connectionId);
            }
            else if (state == ReaPi.EConnState.CONNECTIONERROR)
            {
                SendToDashboard(MessageType.ERROR, "Błąd podczas połączenia <" + connectionId + ">.", errorCode.ToString(), "OnConnectionCallback");
                UpdateDashboard(EventType.DISCONNECT);

                _view.ShowProblemSolution(ErrorType.errorConnection);
            }
        }
예제 #10
0
        public void RJDisconnect()
        {
            try
            {
                if (rjConnection.ConnectionID <= 0)
                {
                    return;
                }

                ReaPi.Disconnect(rjConnection.ConnectionID);
            }
            catch (Exception e) {
                AppLogger.GetLogger().Error($"Błąd rozłączenia połączenia i ID: {rjConnection.ConnectionID}", e);
            }
        }
예제 #11
0
        private void OnConnect(ReaPi.ConnectionIdentifier connectionId)
        {
            string lastError = "";

            rjConnection.ProtocolVersion = new Version(ReaPi.GetProtocolVersion(rjConnection.ConnectionID));

            lastError = ReaPi.SubscribeJobSet(rjConnection.ConnectionID, 1).ToString();
            lastError = ReaPi.SubscribeIOConfigurationSet(rjConnection.ConnectionID, 1).ToString();
            lastError = ReaPi.GetIOOutputLevel(rjConnection.ConnectionID).ToString();

            //SetOutputLevel(OutputTypeReaction.ControlDivert, OutputLevel.Low);
            //SetOutputLevel(OutputTypeReaction.ControlStacker, OutputLevel.Low);

            SendToDashboard(MessageType.LOG, "Połączenie: OK", $" Wskaźnik połączenia: {rjConnection.ConnectionID.ToString()}.", null);
            SendToDashboard(MessageType.ERROR, lastError, null, null);
            UpdateDashboard(EventType.CONNECT);
        }
예제 #12
0
        private void OnJobSetEvent(ReaPi.ConnectionIdentifier connection, int job, string jobFileName)
        {
            SendToDashboard(MessageType.EVENT, $"Job: <{jobFileName}>", null, null);

            if (!string.IsNullOrEmpty(jobFileName))
            {
                try
                {
                    rjConnection.Job = new RJJob(job, jobFileName);

                    if (rjConnection.Job.VariableContents.Count > 0)
                    {
                        ISet <string> groups = rjConnection.Job.GetGroups();
                        //subskrypcja dla każdej grupy
                        foreach (var group in groups)
                        {
                            ReaPi.SubscribeInvalidContent(connection, job, group).ToString();
                            ReaPi.SubscribeBufferFull(connection, job, group).ToString();
                        }
                    }
                }
                catch (Exception) { }

                string logError;

                logError  = ReaPi.SubscribeJobStarted(connection, job).ToString();
                logError += ReaPi.SubscribeJobStopped(connection, job).ToString();
                logError += ReaPi.SubscribeIOConfigurationSet(connection, job).ToString();
                logError += ReaPi.SubscribePrintTrigger(connection, job).ToString();
                logError += ReaPi.SubscribePrintStart(connection, job).ToString();
                logError += ReaPi.SubscribePrintRejected(connection, job).ToString();
                logError += ReaPi.SubscribePrintEnd(connection, job).ToString();
                logError += ReaPi.SubscribePrintAborted(connection, job).ToString();
                logError += ReaPi.SubscribePrintSpeedError(connection, job).ToString();
                logError += ReaPi.SubscribeMissingContent(connection, job).ToString();

                SendToDashboard(MessageType.ERROR, logError, "", "");
            }
            else
            {
                ShowProblemSolution(ErrorType.nullJob);
            }
        }
예제 #13
0
        private void OnResponseCallback(
            ReaPi.ResponseHandle response,
            ReaPi.ConnectionIdentifier connection,
            ReaPi.ECommandId commandid,
            ReaPi.EErrorCode errorCode,
            IntPtr context)
        {
            int         error       = 0;
            ErrorStatus errorStatus = ReaPi.GetErrorStatus(response, out error);

            switch (commandid)
            {
            case ReaPi.ECommandId.CMD_SUBSCRIBEJOBSET:
                CmdSubscribeJobSetResponse(true);
                break;

            case ReaPi.ECommandId.CMD_UNSUBSCRIBEJOBSET:
                CmdSubscribeJobSetResponse(false);
                break;

            case ReaPi.ECommandId.CMD_GETIOCONFIGURATION:
                CmdGetIOConfigurationResponse(ReaPi.GetIOConfigurationFilename(response, out error));
                break;

            case ReaPi.ECommandId.CMD_GETIOOUTPUTLEVEL:
                CmdGetOutputLevelResponse(response, new GetIOOutputLevelResponseEventArgs(connection, response, commandid, ReaPi.GetErrorStatus(response, out error)));
                break;

            case ReaPi.ECommandId.CMD_SETIOOUTPUTLEVEL:
                CmdSetOutputLevelResponse();
                break;

            default:
                break;
            }
            ShowResponseError(response, connection, commandid.ToString(), errorCode);
        }
예제 #14
0
        private void ShowResponseError(
            ReaPi.ResponseHandle response,
            ReaPi.ConnectionIdentifier connectionId,
            string command,
            ReaPi.EErrorCode error)
        {
            if (error == ReaPi.EErrorCode.OK)
            {
                if (showResponseWithStatusOK == true)
                {
                    SendToDashboard(MessageType.EVENT, $"{command}", null, null);
                }
            }
            else
            {
                int    err          = 0;
                string lastError    = command + ", Błąd: " + error;
                string errorMessage = ReaPi.GetErrorMessage(response, out err);
                string errorDomain  = ReaPi.GetErrorDomain(response, out err).ToString();
                string errorCode    = ReaPi.GetErrorCode(response, out err).ToString();

                SendToDashboard(MessageType.ERROR, lastError, errorCode + " / " + errorDomain, errorMessage);
            }
        }
예제 #15
0
        private void OnEventCallback(
            ReaPi.ResponseHandle response,
            ReaPi.ConnectionIdentifier connection,
            ReaPi.EEventId eventId,
            IntPtr context)
        {
            int error = 0;

            SendToDashboard(MessageType.EVENT, $"{eventId.ToString()}", null, null);

            switch (eventId)
            {
            case ReaPi.EEventId.JOBSET:
                OnJobSetEvent(connection, ReaPi.GetJobId(response, out error), ReaPi.GetJobFilename(response, out error));
                break;

            case ReaPi.EEventId.JOBSTARTED:
                OnJobStartedEvent();
                break;

            case ReaPi.EEventId.JOBSTOPPED:
                OnJobStoppedEvent();
                break;

            case ReaPi.EEventId.PRINTTRIGGER:
                OnJobPrintTriggerEvent(eventId);
                break;

            case ReaPi.EEventId.PRINTSTART:
                OnJobPrintStartEvent(eventId);
                break;

            case ReaPi.EEventId.PRINTREJECTED:
                OnJobPrintRejectEvent();
                break;

            case ReaPi.EEventId.PRINTEND:
                OnJobPrintEndEvent();
                break;

            case ReaPi.EEventId.PRINTABORTED:
                OnJobPrintAbortedEvent();
                break;

            case ReaPi.EEventId.PRINTSPEEDERROR:
                OnJobPrintSpeedErrorEvent();
                break;

            case ReaPi.EEventId.INVALIDCONTENT:
                OnInvalidContentEvent(ReaPi.GetGroupname(response, out error));
                break;

            case ReaPi.EEventId.IOCONFIGURATIONSET:
                OnIOConfigurationSetEvent(ReaPi.GetIOConfigurationFilename(response, out error));
                break;

            case ReaPi.EEventId.MISSINGCONTENT:
                OnMissingContentEvent(ReaPi.GetGroupname(response, out error));
                break;

            case ReaPi.EEventId.BUFFERFULL:
                OnJobBufferFullEvent(ReaPi.GetJobErrorStatus(response, out error));
                break;

            default:
                break;
            }
        }