Example #1
0
 public int Write <T>(PointGroup <T> pointGroup)
 {
     try
     {
         if (_isConnect)
         {
             ASCIIEncoding encoding  = new ASCIIEncoding();
             var           sendBytes = creatWriteData(new List <PointGroup <T> > {
                 pointGroup
             });
             var receiveBuffer = new byte[12768];
             _log.ByteSteamLog(ActionType.SEND, sendBytes);
             if (_socket.Send(sendBytes) != -1)
             {
                 Thread.Sleep(10);
                 int count       = _socket.Receive(receiveBuffer);
                 var receivedata = new byte[count];
                 Array.Copy(receiveBuffer, receivedata, count);
                 _log.ByteSteamLog(ActionType.RECEIVE, receiveBuffer);
                 var receiveStr = encoding.GetString(receivedata);
                 receiveStr.Replace("<", "");
                 var strArrary = receiveStr.Split('>');
                 if (strArrary.Length > 2)
                 {
                     if (strArrary[1] == "12")
                     {
                         return(1);
                     }
                     else if (strArrary[1] == "22")
                     {
                         string errorInfo = "";
                         for (int i = 2; i < strArrary.Length - 1; i++)
                         {
                             errorInfo = string.Concat(errorInfo, "<", strArrary[i], ">");
                         }
                         Log.ErrorLog(string.Format("Freedom Write {0} ", errorInfo));
                         return(-1);
                     }
                     else
                     {
                         Log.ErrorLog(string.Format("Freedom Write {0} ", "receive function code error!"));
                         return(-1);
                     }
                 }
                 else
                 {
                     Log.ErrorLog(string.Format("Freedom Write {0} ", "receive data length too less!"));
                     return(-1);
                 }
             }
             else
             {
                 Log.ErrorLog(string.Format("Freedom Write {0} ", "send buffer fail!"));
                 return(-1);
             }
         }
         else
         {
             Log.ErrorLog(string.Format("Freedom Write {0} ", "connect is not build!"));
             return(-1);
         }
     }
     catch (Exception e)
     {
         DisConnect();
         Log.ErrorLog(string.Format("Freedom Write {0} ", e.Message));
         return(-1);
     }
 }
Example #2
0
 public int ReadString(PointGroup <string> pointGroup)
 {
     return(read(new List <PointGroup <string> > {
         pointGroup
     }, stringDataProcess));
 }
Example #3
0
 public int ReadData <T>(PointGroup <T> pointGroup)
 {
     throw new NotImplementedException();
 }
Example #4
0
 public int Readfloat(PointGroup <float> pointGroup)
 {
     return(read(new List <PointGroup <float> > {
         pointGroup
     }, floatDataProcess));
 }
Example #5
0
 public int ReadUInt(PointGroup <uint> pointGroup)
 {
     return(read(new List <PointGroup <uint> > {
         pointGroup
     }, uintDataProcess));
 }
Example #6
0
 public int ReadUShort(PointGroup <ushort> pointGroup)
 {
     return(read(new List <PointGroup <ushort> > {
         pointGroup
     }, ushortDataProcess));
 }
Example #7
0
 public int ReadByte(PointGroup <byte> pointGroup)
 {
     return(read(new List <PointGroup <byte> > {
         pointGroup
     }, byteDataProcess));
 }
Example #8
0
 public int ReadBool(PointGroup <bool> pointGroup)
 {
     return(read(new List <PointGroup <bool> > {
         pointGroup
     }, boolDataProcess));
 }