private async void Page_Loaded(object sender, RoutedEventArgs e) { // Display the version txtVersion.Text = string.Format("MeterMate {0} V{1}.{2}", Model, MajorVersion, MinorVersion); // Display the Copyright notice txtCopyright.Text = "Swiftsoft - Copyright © 2016-2017"; // Show that the handset by default is not connected ledHandsetConnected.LedOn = false; ledEmr3Connected.LedOn = false; // Create timer to expire immediately and then every 12 seconds thereafter timer = new Timer(TimerExpired, null, 0, 12000); SerialDevice meterMatePort = null; SerialDevice bluetoothPort = null; try { // meterMatePort = await GetSerialPort("prolific usb-to-serial comm port"); //meterMatePort = await GetSerialPort("usb serial converter"); meterMatePort = await GetSerialPort("USB-RS232 Cable"); if (meterMatePort == null) { meterMatePort = await GetSerialPort("usb serial converter"); } //meterMatePort = await GetSerialPort("usb <-> serial"); //meterMatePort = await GetSerialPort("cp2102 usb to uart bridge controller"); bluetoothPort = await GetSerialPort("nfo"); if (bluetoothPort == null) { bluetoothPort = await GetSerialPort("minwinpc"); } } catch (NullReferenceException) { //txtStatus.Text = "Could not obtain serial port."; } // Start the EMR3 thread Emr3 emr3 = new Emr3(meterMatePort, this); emr3.Start(); // Start the PDA thread Pda pda = new Pda(bluetoothPort, this); pda.Start(); }
private async void main() { int idx = 0; // Poll forever while (true) { try { // Poll meter for realtime litres. await Pda.ProcessMessage("Grl"); switch (idx) { case 0: // Poll meter for status. await Pda.ProcessMessage("Gs"); break; case 1: // Poll meter for preset litres. await Pda.ProcessMessage("Gpl"); break; case 2: // Poll meter for current temperature. await Pda.ProcessMessage("Gt"); break; //case 3: // // Poll MeterMate for Version/Model // await Pda.ProcessMessage("Gv"); // break; } if (++idx == 3) { idx = 0; } } catch (Exception) { } // A message is sent every 50 ms await Task.Delay(50); } }