public void ScriptProcessingTest() { IAtScriptProcessing iAtScriptProc = new AtScriptProcessing(); string [] arrayString = new string[] { "//asdfasda", "__@HEX = 0xAA|True|530|This is a comment", "AT To Send|False|500|This is a comment" }; var ret = iAtScriptProc.ProcessArrayString(arrayString); Assert.AreEqual(2, ret.Count); Assert.AreEqual(true, ret[0].IsSpecialCommand); Assert.AreEqual(0xAA, ret[0].ByteToSend); Assert.AreEqual(true, ret[0].ReceiveData); Assert.AreEqual(530, ret[0].Delay); Assert.AreEqual(false, ret[1].IsSpecialCommand); Assert.AreEqual("AT To Send", ret[1].ATCommandToSend); Assert.AreEqual(false, ret[1].ReceiveData); Assert.AreEqual(500, ret[1].Delay); }
public void ScriptProcessingTest() { IAtScriptProcessing iAtScriptProc = new AtScriptProcessing(); string [] arrayString = new string[] { "//asdfasda", "__@HEX = 0xAA|True|530|This is a comment", "AT To Send|False|500|This is a comment" }; var ret = iAtScriptProc.ProcessArrayString(arrayString); Assert.AreEqual(2, ret.Count); Assert.AreEqual(true, ret[0].IsSpecialCommand); Assert.AreEqual(0xAA, ret[0].ByteToSend); Assert.AreEqual(true, ret[0].ReceiveData); Assert.AreEqual(530, ret[0].Delay); Assert.AreEqual(false, ret[1].IsSpecialCommand); Assert.AreEqual("AT To Send", ret[1].ATCommandToSend); Assert.AreEqual(false, ret[1].ReceiveData); Assert.AreEqual(500, ret[1].Delay); }
private void btnRun_Click(object sender, EventArgs e) { string SCRFile = tssStatusScrFile.Text.Trim(); txtResult.Clear(); Application.DoEvents(); if (File.Exists(SCRFile) == true) { SerialPort mySer = new SerialPort(cmbSerial.SelectedItem.ToString(), int.Parse(cmbBaud.SelectedItem.ToString())); mySer.WriteBufferSize = 1000; mySer.ReadBufferSize = (int)numRXBuffSize.Value; mySer.Handshake = (Handshake)Enum.Parse(typeof(Handshake), cmbHandShaking.SelectedItem.ToString()); mySer.WriteTimeout = 1000; try { string[] FileAllLines = File.ReadAllLines(SCRFile); IAtScriptProcessing iAtScriptProc = new AtScriptProcessing(); var ret = iAtScriptProc.ProcessArrayString(FileAllLines); try { mySer.Open(); } catch { MessageBox.Show("Error Opening Serial Port!"); return; } btnRun.Enabled = false; foreach (var x in ret) { string temp; mySer.DiscardInBuffer(); if (x.IsSpecialCommand) { temp = String.Format("Special Command: Sending Hex Data 0x{0:X2}\r\n", x.ByteToSend); txtResult.AppendText(temp); mySer.Write(new byte[] { x.ByteToSend }, 0, 1); } else { txtResult.AppendText("Sending Command: " + x.ATCommandToSend); txtResult.AppendText("\r\n"); try { mySer.Write(x.ATCommandToSend); mySer.Write(new byte[] { 0x0D }, 0, 1); } catch { MessageBox.Show("Error Sending Data to GSM Modem!", FRM_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } } txtResult.AppendText("Delay: " + x.Delay + "msec"); txtResult.AppendText("\r\n"); Thread.Sleep(x.Delay); if (x.ReceiveData) { string readSer = mySer.ReadExisting(); if (chkBinMode.Checked) { char[] readChar = readSer.ToCharArray(); StringBuilder strb = new StringBuilder(); foreach (char mychar in readChar) { strb.AppendFormat("<0x{0:X2}>", (int)mychar); } readSer = strb.ToString(); } else if (chkShowEndHex.Checked) { for (int ctr = 0; ctr < 0x20; ctr++) { readSer = readSer.Replace(String.Format("{0}", (char)ctr), String.Format("<0x{0:X2}>", ctr)); } } txtResult.AppendText("Received Reply:\r\n"); txtResult.AppendText(readSer); txtResult.AppendText("\r\n"); } txtResult.AppendText("===========================\r\n"); } } finally { btnRun.Enabled = true; mySer.Dispose(); System.GC.Collect(); } txtResult.AppendText("===========================\r\n"); txtResult.AppendText("===========END===========\r\n"); } else { if (String.IsNullOrEmpty(SCRFile)) MessageBox.Show("Choose file first!", FRM_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Stop); else MessageBox.Show("File does not exist!", FRM_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Stop); } }