Пример #1
0
        private void ReadRFID()
        {
            while (isConnected)
            {
                oSignalUserEvent.WaitOne();
                oSignalUserEvent.Reset();

                rfidCode = S7.GetStringAt(rfidReadBuffer, 2);
                string[] tempArr = rfidCode.Split(',');

                if (!tempArr[0].Equals(string.Empty) && tempArr != null)
                {
                    if (tempArr[1] != "ALIVE")
                    {
                        string tempStr = tempArr[1].Remove(0, 4);

                        using (SqlConnection conn = DBUtils.GetMainDBConnection())
                        {
                            conn.Open();
                            dt = new DataTable();
                            SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM UserDetails", conn);
                            da.Fill(dt);
                        }

                        foreach (DataRow row in dt.Rows)
                        {
                            if (row["Card ID"].ToString().Equals(tempStr))
                            {
                                if (txt_MP_UserName.InvokeRequired)
                                {
                                    txt_MP_UserName.Invoke((MethodInvoker) delegate
                                    {
                                        txt_MP_UserName.Text = row["First Name"].ToString() + " " + row["Last Name"];
                                    });
                                }
                                else
                                {
                                    txt_MP_UserName.Text = row["First Name"].ToString() + " " + row["Last Name"];
                                }

                                if (txt_MP_AccessLvl.InvokeRequired)
                                {
                                    txt_MP_AccessLvl.Invoke((MethodInvoker) delegate
                                    {
                                        txt_MP_AccessLvl.Text = row["Access Level"].ToString();
                                    });
                                }
                                else
                                {
                                    txt_MP_AccessLvl.Text = row["Access Level"].ToString();
                                }

                                S7.SetStringAt(userWriteBuffer, 0, 50, tempStr);
                                S7.SetStringAt(userWriteBuffer, 52, 50, txt_MP_UserName.Text.ToString());

                                short temp = short.Parse(txt_MP_AccessLvl.Text);
                                S7.SetIntAt(userWriteBuffer, 104, temp);

                                usersClient.DBWrite(3104, 0, userWriteBuffer.Length, userWriteBuffer);
                            }
                        }
                    }
                    else
                    {
                        oldUserClient.DBRead(3104, 0, oldUserReadBuffer.Length, oldUserReadBuffer);

                        if (txt_MP_UserName.InvokeRequired)
                        {
                            txt_MP_UserName.Invoke((MethodInvoker) delegate
                            {
                                txt_MP_UserName.Text = S7.GetStringAt(oldUserReadBuffer, 52);
                            });
                        }
                        else
                        {
                            txt_MP_UserName.Text = S7.GetStringAt(oldUserReadBuffer, 52);
                        }

                        if (txt_MP_AccessLvl.InvokeRequired)
                        {
                            txt_MP_AccessLvl.Invoke((MethodInvoker) delegate
                            {
                                txt_MP_AccessLvl.Text = S7.GetIntAt(oldUserReadBuffer, 104).ToString();
                            });
                        }
                        else
                        {
                            txt_MP_AccessLvl.Text = S7.GetIntAt(oldUserReadBuffer, 104).ToString();
                        }
                    }
                }
                else
                {
                    if (txt_MP_UserName.InvokeRequired)
                    {
                        txt_MP_UserName.Invoke((MethodInvoker) delegate
                        {
                            txt_MP_UserName.Text = string.Empty;
                        });
                    }
                    else
                    {
                        txt_MP_UserName.Text = string.Empty;
                    }

                    if (txt_MP_AccessLvl.InvokeRequired)
                    {
                        txt_MP_AccessLvl.Invoke((MethodInvoker) delegate
                        {
                            txt_MP_AccessLvl.Text = string.Empty;
                        });
                    }
                    else
                    {
                        txt_MP_AccessLvl.Text = string.Empty;
                    }

                    S7.SetStringAt(userWriteBuffer, 0, 50, string.Empty);
                    S7.SetStringAt(userWriteBuffer, 52, 50, string.Empty);
                    S7.SetIntAt(userWriteBuffer, 104, 0);

                    usersClient.DBWrite(3104, 0, userWriteBuffer.Length, userWriteBuffer);
                }

                hasReadRFID = false; // creates unlimited rfid reading
                Thread.Sleep(100);
            }
        }
Пример #2
0
        private void Handshake()
        {
            try
            {
                using (SqlConnection conn = DBUtils.GetFEMDBConnection())
                {
                    conn.Open();
                    String query = "INSERT INTO Station31Pick ([FEM Label],Timestamp,[Picked Part]) VALUES (@femlabel, @timestamp, @pickedpart)";


                    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:

                            curPickNum++;
                            scanData = S7.GetStringAt(transactReadBuffer, 96).ToString();
                            Console.WriteLine(scanData);

                            if (!scanData.Equals(""))
                            {
                                this.Invoke((MethodInvoker) delegate
                                {
                                    TextBox temp;
                                    txtBoxes.TryGetValue("pickedBox" + curPickNum, out temp);
                                    //count++;
                                    current_pick.Text = curPickNum.ToString();
                                    temp.Text         = scanData.ToString();
                                });

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

                                if (curPickNum >= pickNum)
                                {
                                    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, 31);                   // Send Equipment ID *** small label scanner
                                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);
                            }
                            Thread.Sleep(50);
                            break;

                        case 100:
                            Console.WriteLine("-------------------------" +
                                              "\nTransaction ID : " + readTransactionID +
                                              "\nResult : Handshake done... Starting next screen." +
                                              "\n-------------------------");
                            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;
            }
        }