Exemplo n.º 1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            /*
             * Try / Catch til initialisering af variabler gennem WebService til Navision
             *
             */
            BalanceWS.BalanceWS CBPAutomation = new BalanceWS.BalanceWS();
            CBPAutomation.UseDefaultCredentials = true;
            tbCommunication.AppendText("Sending Param request to Navision\r\n");
            try
            {
                CBPAutomation.WSReturnParam(ref ioLogicIP, ref s_port, ref s_timeout, ref s_DOnewSSCC, ref s_DIwrap, ref s_DIReady, ref s_DOlabel, ref s_DIfin, ref s_DOst, ref s_DIst, ref EidosPrinterIp, ref EidosPrinterPort, ref NewPalletPosIs, ref s_SSCCPath, ref s_SSCCLabelName, ref b_DeleteFile, ref i_DoDummyPallet);
                ioLogicPortNo            = ushort.Parse(s_port);
                ioLogicTimeout           = ushort.Parse(s_timeout);
                DO_DATA_SEND_TO_FISKER   = byte.Parse(s_DOnewSSCC);
                DI_DUMMY_PALLET          = byte.Parse(s_DIwrap);
                DO_LABEL_SEND_TO_PRINTER = byte.Parse(s_DOlabel);
                DI_READY_FOR_LABEL       = byte.Parse(s_DIReady);
                DI_PALLET_FINISHED       = byte.Parse(s_DIfin);
                DO_DUMMY_PALLET          = byte.Parse(i_DoDummyPallet.ToString());
                DI_SignalFilter          = int.Parse(s_DIst);
                DO_SignalFilter          = int.Parse(s_DOst);

                tbCommunication.AppendText(string.Format("ioLogic IP from Nav: {0}{1}", ioLogicIP, "\r\n"));
                tbCommunication.AppendText(string.Format("ioLogic Port from Nav: {0}{1}", ioLogicPortNo, "\r\n"));
                tbCommunication.AppendText(string.Format("Eidos Printer IP from Nav: {0}{1}", EidosPrinterIp, "\r\n"));
                tbCommunication.AppendText(string.Format("Eidos Port from Nav: {0}{1}", EidosPrinterPort, "\r\n"));
                tbCommunication.AppendText(string.Format("SSCC Label path from Nav: {0}{1}", s_SSCCPath, "\r\n"));
                tbCommunication.AppendText(string.Format("SSCC Label Name from Nav: {0}{1}", s_SSCCLabelName, "\r\n"));

                tbCommunication.AppendText(string.Format("DoNewPallet from Nav: {0}{1}", DO_DATA_SEND_TO_FISKER, "\r\n"));
                tbCommunication.AppendText(string.Format("DiLabelRequest from Nav: {0}{1}", DI_READY_FOR_LABEL, "\r\n"));
                tbCommunication.AppendText(string.Format("DoLabelDataSend from Nav: {0}{1}", DO_LABEL_SEND_TO_PRINTER, "\r\n"));
                tbCommunication.AppendText(string.Format("DiDummyPallet from Nav: {0}{1}", DI_DUMMY_PALLET, "\r\n"));
                tbCommunication.AppendText(string.Format("DoDummyPallet from Nav: {0}{1}", DO_DUMMY_PALLET, "\r\n"));
                tbCommunication.AppendText(string.Format("DiPalletEND from Nav: {0}{1}", DI_PALLET_FINISHED, "\r\n"));

                CBPAutomation.WSReturnServiceParam(ref NavServiceServer, ref NavServiceUserName, ref NavServicePassword, ref NavServiceServiceName, ref IsNavLocalService);
                tbCommunication.AppendText(string.Format("Nav Webservice Server from Nav: {0}{1}", NavServiceServer, "\r\n"));
                tbCommunication.AppendText(string.Format("User for starting Service from Nav: {0}{1}", NavServiceUserName, "\r\n"));
                tbCommunication.AppendText(string.Format("Password for starting Service from Nav: {0}{1}", NavServicePassword, "\r\n"));
                tbCommunication.AppendText(string.Format("Service to Start from Nav: {0}{1}", NavServiceServiceName, "\r\n"));
                tbCommunication.AppendText(string.Format("Service is running local from Nav: {0}{1}", IsNavLocalService.ToString(), "\r\n"));

                btnInit_Click(sender, e);
                btnAutoRun_Click(sender, e);
            }
            catch (Exception ex)
            {
                tbCommunication.AppendText(string.Format("WebService faild with message: {0}{1}", ex.Message.ToString(), "\r\n"));
            }
        }
Exemplo n.º 2
0
        //------------- Format variable ------------


        private void RunTimer_Tick(object sender, EventArgs e)
        {
            Int32 dwShiftValue = 0x0000;
            int   i            = 0;

            UInt32[] dwGetDIValue = new UInt32[1];
            if (cbService.Checked)
            {
                CheckService(NavServiceServer, NavServiceUserName, NavServicePassword, NavServiceServiceName, false);
            }
            BalanceWS.BalanceWS CBPAutomation = new BalanceWS.BalanceWS();
            CBPAutomation.UseDefaultCredentials = true;
            try
            {
                bool OK = false;
                OK = CBPAutomation.WSNewPalletExist(NewPalletPosIs);
                if (OK)
                {
                    ret = CheckConnection(false);
                    if (ret == MXIO_CS.EIO_SOCKET_DISCONNECT)
                    {
                        CreateIoHandle();
                    }
                    ret = MOXA_CSharp_MXIO.MXIO_CS.E1K_DO_Writes(hConnection[0], DO_DATA_SEND_TO_FISKER, 1, TRIGGER_TYPE_LO_2_HI);
                    MXEIO_Error.CheckErr(ret, "E1K_DO_Writes");
                    if (ret == MXIO_CS.MXIO_OK)
                    {
                        tbCommunication.AppendText(string.Format("New Pallet E1K_DO_Writes Set Ch{0} DO Direction DO Mode value = ON success.{1}", DO_DATA_SEND_TO_FISKER, "\r\n"));
                    }
                    else
                    {
                        tbCommunication.AppendText(string.Format("New Pallet E1K_DO_Write Ch{0} ON returned ERROR: {1} Return value: {2}{3}", DO_DATA_SEND_TO_FISKER, MXEIO_Error.CheckErr(ret, "E1K_DO_Writes"), ret.ToString(), "\r\n"));
                    }
                    GlobalChannel = DO_DATA_SEND_TO_FISKER;
                    Thread.Sleep(2000);
                    ResetChanel_Tick(sender, e);
                }

                if (OK)
                {
                    try
                    {
                        CBPAutomation.WSRenameNewPallet(NewPalletPosIs);
                    }
                    catch (Exception ex)
                    {
                        tbCommunication.AppendText(string.Format("Rename New pallet failed: {0}{1}", MessageBox.Show(ex.Message), "\r\n"));
                    }
                }
            }
            catch (Exception ex)
            {
                tbCommunication.AppendText(string.Format("New pallet check failed: {0}{1}", MessageBox.Show(ex.Message), "\r\n"));
            }

            ret = CheckConnection(false);
            if (ret == MXIO_CS.EIO_SOCKET_DISCONNECT)
            {
                CreateIoHandle();
            }

            ret = MXIO_CS.E1K_DI_Reads(hConnection[0], bytStartChannel, bytCount, dwGetDIValue);
            MXEIO_Error.CheckErr(ret, "E1K_DI_Reads");

            if (ret == MXIO_CS.MXIO_OK)
            {
                for (i = 0, dwShiftValue = 0; i < bytCount; i++, dwShiftValue++)
                {
                    MyString = (((dwGetDIValue[0] & (1 << dwShiftValue)) == 0) ? "OFF" : "ON");
                    if (MyString.Equals("ON"))
                    {
                        // se hvilken Ch det drejer sig om og udfør handling.
                        //tbCommunication.AppendText(string.Format("DI value: ch[{0}] = {1}{2}", i + bytStartChannel, ((dwGetDIValue[0] & (1 << dwShiftValue)) == 0) ? "OFF" : "ON", "\r\n"));
                        if ((dwShiftValue) == DI_DUMMY_PALLET)
                        {
                            try
                            {
                                CBPAutomation.WSAddPalletToQue(string.Format("W {0}", DateTime.Now.ToShortDateString() + ' ' + DateTime.Now.ToShortTimeString()));
                                tbCommunication.AppendText(string.Format("Add Wrap-only pallet OK: {0}", "\r\n"));
                            }
                            catch (Exception ex)
                            {
                                tbCommunication.AppendText(string.Format("Add Wrap-only pallet failed: {0}{1}", MessageBox.Show(ex.Message), "\r\n"));
                            }
                        }


                        if ((dwShiftValue) == DI_READY_FOR_LABEL)
                        {
                            try
                            {
                                if (CBPAutomation.WSIsDummyPallet())
                                {
                                    ret = CheckConnection(false);
                                    if (ret == MXIO_CS.EIO_SOCKET_DISCONNECT)
                                    {
                                        CreateIoHandle();
                                    }

                                    ret = MOXA_CSharp_MXIO.MXIO_CS.E1K_DO_Writes(hConnection[0], DO_DUMMY_PALLET, 1, TRIGGER_TYPE_LO_2_HI);
                                    MXEIO_Error.CheckErr(ret, "E1K_DO_Writes");
                                    if (ret == MXIO_CS.MXIO_OK)
                                    {
                                        tbCommunication.AppendText(string.Format("Dummy Pallet DataE1K_DO_Writes Set Ch{0} DO Direction DO Mode value = ON success.{1}", DO_LABEL_SEND_TO_PRINTER, "\r\n"));
                                    }
                                    else
                                    {
                                        tbCommunication.AppendText(string.Format("Dummy Pallet E1K_DO_Write returned ERROR: {0} Return value: {1}{2}", MXEIO_Error.CheckErr(ret, "E1K_DO_Writes"), ret.ToString(), "\r\n"));
                                    }
                                    Thread.Sleep(2000);
                                    GlobalChannel = DO_DUMMY_PALLET;
                                    ResetChanel_Tick(sender, e);
                                }

                                else if (CBPAutomation.WSCreateSSCCDataFile())
                                {
                                    if (System.IO.File.Exists(s_SSCCPath + s_SSCCLabelName))
                                    {
                                        System.IO.File.Copy(s_SSCCPath + s_SSCCLabelName, EidosPrinterIp + EidosPrinterPort, true);
                                    }

                                    if (b_DeleteFile)
                                    {
                                        System.IO.File.Delete(s_SSCCPath + s_SSCCLabelName);
                                    }

                                    ret = CheckConnection(false);
                                    if (ret == MXIO_CS.EIO_SOCKET_DISCONNECT)
                                    {
                                        CreateIoHandle();
                                    }

                                    ret = MOXA_CSharp_MXIO.MXIO_CS.E1K_DO_Writes(hConnection[0], DO_LABEL_SEND_TO_PRINTER, 1, TRIGGER_TYPE_LO_2_HI);
                                    MXEIO_Error.CheckErr(ret, "E1K_DO_Writes");
                                    if (ret == MXIO_CS.MXIO_OK)
                                    {
                                        tbCommunication.AppendText(string.Format("Create SSCC DataE1K_DO_Writes Set Ch{0} DO Direction DO Mode value = ON success.{1}", DO_LABEL_SEND_TO_PRINTER, "\r\n"));
                                    }
                                    else
                                    {
                                        tbCommunication.AppendText(string.Format("Create SSCC E1K_DO_Write returned ERROR: {0} Return value: {1}{2}", MXEIO_Error.CheckErr(ret, "E1K_DO_Writes"), ret.ToString(), "\r\n"));
                                    }
                                    Thread.Sleep(2000);
                                    GlobalChannel = DO_LABEL_SEND_TO_PRINTER;
                                    //RunTimer.Stop();
                                    //ResetChanel.Start();
                                    ResetChanel_Tick(sender, e);
                                }
                            }
                            catch (Exception ex)
                            {
                                tbCommunication.AppendText(string.Format("Send SSCC Data to printer failed: {0}{1}", MessageBox.Show(ex.Message), "\r\n"));
                            }
                        }

                        if ((dwShiftValue) == DI_PALLET_FINISHED)
                        {
                            try
                            {
                                CBPAutomation.WSRemovePallet();
                                tbCommunication.AppendText(string.Format("Remove pallet success: {0}", "\r\n"));
                                Thread.Sleep(2000);
                            }
                            catch (Exception ex)
                            {
                                tbCommunication.AppendText(string.Format("Remove pallet failed: {0}{1}", MessageBox.Show(ex.Message), "\r\n"));
                            }
                        }
                    }
                }
            }
        }