private static void IndicatorScannerSerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e) { var strMessage = mIndicatorScannerSerialPort.ReadString(); if (strMessage == string.Empty || strMessage == null ) return; Debug.Print("The type of data expected is: " + mMenu.DataRecieved.GetName()); Debug.Print("Data contents recieved from the Serial Port:\r\n" + strMessage); switch (mMenu.DataRecieved) { case RecievedData.ScaleIndicator: var objIndicatorData = new IndicatorData(strMessage); if (objIndicatorData.HasValidDataString) { Debug.Print("Valid Data was sent from the Indicator..."); Settings.NetWeight = objIndicatorData.NetWeight; if (mMenu.MenuSelection == MenuSelection.ViewPieceCount) mMenu.DisplayInformation(Settings); else { /*A new thread must be started in order for the WebGet function to work properly; otherwise WebGet(objIndicatorData) would just silently fail... * http://www.codeproject.com/Articles/795829/Multithreading-with-Netduino-and-NET-Microframework * https://www.youtube.com/watch?v=YZOrORB88-s */ var DataRequestThread = new Thread(delegate() { WebGet(objIndicatorData); }); DataRequestThread.Start(); } } break; case RecievedData.ScannerJobAndSuffix: Settings.JobNumber = strMessage; Settings.StoreJobNumber(); mMenu.DataRecieved = RecievedData.None; mMenu.DisplayInformation(Settings); break; case RecievedData.ScannerOperation: Settings.Operation = strMessage; Settings.StoreOperationNumber(); mMenu.DataRecieved = RecievedData.None; mMenu.DisplayInformation(Settings); break; } }
public static void WebGet(IndicatorData objIndicatorData) { try { var URL = Settings.ShopTrakTransactionsURL.SetParameters(new string[] { Settings.Job, Settings.Suffix.ToString(), Settings.Operation.ToString() }); Debug.Print("WebGet URL is: " + URL); var objURI = new Uri(URL); var webClient = new HTTP_Client(new IntegratedSocket(objURI.Host, (ushort)objURI.Port)); var response = webClient.Get(objURI.AbsolutePath); Debug.Print("Data recieved from URL is:\r\n" + response.ResponseBody); if (response.ResponseCode != 200) // Did we get the expected response? (a "200 OK") throw new ApplicationException("HTTP Response: " + response.ResponseCode.ToString()); else if (response.ResponseBody == "[]") //Does the REST Dataset return empty? throw new ApplicationException("Nobody punched in that Job."); ArrayList arrayList = JsonSerializer.DeserializeString(response.ResponseBody) as ArrayList; Hashtable hashtable = arrayList[0] as Hashtable; //get the first row of records //Microsoft.SPOT.Time.TimeService.SetTimeZoneOffset(300); Settings.PrintDateTime = DateTimeExtensions.FromASPNetAjax(hashtable["CurrentDateTime"].ToString()).AddHours(-5);//Central Time Zone has 5 hour offset from UTC Settings.Item = hashtable["item"].ToString(); StringBuilder strBldrEmployees = new StringBuilder(); for (int intCounter = 0; intCounter < arrayList.Count; intCounter++) //iterate over all the rows to get the employees that are punched into the jobs { hashtable = arrayList[intCounter] as Hashtable; strBldrEmployees.Append(hashtable["emp_num"].ToString().Trim() + ","); } strBldrEmployees.Remove(strBldrEmployees.ToString().LastIndexOf(","), 1); //remove the last comma from the string Settings.Employees = strBldrEmployees.ToString(); //Instantiate my label so that I can populate the Format property with the value pulled from the SDCard. var objLabel = new Label(new string[] { Settings.Item, Settings.JobNumber, Settings.OperationNumber.ToString("D3"), Settings.Employees, Settings.PieceCount.ToString("N"), Settings.PrintDateTime.ToString("MM/dd/yy h:mm:ss tt"), Settings.PrintDateTime.ToString("dddd") }); objLabel.LabelFormat = Settings.LabelFormat; Debug.Print("Data written to printer serial port is:\r\n" + objLabel.LabelText); mPrinterSerialPort.WriteString(objLabel.LabelText); } catch (Exception objEx) { Debug.Print("Exception caught in WebGet()\r\n"); Debug.Print(objEx.Message); mMenu.DisplayError(objEx); } }