public void SendQueuePush(string msg, string value) { SerialMsg Packet = new SerialMsg(msg, value); _dispatchQueue.Enqueue(Packet); }
private void SendData(SerialMsg Packet) { string msg = ""; string instruction = Packet.GetInstruction(); string value = Packet.GetValue(); msg = instruction + value; switch (instruction) { case "BEEP": _returnBuffer = ""; //Console.WriteLine("Turning devicice beeper : {0}", value); DataGetter(msg); Thread.Sleep(_returnDelay); break; case "OUT": _returnBuffer = ""; //Console.WriteLine("Turning device power to: {0}", value); DataGetter(msg); Thread.Sleep(_returnDelay); break; case "VSET1:": _returnBuffer = ""; //Console.WriteLine("Sending voltage value: {0}",value); _port.Write(msg); //Console.WriteLine("Data sent: {0}", msg); Thread.Sleep(_returnDelay); break; case "ISET1:": _returnBuffer = ""; //Console.WriteLine("Sending current value: {0}",value); _port.Write(msg); //Console.WriteLine("Data sent: {0}", msg); Thread.Sleep(_returnDelay); break; case "OCP": _returnBuffer = ""; //Console.WriteLine("Setting OCP to: {0}", value); _port.Write(msg); Thread.Sleep(_returnDelay); break; case "OVP": _returnBuffer = ""; //Console.WriteLine("Setting OVP to: {0}", value); _port.Write(msg); Thread.Sleep(_returnDelay); break; case "RCL": _returnBuffer = ""; //Console.WriteLine("recalling state from Mem loc{0}", value); _port.Write(msg); Thread.Sleep(_returnDelay); break; case "SAV": _returnBuffer = ""; //Console.WriteLine("Saving state to Mem loc{0}",value); _port.Write(msg); Thread.Sleep(_returnDelay); break; case "VOUT1?": _returnBuffer = ""; DataGetter(msg); Thread.Sleep(_returnDelay); try { _fvoltage = float.Parse(_returnBuffer); } catch { Console.WriteLine("Voltage sense error"); } break; case "IOUT1?": _returnBuffer = ""; DataGetter(msg); Thread.Sleep(_returnDelay); try { _fcurrent = float.Parse(_returnBuffer); } catch { Console.WriteLine("Current sense error"); } break; case "*IDN?": _returnBuffer = ""; //Console.WriteLine("Getting device decription"); DataGetter(msg); Thread.Sleep(_returnDelay); _IDN = _returnBuffer; //Console.Write("Connected: ", _returnBuffer); break; case "STATUS?": _returnBuffer = ""; //Console.WriteLine("Getting device decription"); DataGetter(msg); Thread.Sleep(_returnDelay); _IDN = _returnBuffer; //Console.Write("Connected: ", _returnBuffer); break; case "CSL": _ConsoleReturn = ""; _returnBuffer = ""; //Console.WriteLine("Sending console message"); DataGetter(value); Thread.Sleep(_returnDelay); _ConsoleReturn = _returnBuffer; //Console.Write("Device returned: ", _ConsoleReturn); //Console.WriteLine("(Output in Hex): ", String.Format("{0,10:X}", _ConsoleReturn)); break; default: Console.WriteLine("Error, unsupported instruction"); _returnBuffer = ""; break; } }