Esempio n. 1
0
        public ScanForm()
        {
            GlobalVariable.CreateTestLoginInfo();
            InitializeComponent();
            InitGridView();
            BindData();
            com = new COMServer();
            com.OnReceiveCOMData += (sn) =>
            {
                if (com.IsAutoScan)
                {
                    Loger.LogMessage("COM1口收到数据:" + sn);
                    if (sn.Equals(scanFailCode, StringComparison.CurrentCultureIgnoreCase))
                    {
                        scanFailFlag          = true;
                        labScanFail.BackColor = Color.Red;
                        com.Send("#2,0");
                        return;
                    }

                    tbNo.Text = sn;
                    runSN();
                }
            };
        }
 public void init(COMServer tmpcomServer, int j)
 {
     comServer = tmpcomServer;
     while (mRun)
     {
         Console.WriteLine("new SerialPort()", Environment.NewLine);
         portnr = j;
         _serialPort = new SerialPort();
         int i = 0;
         foreach (string s in SerialPort.GetPortNames())
         {
             if (j == i)
             {
                 Console.WriteLine(s);
                 _serialPort.PortName = s;
             }
             i++;
         }
         _serialPort.ReadTimeout = 500;
         _serialPort.WriteTimeout = 500;
         _serialPort.BaudRate = 9600;
         _serialPort.Parity = (Parity)Enum.Parse(typeof(Parity), _serialPort.Parity.ToString());
         _serialPort.DataBits = int.Parse(_serialPort.DataBits.ToString());
         _serialPort.StopBits = (StopBits)Enum.Parse(typeof(StopBits), _serialPort.StopBits.ToString());
         _serialPort.Handshake = (Handshake)Enum.Parse(typeof(Handshake), _serialPort.Handshake.ToString());
         _serialPort.Open();
         _serialPort.DataReceived += new SerialDataReceivedEventHandler(sp_DataReceived);
         while (_serialPort.IsOpen == true)
         {
             Thread.Sleep(50);
         }
         Console.WriteLine("closed", Environment.NewLine);
     }
     Console.WriteLine("eind init", Environment.NewLine);
 }
Esempio n. 3
0
 public void init(COMServer tmpcomServer, int j)
 {
     comServer = tmpcomServer;
     while (mRun)
     {
         Console.WriteLine("new SerialPort()", Environment.NewLine);
         portnr      = j;
         _serialPort = new SerialPort();
         int i = 0;
         foreach (string s in SerialPort.GetPortNames())
         {
             if (j == i)
             {
                 Console.WriteLine(s);
                 _serialPort.PortName = s;
             }
             i++;
         }
         _serialPort.ReadTimeout  = 500;
         _serialPort.WriteTimeout = 500;
         _serialPort.BaudRate     = 9600;
         _serialPort.Parity       = (Parity)Enum.Parse(typeof(Parity), _serialPort.Parity.ToString());
         _serialPort.DataBits     = int.Parse(_serialPort.DataBits.ToString());
         _serialPort.StopBits     = (StopBits)Enum.Parse(typeof(StopBits), _serialPort.StopBits.ToString());
         _serialPort.Handshake    = (Handshake)Enum.Parse(typeof(Handshake), _serialPort.Handshake.ToString());
         _serialPort.Open();
         _serialPort.DataReceived += new SerialDataReceivedEventHandler(sp_DataReceived);
         while (_serialPort.IsOpen == true)
         {
             Thread.Sleep(50);
         }
         Console.WriteLine("closed", Environment.NewLine);
     }
     Console.WriteLine("eind init", Environment.NewLine);
 }
Esempio n. 4
0
        public int InsertNewDataToTmp(string billno, int setMaxNo, COMServer com)
        {
            _com = com;
            int insertId = 0;

            if (setMaxNo > 0)
            {
                maxScanNo = setMaxNo - 1;
            }
            else
            {
                GetMaxSCANNO();
            }
            Loger.LogMessage("maxScanNo:" + maxScanNo);
            if (CheckBillNOInTmp(billno))//tmp表已存在此billno
            {
                Loger.LogMessage(billno + "在tmp表中");
                insertId = CopyTmp(billno);
            }
            else
            {
                Loger.LogMessage(billno + "未在tmp表中");
                insertId = CopyFromHead(billno);
            }
            return(insertId);
        }
Esempio n. 5
0
        private void AddSerialPort(object messageObj)
        {
            int         portId    = (int)messageObj;
            serial_port tmpserial = new serial_port();
            COMServer   tmpdata   = new COMServer(ParseData);

            tmpserial.init(tmpdata, portId);
            serial[portId] = tmpserial;
            MyData[portId] = tmpdata;
            Console.WriteLine("serial delegated", Environment.NewLine);
        }
Esempio n. 6
0
 private void AddSerialPort(object messageObj)
 {
     int portId = (int)messageObj;
     serial_port tmpserial = new serial_port();
     COMServer tmpdata = new COMServer(ParseData);
     tmpserial.init(tmpdata, portId);
     serial[portId] = tmpserial;
     MyData[portId] = tmpdata;
     Console.WriteLine("serial delegated", Environment.NewLine);
 }
#pragma warning restore CA1810

        internal COMWrapper(COMServer server, Guid guid)
            : this(server, Activator.CreateInstance(Type.GetTypeFromCLSID(guid, true) !, true) !)