private void axSerialPortMonitorAx_OnWrite(object sender, AxspsnifferLib._ISerialPortMonitorAxEvents_OnWriteEvent e) { System.Array buf = e.data as System.Array; //Check to see if real receipt data is being sent to the printer. Examples included cash drawer. if ( buf.Length < 500) { AddLog("Non receipt data",false); } else { rawContent = System.Text.Encoding.ASCII.GetString(buf as byte[]); cleanContent = CleanString(rawContent); AddLog("Content" + cleanContent, false); } }
private void axSerialPortMonitorAx_OnOpenClose(object sender, AxspsnifferLib._ISerialPortMonitorAxEvents_OnOpenCloseEvent e) { AddLog("====================================",false); AddLog("Serial port " + (e.bOpen ? "opened." : "closed"),false); AddLog("====================================",false); string POSapp = e.szPath; if (e.bOpen) { AddLog("Application: " + e.szPath,false); if (POSapp != "" && !POSapp.Contains("DocketPlaceClient")) { is_realapp = true; } } else { if (is_realapp && !String.IsNullOrEmpty(cleanContent)) { AddLog("DocketPlace Footer", true); is_realapp = false; ClearErrorMessages(); //Stop Sniffing. SniffSwitch(); if (Properties.Settings.Default.POSSoftware == "Microsoft") { TriggerCashDrawer(); } if (SendSalesDataCheckBox.Checked) { try { LocalDocket currentDocket = null; switch (Properties.Settings.Default.POSSoftware) { case "MYOB": currentDocket = MYOBRewards.GetLastDocket(rawContent); break; case "Microsoft": currentDocket = MicrosoftRewards.GetLastDocket(rawContent); break; } if (currentDocket != null) { try { AdRequest newRewardsRequest = HydrateAdRequest(); currentDocket.receipt_content = Helpers.EncodeToBase64(cleanContent); newRewardsRequest.currentDocket = currentDocket; printCoupon(false, cleanContent, newRewardsRequest); } catch (System.Net.WebException ex) { RewardsHelper.SaveLastDocket(currentDocket); AddLog(ex.Status.ToString(), true); PrintDefaulltLocalAd(); } } } catch (Exception ex) { AddLog(ex.ToString(), true); PrintDefaulltLocalAd(); } } else { try { AdRequest newRequest = HydrateAdRequest(); LocalDocket nonRewardsDocket = new LocalDocket(); nonRewardsDocket.creation_datetime = DateTime.Now; nonRewardsDocket.receipt_content = Helpers.EncodeToBase64(cleanContent); newRequest.currentDocket = nonRewardsDocket; printCoupon(false, cleanContent, newRequest); } catch (System.Net.WebException ex) { PrintDefaulltLocalAd(); } } //Clear the content in case theres any weird non receipt commands sent to printer afterwards. rawContent = ""; cleanContent = ""; AddLog("DocketPlace Footer Printed", true); //Start Sniffing again. SniffSwitch(); } } }