override public void HandleMsg(string msg) { if (msg == "errorBeep") { Beeps(3); } else if (msg == "beepTwice") { Beeps(2); } else if (msg == "goodBeep") { Beeps(1); } else if (msg == "twoPairs") { Thread.Sleep(300); Beeps(2); Thread.Sleep(300); Beeps(2); } else if (msg == "rePoll") { scale_state = WeighState.None; sp.Write("S14\r"); } }
override public void HandleMsg(string msg) { if (msg == "errorBeep") { Beeps(3); } else if (msg == "beepTwice") { Beeps(2); } else if (msg == "goodBeep") { Beeps(1); } else if (msg == "twoPairs") { Thread.Sleep(300); Beeps(2); Thread.Sleep(300); Beeps(2); } else if (msg == "rePoll") { /* ignore these commands on purpose scale_state = WeighState.None; GetStatus(); */ } else if (msg == "wakeup") { scale_state = WeighState.None; GetStatus(); } else if (msg == "reBoot") { scale_state = WeighState.None; lock (writeLock) { // ASCII: 10 sp.Write(new byte[]{ STX, 0x31, 0x30, ETX }, 0, 4); Thread.Sleep(5000); // ASCII: 14 sp.Write(new byte[]{ STX, 0x31, 0x34, ETX }, 0, 4); } } }
public SPH_NCR_Scale(string p) : base(p) { sp = new SerialPort(); sp.PortName = this.port; sp.BaudRate = 9600; sp.DataBits = 7; sp.StopBits = StopBits.One; sp.Parity = Parity.Odd; sp.RtsEnable = true; sp.Handshake = Handshake.None; sp.ReadTimeout = 500; scale_state = WeighState.None; last_weight = "0000"; sp.Open(); }
public SPH_Magellan_Scale(string p) : base(p) { sp = new SerialPort(); sp.PortName = this.port; sp.BaudRate = 9600; sp.DataBits = 7; sp.StopBits = StopBits.One; sp.Parity = Parity.Odd; sp.RtsEnable = true; sp.Handshake = Handshake.None; sp.ReadTimeout = 500; scale_state = WeighState.None; last_weight = "0000"; sp.Open(); }
override public void HandleMsg(string msg) { if (msg == "errorBeep") { Beeps(3); } else if (msg == "beepTwice") { Beeps(2); } else if (msg == "goodBeep") { Beeps(1); } else if (msg == "twoPairs") { Thread.Sleep(300); Beeps(2); Thread.Sleep(300); Beeps(2); } else if (msg == "rePoll") { /* ignore these commands on purpose * scale_state = WeighState.None; * GetStatus(); */ } else if (msg == "wakeup") { scale_state = WeighState.None; GetStatus(); } else if (msg == "reBoot") { scale_state = WeighState.None; lock (writeLock) { // ASCII: 10 sp.Write(new byte[] { STX, 0x31, 0x30, ETX }, 0, 4); Thread.Sleep(5000); // ASCII: 14 sp.Write(new byte[] { STX, 0x31, 0x34, ETX }, 0, 4); } } }
override public void HandleMsg(string msg) { if (msg == "errorBeep") { Beeps(3); } else if (msg == "beepTwice") { Beeps(2); } else if (msg == "goodBeep") { Beeps(1); } else if (msg == "twoPairs") { Thread.Sleep(300); Beeps(2); Thread.Sleep(300); Beeps(2); } else if (msg == "rePoll") { /* ignore these commands on purpose * scale_state = WeighState.None; * GetStatus(); */ } else if (msg == "wakeup") { scale_state = WeighState.None; GetStatus(); } else if (msg == "reBoot") { scale_state = WeighState.None; lock (writeLock) { sp.Write("S10\r"); Thread.Sleep(5000); sp.Write("S14\r"); } } }
private string ParseData(string s) { if (s.Substring(0, 2) == "S0") // scanner message { if (s.Substring(0, 4) == "S08A" || s.Substring(0, 4) == "S08F") // UPC-A or EAN-13 { return(s.Substring(4)); } else if (s.Substring(0, 4) == "S08E") // UPC-E { return(this.ExpandUPCE(s.Substring(4))); } else if (s.Substring(0, 4) == "S08R") // GTIN / GS1 { return("GS1~" + s.Substring(3)); } else if (s.Substring(0, 5) == "S08B1") // Code39 { return(s.Substring(5)); } else if (s.Substring(0, 5) == "S08B2") // Interleaved 2 of 5 { return(s.Substring(5)); } else if (s.Substring(0, 5) == "S08B3") // Code128 { return(s.Substring(5)); } else { return(s); // catch all } } else if (s.Substring(0, 2) == "S1") // scale message /** * The scale supports two primary commands: * S11 is "get stable weight". This tells the scale to return * the next stable non-zero weight. * S14 is "get state". This tells the scale to return its * current state. * * The "scale_state" variable tracks all six known scale states. * The state is only changed if the status response is different * than the current state and this only returns a non-null string * when the state changes. The goal is to only pass a message back * to POS once per state change. The "last_weight" is tracked in * case the scale jumps directly from one stable, non-zero weight * to another without passing through another state in between. */ { if (s.Substring(0, 3) == "S11") // stable weight following weight request { GetStatus(); if (scale_state != WeighState.NonZero || last_weight != s.Substring(3)) { scale_state = WeighState.NonZero; last_weight = s.Substring(3); return(s); } } else if (s.Substring(0, 4) == "S140") // scale not ready { GetStatus(); if (scale_state != WeighState.None) { scale_state = WeighState.None; return("S140"); } } else if (s.Substring(0, 4) == "S141") // weight not stable { GetStatus(); if (scale_state != WeighState.Motion) { scale_state = WeighState.Motion; return("S141"); } } else if (s.Substring(0, 4) == "S142") // weight over max { GetStatus(); if (scale_state != WeighState.Over) { scale_state = WeighState.Over; return("S142"); } } else if (s.Substring(0, 4) == "S143") // stable zero weight { GetStatus(); if (scale_state != WeighState.Zero) { scale_state = WeighState.Zero; return("S110000"); } } else if (s.Substring(0, 4) == "S144") // stable non-zero weight { GetStatus(); if (scale_state != WeighState.NonZero || last_weight != s.Substring(4)) { scale_state = WeighState.NonZero; last_weight = s.Substring(4); return("S11" + s.Substring(4)); } } else if (s.Substring(0, 4) == "S145") // scale under zero weight { GetStatus(); if (scale_state != WeighState.Under) { scale_state = WeighState.Under; return("S145"); } } else { GetStatus(); return(s); // catch all } } else // not scanner or scale message { return(s); // catch all } return(null); }
private string ParseData(string s) { if (s.Substring(0,1) == "0") { // scanner message if (s.Substring(0,3) == "08A" || s.Substring(0,3) == "08F") { // UPC-A or EAN-13 return s.Substring(3); } else if (s.Substring(0,3) == "08E") { // UPC-E return this.ExpandUPCE(s.Substring(3)); } else if (s.Substring(0,3) == "08R") { // GTIN / GS1 return "GS1~"+s.Substring(2); } else if (s.Substring(0,4) == "08B1") { // Code39 return s.Substring(4); } else if (s.Substring(0,4) == "08B2") { // Interleaved 2 of 5 return s.Substring(4); } else if (s.Substring(0,4) == "08B3") { // Code128 return s.Substring(4); } else { return s; // catch all } } else if (s.Substring(0,1) == "1") { // scale message /** The scale supports two primary commands: 11 is "get stable weight". This tells the scale to return the next stable non-zero weight. 14 is "get state". This tells the scale to return its current state. The "scale_state" variable tracks all six known scale states. The state is only changed if the status response is different than the current state and this only returns a non-null string when the state changes. The goal is to only pass a message back to POS once per state change. The "last_weight" is tracked in case the scale jumps directly from one stable, non-zero weight to another without passing through another state in between. */ if (s.Substring(0,2) == "11") { // stable weight following weight request GetStatus(); if (scale_state != WeighState.NonZero || last_weight != s.Substring(2)) { scale_state = WeighState.NonZero; last_weight = s.Substring(2); return "S"+s; } } else if (s.Substring(0,3) == "140") { // scale not ready GetStatus(); if (scale_state != WeighState.None) { scale_state = WeighState.None; return "S140"; } } else if (s.Substring(0,3) == "141") { // weight not stable GetStatus(); if (scale_state != WeighState.Motion) { scale_state = WeighState.Motion; return "S141"; } } else if (s.Substring(0,3) == "142") { // weight over max GetStatus(); if (scale_state != WeighState.Over) { scale_state = WeighState.Over; return "S142"; } } else if (s.Substring(0,3) == "143") { // stable zero weight GetStatus(); if (scale_state != WeighState.Zero) { scale_state = WeighState.Zero; return "S110000"; } } else if (s.Substring(0,3) == "144") { // stable non-zero weight GetStatus(); if (scale_state != WeighState.NonZero || last_weight != s.Substring(3)) { scale_state = WeighState.NonZero; last_weight = s.Substring(3); return "S11"+s.Substring(3); } } else if (s.Substring(0,3) == "145") { // scale under zero weight GetStatus(); if (scale_state != WeighState.Under) { scale_state = WeighState.Under; return "S145"; } } else { GetStatus(); return "S"+s; // catch all } } else { // not scanner or scale message return s; // catch all } return null; }
private string ParseData(string s) { if (s.Substring(0,2) == "S0") { // scanner message if (s.Substring(0,4) == "S08A" || s.Substring(0,4) == "S08F") { // UPC-A or EAN-13 return s.Substring(4); } else if (s.Substring(0,4) == "S08E") { // UPC-E return this.ExpandUPCE(s.Substring(4)); } else if (s.Substring(0,4) == "S08R") { // GTIN / GS1 return "GS1~"+s.Substring(3); } else if (s.Substring(0,5) == "S08B1") { // Code39 return s.Substring(5); } else if (s.Substring(0,5) == "S08B2") { // Interleaved 2 of 5 return s.Substring(5); } else if (s.Substring(0,5) == "S08B3") { // Code128 return s.Substring(5); } else { return s; // catch all } } else if (s.Substring(0,2) == "S1") { // scale message /** Rate limiter. Two consecutive, identical messages are probably scale state results. Take a short pause to avoid flooding the scale with constant state requests. */ if (s == last_message) { Thread.Sleep(200); } /** The scale supports two primary commands: S11 is "get stable weight". This tells the scale to return the next stable non-zero weight. S14 is "get state". This tells the scale to return its current state. The "scale_state" variable tracks whether the scale is currently at a stable zero weight, stable non-zero weight, or neither (i.e., None). Future: maybe stop using S11 entirely? Send a hard reset (S10) in some situations? */ if (s.Substring(0,3) == "S11") { // stable weight following weight request sp.Write("S14\r"); scale_state = WeighState.NonZero; return s; } else if (s.Substring(0,4) == "S140") { // scale not ready scale_state = WeighState.None; sp.Write("S14\r"); return "S140"; } else if (s.Substring(0,4) == "S141") { // weight not stable scale_state = WeighState.None; sp.Write("S14\r"); return "S141"; } else if (s.Substring(0,4) == "S142") { // weight over max scale_state = WeighState.None; sp.Write("S14\r"); return "S142"; } else if (s.Substring(0,4) == "S143") { // stable zero weight sp.Write("S14\r"); if (scale_state != WeighState.Zero) { scale_state = WeighState.Zero; return "S110000"; } } else if (s.Substring(0,4) == "S144") { // stable non-zero weight if (scale_state != WeighState.NonZero) { sp.Write("S11\r"); } else { sp.Write("S14\r"); } } else if (s.Substring(0,4) == "S145") { // scale under zero weight scale_state = WeighState.None; sp.Write("S14\r"); return "S145"; } else { return s; // catch all } } else { // not scanner or scale message return s; // catch all } return null; }
private string ParseData(string s) { if (s.Substring(0, 2) == "S0") // scanner message { if (s.Substring(0, 4) == "S08A" || s.Substring(0, 4) == "S08F") // UPC-A or EAN-13 { return(s.Substring(4)); } else if (s.Substring(0, 4) == "S08E") // UPC-E { return(this.ExpandUPCE(s.Substring(4))); } else if (s.Substring(0, 4) == "S08R") // GTIN / GS1 { return("GS1~" + s.Substring(3)); } else if (s.Substring(0, 5) == "S08B1") // Code39 { return(s.Substring(5)); } else if (s.Substring(0, 5) == "S08B2") // Interleaved 2 of 5 { return(s.Substring(5)); } else if (s.Substring(0, 5) == "S08B3") // Code128 { return(s.Substring(5)); } else { return(s); // catch all } } else if (s.Substring(0, 2) == "S1") // scale message /** * Rate limiter. Two consecutive, identical messages * are probably scale state results. Take a short * pause to avoid flooding the scale with constant * state requests. */ { if (s == last_message) { Thread.Sleep(200); } /** * The scale supports two primary commands: * S11 is "get stable weight". This tells the scale to return * the next stable non-zero weight. * S14 is "get state". This tells the scale to return its * current state. * The "scale_state" variable tracks whether the scale is * currently at a stable zero weight, stable non-zero weight, * or neither (i.e., None). * * Future: maybe stop using S11 entirely? Send a hard reset (S10) * in some situations? */ if (s.Substring(0, 3) == "S11") // stable weight following weight request { sp.Write("S14\r"); scale_state = WeighState.NonZero; return(s); } else if (s.Substring(0, 4) == "S140") // scale not ready { scale_state = WeighState.None; sp.Write("S14\r"); return("S140"); } else if (s.Substring(0, 4) == "S141") // weight not stable { scale_state = WeighState.None; sp.Write("S14\r"); return("S141"); } else if (s.Substring(0, 4) == "S142") // weight over max { scale_state = WeighState.None; sp.Write("S14\r"); return("S142"); } else if (s.Substring(0, 4) == "S143") // stable zero weight { sp.Write("S14\r"); if (scale_state != WeighState.Zero) { scale_state = WeighState.Zero; return("S110000"); } } else if (s.Substring(0, 4) == "S144") // stable non-zero weight { if (scale_state != WeighState.NonZero) { sp.Write("S11\r"); } else { sp.Write("S14\r"); } } else if (s.Substring(0, 4) == "S145") // scale under zero weight { scale_state = WeighState.None; sp.Write("S14\r"); return("S145"); } else { return(s); // catch all } } else // not scanner or scale message { return(s); // catch all } return(null); }
override public void HandleMsg(string msg) { if (msg == "errorBeep") { Beeps(3); } else if (msg == "beepTwice") { Beeps(2); } else if (msg == "goodBeep") { Beeps(1); } else if (msg == "twoPairs") { Thread.Sleep(300); Beeps(2); Thread.Sleep(300); Beeps(2); } else if (msg == "rePoll") { /* ignore these commands on purpose scale_state = WeighState.None; GetStatus(); */ } else if (msg == "wakeup") { scale_state = WeighState.None; GetStatus(); } else if (msg == "reBoot") { scale_state = WeighState.None; lock (writeLock) { sp.Write("S10\r"); Thread.Sleep(5000); sp.Write("S14\r"); } } }
/// <summary> /// Initializes a new instance of the <see cref="SPH_Magellan_Scale"/> class. /// </summary> /// <param name="p">port file descriptor</param> public SPH_Magellan_Scale(string p) : base(p) { this.sp = new SerialPort(); this.sp.PortName = this.port; this.sp.BaudRate = 9600; this.sp.DataBits = 7; this.sp.StopBits = StopBits.One; this.sp.Parity = Parity.Odd; this.sp.RtsEnable = true; this.sp.Handshake = Handshake.None; this.sp.ReadTimeout = 500; this.wsp = new WrappedSerialPort(this.sp); this.scaleState = WeighState.None; this.lastWeight = "0000"; }