protected void RaiseDeviceMessageEvent(DeviceDriver device, string message, object data)
 {
     if (DeviceMessages != null)
     {
         DeviceMessages(device, message, data);
     }
 }
示例#2
0
 protected void RaiseDeviceStatus(DeviceDriver device, eDeviceStatus status)
 {
     if (DeviceStatus != null)
     {
         DeviceStatus(device, status);
     }
 }
示例#3
0
 protected void RaiseDataReceivedEvent(DeviceDriver device, byte[] data, int length)
 {
     if (DataReceived != null)
     {
         DataReceived(device, data, length);
     }
 }
 void DataReceived(DeviceDriver driver, byte[] data, int len)
 {
     if (InvokeRequired)
     {
         BeginInvoke(new MethodInvoker(delegate() { DataReceived(driver, data, len); }));
     }
     else
     {
         String s = ASCIIEncoding.ASCII.GetString(data);
         txtReceived.Text += s + "\r\n";
     }
 }
        public void ResumePrint()
        {
            m_paused = false;
            m_state  = BuildManager.STATE_DO_NEXT_LAYER;
            StartBuildTimer();
            RaiseStatusEvent(eBuildStatus.eBuildResumed, "Next Layer");
            Drivers.DeviceDriver dr = UVDLPApp.Instance().m_deviceinterface.Driver;
            string resumecmd        = UVDLPApp.Instance().m_printerinfo.GetStringVar("ResumeCommand");

            if (resumecmd.Length > 0)
            {
                UVDLPApp.Instance().m_deviceinterface.SendCommandToDevice(resumecmd);
            }
        }
        public void PausePrint()
        {
            m_paused = true;
            m_state  = STATE_IDLE;
            StopBuildTimer();
            RaiseStatusEvent(eBuildStatus.eBuildPaused, "Print Paused");
            // special coding for Elite Image Works
            // in the future, this should be pulled from the machine config file
            // special commands or something...
            Drivers.DeviceDriver dr = UVDLPApp.Instance().m_deviceinterface.Driver;
            string pausecmd         = UVDLPApp.Instance().m_printerinfo.GetStringVar("PauseCommand");

            if (pausecmd.Length > 0)
            {
                UVDLPApp.Instance().m_deviceinterface.SendCommandToDevice(pausecmd);
            }
        }
        public void LineReceived(DeviceDriver device, string line) 
        {
            // parse for temperature data
            //convert to string
            string ln = line.Trim().ToUpper();

            //ok T:201 B:117 
            String[] parts = line.Split(' '); // split on spaces
            bool temp = false;
            if (parts.Length > 1)  // if this is more than just an 'ok'
            {
                foreach (string part in parts)
                {
                    try
                    {
                        //part = part.ToUpper(); 

                        if (part.StartsWith("T:"))
                        {
                            string[] tmp = part.Split(':');
                            EXT0_Temp = double.Parse(tmp[1]);
                            temp = true;
                        }
                        if (part.StartsWith("B:"))
                        {
                            string[] tmp = part.Split(':');
                            HBP_Temp = double.Parse(tmp[1]);
                            temp = true;
                        }
                        if (temp) 
                        {
                            //update the gui
                            UpdateForm();
                        }
                    }
                    catch (Exception ex) 
                    {
                        DebugLogger.Instance().LogError(ex.Message);
                    }
                }
            }

        }
        /*
        public void Configure(ConnectionConfig cc,int idx)
        {
            m_lstprojectors[idx].Configure(cc);
        }
         */
        /*
        public void ConfigureProjector(ConnectionConfig cc)
        {
            DriverProjector.Configure(cc);
        }
        */
        public void DriverDeviceStatusEvent(DeviceDriver device, eDeviceStatus status)
        {
            switch (status)
            {
                case eDeviceStatus.eError:
                    if (StatusEvent != null)
                    {
                        StatusEvent(ePIStatus.eError, "I/O Error");
                    }
                    break;
                case eDeviceStatus.eConnect:
                    if (StatusEvent != null)
                    {
                        StatusEvent(ePIStatus.eConnected, "Connected");
                    }
                    break;
                case eDeviceStatus.eDisconnect:
                    if (StatusEvent != null)
                    {
                        StatusEvent(ePIStatus.eDisconnected, "Disconnected");
                    }
                    break;

            }
        }
 public void AddDriver(DeviceDriver d)
 {
     m_lstprojectors.Add(d);
     //add some events here..
     d.DataReceived += new DeviceDriver.DataReceivedEvent(DriverDataReceivedEvent);
     d.DeviceStatus += new DeviceDriver.DeviceStatusEvent(DriverDeviceStatusEvent);
 }
        private bool m_ready; // ready to send a command

        #endregion Fields

        #region Constructors

        public DeviceInterface()
        {
            m_projector = null;
            m_driver = null;
            m_ready = true;
            m_databufA = null;// new byte[BUFF_SIZE];
            m_databufB = null;// new byte[BUFF_SIZE];
        }
 // this is called when we receive data from the device driver
 void DriverDataReceivedEvent(DeviceDriver device, byte[] data, int length)
 {
     // stop the watchdog timer
     m_timeouttimer.Enabled = false;
     // raise the data event
     if (DataEvent != null)
     {
         DataEvent(device, data, length);
     }
     //raise a data event notifying that we're ready for the next command
     if (StatusEvent != null)
     {
         StatusEvent(ePIStatus.eReady, "Ready");
     }
 }
 public DeviceInterface()
 {
     m_timeoutms = DEF_TIMEOUT;
     m_timeouttimer = new Timer();
     m_timeouttimer.Elapsed += new ElapsedEventHandler(m_timeouttimer_Elapsed);
     m_timeouttimer.Interval = m_timeoutms;
     m_driver = null;
 }
        // this is called when we receive data from the device driver
        // one or more full lines can be received here
        void DriverDataReceivedEvent(DeviceDriver device, byte[] data, int length)
        {
            lock (lockobj)
            {
                try
                {
                    m_ready = true;
                    // raise the data event
                    if (DataEvent != null)
                    {
                        DataEvent(device, data, length);
                    }
                    /*
                    //raise a data event notifying that we're ready for the next command
                    if (StatusEvent != null)
                    {
                        StatusEvent(ePIStatus.eReady, "Ready");
                    }
                    */
                    // copy the data into the A buffer
                    int termpos = -1;
                    // copy the data into the 'A' buffer
                    // need to copy into the end of the A buffer
                    if (m_databufA == null)
                    {
                        m_databufA = CopyData(0, data, 0, length);

                    }
                    else
                    {
                        m_databufA = AddBuffers(m_databufA, data);
                    }
                    termpos = Term_Pos(m_databufA, m_databufA.Length);
                    while (termpos != -1)
                    {
                        m_databufB = CopyData(0, m_databufA, 0, termpos + 1);
                        string result = System.Text.Encoding.ASCII.GetString(m_databufB); // should this be ascii?
                        //lock (lockobj)
                       // {
                        m_ready = true;
                       // }

                        if (LineDataEvent != null)
                        {
                            LineDataEvent(device, result); // raise an event for each complete line we receive
                        }
                        m_databufB = CopyData(0, m_databufA, termpos + 1, (m_databufA.Length - (termpos + 1)));
                        m_databufA = CopyData(0, m_databufB, 0, m_databufB.Length);
                        termpos = Term_Pos(m_databufA, m_databufA.Length); // check again
                    }
                }
                catch (Exception)
                {
                    // DebugLogger.Instance().LogError(ex.Message);  // this is erroring on the null driver for some reason
                }
            }
        }
 protected void RaiseDataReceivedEvent(DeviceDriver device, byte[] data, int length)
 {
     if (DataReceived != null)
     {
         DataReceived(device, data, length);
     }
 }
        // this is called when we receive data from the device driver
        // one or more full lines can be received here
        void DriverDataReceivedEvent(DeviceDriver device, byte[] data, int length)
        {
            lock (lockobj)
            {
                try
                {
                    // m_ready = true; // not sure I should do this here, I think it may be the cause of the flow control issue
                    // raise the data event
                    if (DataEvent != null)
                    {
                        DataEvent(device, data, length);
                    }

                    if (m_alwaysready)
                    {
                        // don't go any further to parse responses and generate line data events
                        // alwaysready is true for EliteImageWorks driver
                        return;
                    }
                    // copy the data into the A buffer
                    int termpos = -1;
                    // copy the data into the 'A' buffer
                    // need to copy into the end of the A buffer
                    if (m_databufA == null)
                    {
                        m_databufA = CopyData(0, data, 0, length);

                    }
                    else
                    {
                        m_databufA = AddBuffers(m_databufA, data);
                    }
                    termpos = Term_Pos(m_databufA, m_databufA.Length);
                    while (termpos != -1)
                    {
                        m_databufB = CopyData(0, m_databufA, 0, termpos + 1);
                        string result = System.Text.Encoding.ASCII.GetString(m_databufB);
                        m_ready = true;

                        if (LineDataEvent != null)
                        {
                            LineDataEvent(device, result); // raise an event for each complete line we receive
                        }
                        m_databufB = CopyData(0, m_databufA, termpos + 1, (m_databufA.Length - (termpos + 1)));
                        m_databufA = CopyData(0, m_databufB, 0, m_databufB.Length);
                        termpos = Term_Pos(m_databufA, m_databufA.Length); // check again
                    }
                }
                catch (Exception)
                {
                    // DebugLogger.Instance().LogError(ex.Message);  // this is erroring on the null driver for some reason
                }
            }
        }
 protected void RaiseDeviceMessageEvent(DeviceDriver device, string message, object data)
 {
     if (DeviceMessages != null)
     {
         DeviceMessages(device, message, data);
     }
 }
        // this is called when we receive data from the device driver
        // one or more full lines can be received here
        void DriverDataReceivedEvent(DeviceDriver device, byte[] data, int length)
        {
            try
            {
                // stop the watchdog timer
                m_timeouttimer.Enabled = false; // disable the timer
                // raise the data event
                if (DataEvent != null)
                {
                    DataEvent(device, data, length);
                }
                //raise a data event notifying that we're ready for the next command
                if (StatusEvent != null)
                {
                    StatusEvent(ePIStatus.eReady, "Ready");
                }

                string result = System.Text.Encoding.UTF8.GetString(data);
                // split it into multiple lines
                string[] lines = result.Split('\n');
                foreach (string line in lines)
                {
                    if (LineDataEvent != null)
                    {
                        LineDataEvent(device, line);
                    }
                    //now parse the response to look for temperature reporting events

                    //convert to string
                    string ln = line.Trim();

                    //ok T:201 B:117
                    String[] parts = line.Split(' '); // split on spaces
                    bool temp = false;
                    if (parts.Length > 1)  // if this is more than just an 'ok'
                    {
                        try
                        {
                            foreach (string part in parts)
                            {
                                if (part.StartsWith("T"))
                                {
                                    string[] tmp = part.Split(':');
                                    m_Ext0Temp = double.Parse(tmp[1]);
                                    temp = true;
                                }
                                if (part.StartsWith("B"))
                                {
                                    string[] tmp = part.Split(':');
                                    m_HBPtemp = double.Parse(tmp[1]);
                                    temp = true;
                                }

                            }
                        }
                        catch (Exception ex) { }

                    }
                    if (temp)
                    {
                        if (StatusEvent != null)
                        {
                            StatusEvent(ePIStatus.eTemperatureData, "Temperatures read");
                        }
                    }
                }
            }
            catch (Exception ex)
            {

            }
        }
        private bool m_ready; // ready to send a command

        #endregion Fields

        #region Constructors

        public DeviceInterface()
        {
            m_lstprojectors = new List<DeviceDriver>();
            m_driver = null;
            m_ready = true;
            m_databufA = null;// new byte[BUFF_SIZE];
            m_databufB = null;// new byte[BUFF_SIZE];
            m_alwaysready = false; // assume it's a generic driver that requires gcode response to be ready
        }
 void LineDataReceived(DeviceDriver driver, string line)
 {
     if (InvokeRequired)
     {
         BeginInvoke(new MethodInvoker(delegate() { LineDataReceived(driver, line); }));
     }
     else
     {
         line = line.Trim();
         //sb.Insert(0, line);
         txtReceived.Text += line + "\r\n";
         //txtReceived.Refresh();
     }
 }
 protected void RaiseDeviceStatus(DeviceDriver device,eDeviceStatus status)
 {
     if (DeviceStatus != null)
     {
         DeviceStatus(device,status);
     }
 }
 void datareceivedev(DeviceDriver device, byte[] dat, int len)
 {
     string str = Utility.ByteArrayToString(dat);
     DebugLogger.Instance().LogInfo(str);
 }