Example #1
0
        private int ReadSomeStore(string server, int port, bool breakOnSpecialStore, int Store_No)
        {
            string Tempstring;
            int    StoreCounter;
            bool   DataAvailabel    = true;
            bool   IsDataTableEmpty = true;


            for (StoreCounter = 1; DataAvailabel == true; StoreCounter++)
            {
                try
                {
                    var client  = new TcpClient();
                    var result  = client.BeginConnect(server, port, null, null);
                    var success = result.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(2));
                    if (!success)
                    {
                        return(-1); // client is null !!!
                    }
                    else
                    {
                        NetworkStream stream = client.GetStream();
                        Tempstring = StoreCounter.ToString("X4");
                        ASCIIEncoding.ASCII.GetBytes(Tempstring, 0, 4, RequestStoreInfo, 7);
                        stream.Write(RequestStoreInfo, 0, RequestStoreInfo.Length);
                        String responseData = String.Empty;
                        int    BytesCount   = stream.Read(Buffer, 0, Buffer.Length);
                        Store  Stor_Data    = new Store();
                        ProcessStatus = ProcessRecivedStoreData(Stor_Data, Buffer, BytesCount);
                        if (ProcessStatus == 1)
                        {
                            if (breakOnSpecialStore == true)
                            {
                                if (StoreCounter == Store_No)
                                {
                                    DataAvailabel    = false;
                                    IsDataTableEmpty = false;
                                    Stor_Data.Code   = StoreCounter;
                                    StoreInfo        = Stor_Data;
                                }
                            }
                            else
                            {
                                Stor_Data.Code = StoreCounter;
                                Stores.Add(Stor_Data);
                                IsDataTableEmpty = false;
                            }
                        }
                        else
                        {
                            DataAvailabel = false;
                        }


                        stream.Close();
                        client.Close();
                    }
                }
                catch (ArgumentNullException)
                {
                    return(-2); // ArgumentNullException !!!
                }
                catch (SocketException)
                {
                    return(-3); // SocketException !!!
                }
            }
            if (IsDataTableEmpty == true)
            {
                return(2); // succeed : scale has no data
            }
            return(1);     // succeed : scale has data
        }
Example #2
0
 void Start()
 {
     storeCounter = GameObject.Find("StoreCounter").GetComponent <StoreCounter>();;
 }