示例#1
0
      public void Start(SerialWriteHandler writeHandler)
      {
         if (false == this.active)
         {
            this.serialWriteHandler = writeHandler;

            try
            {
               this.active = true;

               this.thread = new Thread(this.Process);
               this.thread.IsBackground = true;
               this.thread.Name = "FG Scale";

               this.execute = true;
               this.thread.Start();
            }
            catch
            {
               this.faultReason = "unable to open port";
            }
         }
      }
示例#2
0
      public void Stop()
      {
         if (false != this.active)
         {
            this.execute = false;
            this.thread.Join(3000);

            this.thread = null;

            if (null != this.serialWriteHandler)
            {
               this.serialWriteHandler = null;
            }
            else
            {
               this.serialPort.Close();
            }

            this.active = false;
            this.faultReason = "closed";
         }
      }
示例#3
0
      public void Start(int port, int rate)
      {
         if (false == this.active)
         {
            this.serialWriteHandler = null;

            string serialPortName = "COM" + port.ToString();
            this.serialPort.PortName = serialPortName;
            this.serialPort.BaudRate = rate;

            try
            {
               this.serialPort.Open();
               this.active = true;

               this.thread = new Thread(this.Process);
               this.thread.IsBackground = true;
               this.thread.Name = "FG Scale";

               this.execute = true;
               this.thread.Start();
            }
            catch
            {
               this.faultReason = "unable to open port";
            }
         }
      }