private void Calibrate() { try { connection.WriteVariable("Cal_Weight", SharedVariables.LoadFac); connection.Call("Calibrate"); SharedVariables.CalWinCal = false; } catch (Exception i) { MessageBox.Show("Could not Write" + i); } }
private void timer1_Tick(object sender, EventArgs e) { if (!connection.Connected) { connection.Connect(); // Scan all functions shared connection.RefreshFunctions(); connection.RefreshVariables(); } if (isTimerRunning) { rfidValue = connection.Call("returnRfid").Value.ToString(); //ok txtAttendeeRFID.Text = rfidValue.ToString().PadLeft(10, '0'); //ok var attendees = GetAttendees().Where(a => a.AttendeeRFID.ToString() == rfidValue && a.AttendeeRFID.ToString() != "0" && a.AttendeeRFID.ToString() != string.Empty); var isRfidRegistered = attendees.Any(); if (!isRfidRegistered && txtAttendeeRFID.Text != "0000000000" && txtAttendeeRFID.Text != "") { timer1.Stop(); var addAttendeeForm = new AddAttendeeForm(AttendeeRepository); addAttendeeForm.FormClosed += AddAttendeeForm_FormClosed; addAttendeeForm.txtRFID.Enabled = false; addAttendeeForm.txtRFID.Text = rfidValue; addAttendeeForm.ShowDialog(); } else if (isRfidRegistered) { txtName.Text = attendees.SingleOrDefault().Name; txtAge.Text = attendees.SingleOrDefault().Age.ToString(); txtAddress.Text = attendees.SingleOrDefault().Address; selectedAttendeeId = attendees.SingleOrDefault().Id; } //txtName.Enabled = !isRfidRegistered; //txtAge.Enabled = !isRfidRegistered; //txtAddress.Enabled = !isRfidRegistered; } if (txtAttendeeRFID.Text != "0000000000" && txtAttendeeRFID.Text != "") //ok { if (isTimerRunning) { connection.WriteVariable("i", 2); //connection.Call("modifyI", 2); } isTimerRunning = false; //ok proximityValue = connection.Call("returnProximity").Value.ToString(); if (proximityValue == "0") { bodytempValue = connection.Call("returnTemperature").Value.ToString(); //ok //bodytempValue = connection.ReadVariable("bodytemp").Value.ToString(); //ok txtTemperature.Text = bodytempValue; } else { txtTemperature.Text = string.Empty; } } //try //{ // if (isTimerRunning) // { // } // if (value.ToString() != "0" || value.ToString() != "") // { // isTimerRunning = false; // var runFunctionChangeVariableIToNum = connection.WriteVariable("i", 2); // connection.WriteVariable("rfid", 0); // } //} //catch(Exception ex) //{ //} }
private void TimerTick() { try { if (!connection.Connected) { connection.Connect(); // Scan all functions shared connection.RefreshFunctions(); connection.RefreshVariables(); } if (isTimerRunning) { rfidValue = connection.Call("returnRfid").Value.ToString(); //ok txtAttendeeRFID.Text = rfidValue.ToString().PadLeft(10, '0'); //ok var attendees = GetAttendees().Where(a => a.AttendeeRFID.ToString() == rfidValue && a.AttendeeRFID.ToString() != "0" && a.AttendeeRFID.ToString() != string.Empty); var isRfidRegistered = attendees.Any(); if (!isRfidRegistered && txtAttendeeRFID.Text != "0000000000" && txtAttendeeRFID.Text != "") { //connectionTimer.Stop(); //var addAttendeeForm = new AddAttendeeForm(AttendeeRepository); //addAttendeeForm.FormClosed += AddAttendeeForm_FormClosed; //addAttendeeForm.txtRFID.Enabled = false; //addAttendeeForm.txtRFID.Text = rfidValue; //addAttendeeForm.ShowDialog(); btnAdd.Text = "RFID Not Registered"; connection.WriteVariable("i", 5); Thread.Sleep(2000); AutomaticReset(); } else if (isRfidRegistered) { txtName.Text = attendees.SingleOrDefault().Name; txtAge.Text = attendees.SingleOrDefault().Age.ToString(); txtAddress.Text = attendees.SingleOrDefault().Address; selectedAttendeeId = attendees.SingleOrDefault().Id; selectedAttendeeStatus = attendees.SingleOrDefault().Status; if (selectedAttendeeStatus == "POSITIVE") { btnAdd.Text = "POSITIVE"; connection.WriteVariable("i", 4); Thread.Sleep(2000); AutomaticReset(); } else if (selectedAttendeeStatus == "PUI") { btnAdd.Text = "PUI"; connection.WriteVariable("i", 3); Thread.Sleep(2000); AutomaticReset(); } } //txtName.Enabled = !isRfidRegistered; //txtAge.Enabled = !isRfidRegistered; //txtAddress.Enabled = !isRfidRegistered; } if (txtAttendeeRFID.Text != "0000000000" && txtAttendeeRFID.Text != "") //ok { if (isTimerRunning) { connection.WriteVariable("i", 2); //connection.Call("modifyI", 2); } isTimerRunning = false; //ok proximityValue = connection.Call("returnProximity").Value.ToString(); if (proximityValue == "0") { bodytempValue = connection.Call("returnTemperature").Value.ToString(); //ok txtTemperature.Text = bodytempValue; btnAdd.PerformClick(); } else { txtTemperature.Text = string.Empty; } } } catch (Exception ex) { } }
static void Main(string[] args) { WriteHeader(); SharerConnection connection; LBL_START: try { // ask for COM port string port = null; while (port == null) { var ports = SharerConnection.GetSerialPortNames(); port = DisplayOptions("On which COM port your Arduino is connected to ?", ports); } WriteHeader(); // ask for baurate int bauds = 0; while (bauds == 0) { bauds = DisplayOptions("Choose a baudrate.", new int[] { 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 31250, 38400, 57600, 115200 }); } connection = new SharerConnection(port, bauds); connection.Connect(); } catch (Exception ex) { ShowException(ex); goto LBL_START; } LBL_SHOW_OPTIONS: try { WriteHeader(); // Build option list var options = new List <string>(); options.Add(GET_INFO); options.AddRange(connection.Functions.Select((x) => $"{CALL}{x.Name}")); options.AddRange(connection.Variables.SelectMany((x) => new string[] { $"{READ}{x.Name}", $"{WRITE}{x.Name}" })); var answer = DisplayOptions("What would you like to do ?", options); Console.WriteLine(); if (answer == null) { goto LBL_SHOW_OPTIONS; } else if (answer.StartsWith(GET_INFO)) { Console.WriteLine(connection.GetInfos()); // print board info } else if (answer.StartsWith(CALL)) { // call a function var name = answer.Substring(CALL.Length); var function = connection.Functions.FirstOrDefault((x) => string.Equals(x.Name, name)); if (function == null) { throw new Exception($"No function called {name}"); } Console.WriteLine($"Call function: {function.Prototype}"); var argValues = new List <string>(); foreach (var arg in function.Arguments) { Console.Write($" {arg.Name}= "); argValues.Add(Console.ReadLine()); } var result = connection.Call(name, argValues.ToArray()); Console.Write("--> "); Console.WriteLine(result); } else if (answer.StartsWith(READ)) { // read variable var name = answer.Substring(READ.Length); var variable = connection.Variables.FirstOrDefault((x) => string.Equals(x.Name, name)); if (variable == null) { throw new Exception($"No variable called {name}"); } var value = connection.ReadVariable(name); Console.WriteLine($" {variable.Type.ToString()} {name} = {value?.ToString()}"); } else if (answer.StartsWith(WRITE)) { // write variable var name = answer.Substring(WRITE.Length); Console.Write($"Enter a new value for {name}: "); var value = Console.ReadLine(); if (connection.WriteVariable(name, value)) { Console.WriteLine("OK"); } else { Console.WriteLine("Failed to write variable"); } } else { Console.Write("Answer not understood !?"); } } catch (Exception ex) { ShowException(ex); } Console.WriteLine("Press any key to continue testing Sharer..."); Console.Read(); goto LBL_SHOW_OPTIONS; }