private void Setting_Load(object sender, EventArgs e) { isSaved = false; sp = new SerialPortReader(this, label5); loadPort(); loadPortSetting(); }
public void first_weight_Load(object sender, EventArgs e) { isSaved = false; if (Properties.Settings.Default.username == "admin") { lblWeightReading.ReadOnly = false; } else { lblWeightReading.ReadOnly = true; } btnSave.Enabled = false; com = new common(); serial = new SerialPortReader(this, lblWeightReading); serial.Connect(); //lblWeightReading.Text = new Random().Next(500, 1000).ToString(); loadintocombo(driversPath, cbDriverName); loadintocombo(goodsPath, cbProduct); loadintocombo(trucksPath, cbCarType); //loadintocombo(productPath, cbProduct); loadIntoComboFromDatabse(cbCustomerName, "select id,name from Customers"); //string sql = "select max(id) from Wieghts"; string sql = "select IDENT_CURRENT('Wieghts')"; using (SqlConnection connection = new SqlConnection(com.connstr())) { using (SqlCommand command = new SqlCommand(sql, connection)) { connection.Open(); var result = command.ExecuteScalar(); if (result.Equals(DBNull.Value)) { label12.Text = "1"; resetId(); } else { label12.Text = (Convert.ToInt32(command.ExecuteScalar()) + 1).ToString(); } } } }
private void Form1_Load(object sender, EventArgs e) { _parser = new NmeaParser(); _parser.NmeaSentenceReceived += new NmeaSentenceReceivedEventHandler(_parser_NmeaSentenceReceived); string[] ports = SerialPortReader.GetAvailablePorts(); if (ports != null && ports.Length > 0) { this._comPorts.Items.AddRange(ports); this._comPorts.SelectedIndex = 0; } string port = this._comPorts.SelectedItem as string; _portReader = new SerialPortReader(port); _portReader.DataReceived += new GpsDataReceivedEventHandler(_portReader_DataReceived); UpdateControls(); }
public static void portDataReceived(object sender, SerialDataReceivedEventArgs e) { //try //{ // dataReceived = newPort.ReadExisting(); // Console.WriteLine(dataReceived); // string value = dataReceived; // string[] collection = value.Split(':'); // Console.WriteLine("Temperature:" + collection[3]); // //Environment.Exit(0); //} //catch (IOException exception) //{ // Console.WriteLine("N/A"); // Console.WriteLine("\n Message ---", exception.Message); //} SerialPortReader reader = (SerialPortReader)sender; int indexStart = -1; int indexEnd = -1; switch (e.EventType) { case SerialData.Chars: string text = reader.getSerialPort().ReadExisting(); standingThermometerDataBuffer = standingThermometerDataBuffer + text; try { indexStart = standingThermometerDataBuffer.IndexOf("W"); indexEnd = standingThermometerDataBuffer.IndexOf("\n\r"); List<string> strArray = new List <string>(); while (indexStart != -1 && indexEnd != -1) { string slpitData = standingThermometerDataBuffer.Substring(indexStart, indexStart + indexEnd + 2); standingThermometerDataBuffer = standingThermometerDataBuffer.Substring(indexStart + indexEnd + 2); strArray.Add(slpitData); indexStart = standingThermometerDataBuffer.IndexOf("W"); indexEnd = standingThermometerDataBuffer.IndexOf("\n\r"); } string[] temperatureInfo = null; string[] barcodeInfo = null; foreach (string str in strArray) { string strInfo = str.Trim(); strInfo = strInfo.Replace("\r",""); strInfo = strInfo.Replace("\n",""); strInfo = strInfo.Replace("\0", ""); if (strInfo.Length > 0) { string[] info = strInfo.Split(":"); if (info[0].ToLower().Equals("w") && temperatureInfo == null) { temperatureInfo = info; break; } else if (info[0].ToLower().Equals("m")) { barcodeInfo = info; } } if (barcodeInfo != null && temperatureInfo != null) { break; } if (temperatureInfo != null) { string[] info = temperatureInfo; try { string weight = "", temp = ""; if (info[1].Equals(SerialPortManager.StandingThermometerNoValue) == false) { float weightF = 0; if (!float.TryParse(info[1], out weightF)) weight = ""; else weight = weightF.ToString("0.0"); } if(temp.Length > 0 || weight.Length > 0){ float temperatureF = 0; float weightF = 0; if(!float.TryParse(temp, out temperatureF)) temperatureF = 0; if(!float.TryParse(weight, out weightF)) weightF =0; if(weightF > 0) weightF += TaidiiExe.Properties.Settings.Default.WERIGJING_SCALE; if(weightF < 0) weightF = 0; if(temperatureF > 30){ // raise event New_TWH_DataReceivedEventArgs tempArgs = new New_TWH_DataReceivedEventArgs(temperatureF.ToString(), weightF.ToString(),""); if(SerialPortDataManager.New_TWH_EventHandler != null){ SerialPortManager.New_TWH_EventHandle(tempArgs); } } } } catch(Exception e){} } if(barcodeInfo != null){ string[] info = barcodeInfo; try{ string barcode = info[1]; if(barcode[barcode.Length -1] == '#'){ barcode = barcode.Substring(0, barcode.Length - 1); } if(SerialPortManager.NewBarCodeEventHandler != null){ SerialPort } } } } } }