Esempio n. 1
0
        public void WriteToSQLDataBase()
        {
            using (SqlConnection conn = DBUtils.GetFEMDBConnection())
            {
                conn.Open();
                if (readTransactionID == 1)
                {
                    try
                    {
                        using (SqlCommand cmd = new SqlCommand("INSERT INTO Production_Line1 VALUES (@Line_ID, @Skid_ID, @Part_Number, @Station_Status, @Error_Code, @Operator, @Timestamp, @Equipment_ID, @Production_Data)", conn))
                        {
                            cmd.Parameters.AddWithValue("@Line_ID", lineID);
                            cmd.Parameters.AddWithValue("@Part_Number", identifier);
                            //cmd.Parameters.AddWithValue("@Transaction_ID", readTransactionID);
                            //cmd.Parameters.AddWithValue("@Channel_Status", channelStatus);
                            cmd.Parameters.AddWithValue("@Station_Status", stationStatus);
                            cmd.Parameters.AddWithValue("@Error_Code", errorCode);
                            //cmd.Parameters.AddWithValue("@Oper", userName);
                            cmd.Parameters.AddWithValue("@Timestamp", DateTime.Now);
                            cmd.Parameters.AddWithValue("@Equipment_ID", equipmentID);
                            cmd.Parameters.AddWithValue("@Production_Data", productionData);

                            cmd.ExecuteNonQuery();
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("==> Couldn't write to database " + ex);
                    }
                }
                else if (readTransactionID > 1)
                {
                    try
                    {
                        using (SqlCommand cmd = new SqlCommand("UPDATE Production_Line1 SET Production_Data = @Production_Data, Transaction_ID = @Transaction_ID WHERE Identifier = @Identifier", conn))
                        {
                            cmd.Parameters.AddWithValue("@Production_Data", productionData);
                            cmd.Parameters.AddWithValue("@Transaction_ID", readTransactionID);
                            cmd.Parameters.AddWithValue("@Identifier", identifier);

                            cmd.ExecuteNonQuery();
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("==> Couldn't write to database" + ex);
                    }
                }
            }
        }
Esempio n. 2
0
        private void Handshake()
        {
            try
            {
                using (SqlConnection conn = DBUtils.GetFEMDBConnection())
                {
                    conn.Open();
                    String query = "INSERT INTO Station31Bolt ([FEM Label],Timestamp,[Bolt Result]) VALUES (@femlabel, @timestamp, @boltresult)";

                    while (isConnected)
                    {
                        oSignalTransactEvent.WaitOne();
                        oSignalTransactEvent.Reset();

                        SqlCommand command = new SqlCommand(query, conn);

                        switch (readTransactionID)
                        {
                        case 2:
                        case 4:
                        case 6:
                        case 8:
                        case 10:
                        case 12:
                        case 14:
                        case 16:
                        case 18:
                        case 20:
                        case 22:
                            curBoltNum++;
                            boltResult = S7.GetStringAt(transactReadBuffer, 96).ToString();

                            if (!boltResult.Equals(""))
                            {
                                this.Invoke((MethodInvoker) delegate
                                {
                                    current_bolt.Text = curBoltNum.ToString();
                                });

                                command.Parameters.AddWithValue("@femlabel", FEMLabel);
                                command.Parameters.AddWithValue("@timestamp", DateTime.Now);
                                command.Parameters.AddWithValue("@boltresult", boltResult);
                                command.ExecuteNonQuery();

                                if (curBoltNum >= boltNum)
                                {
                                    S7.SetByteAt(transactWriteBuffer, 45, 99);
                                    int result1 = transactClient.DBWrite(3101, 0, transactWriteBuffer.Length, transactWriteBuffer);
                                    break;
                                }

                                S7.SetByteAt(transactWriteBuffer, 45, (byte)(readTransactionID + 1));
                                S7.SetByteAt(transactWriteBuffer, 94, 60);                   // Send Equipment ID *** bolting tool
                                S7.SetByteAt(transactWriteBuffer, 44, (byte)maxNumAttempts); // Send MaxNumOfAttempts
                                int result2 = transactClient.DBWrite(3101, 0, transactWriteBuffer.Length, transactWriteBuffer);
                                Console.WriteLine("Write Result : " + result2 + "\n-------------------------");
                            }
                            else     // no data received from plc
                            {
                                //S7.SetByteAt(transactWriteBuffer, 45, 3); // Check what tr id to send back if no data was received
                                S7.SetByteAt(transactWriteBuffer, 48, 99);
                                int result2 = transactClient.DBWrite(3101, 0, transactWriteBuffer.Length, transactWriteBuffer);
                            }
                            break;

                        case 100:

                            Console.WriteLine("-------------------------" +
                                              "\nTransaction ID : " + readTransactionID +
                                              "\nResult : Handshake done... Starting next screen." +
                                              "\n-------------------------");

                            subSequences = entireSequence.Split('-');
                            if ((sequencePos + 1) >= subSequences.Length)
                            {
                                hub.PublishAsync(new ScreenChangeObject("0"));
                                this.Close();
                            }
                            else
                            {
                                string[] nextStep = subSequences[sequencePos + 1].Split(',');
                                hub.PublishAsync(new ScreenChangeObject(nextStep[0], nextStep[1], entireSequence, (sequencePos + 1), skidID, FEMLabel));
                                this.Close();
                            }

                            break;

                        default:
                            break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                handshakeCleared = false;
            }
        }