private void Button_Send_Click(object sender, EventArgs e) { if (textBox_command.Text + textBox_param.Text != "") { String sendStrHex; if (checkBox_hexCommand.Checked) { sendStrHex = textBox_command.Text; } else { sendStrHex = Accessory.ConvertStringToHex(textBox_command.Text); } if (checkBox_hexParam.Checked) { sendStrHex += textBox_param.Text; } else { sendStrHex += Accessory.ConvertStringToHex(textBox_param.Text); } try { serialPort1.Write(Accessory.ConvertHexToByteArray(sendStrHex), 0, sendStrHex.Length / 3); } catch (Exception ex) { MessageBox.Show("Error sending to port " + serialPort1.PortName + ": " + ex.Message); } var outStr = Accessory.ConvertHexToString(sendStrHex); _logger.AddText(outStr, (byte)DataDirection.Sent, DateTime.Now); } }
public static string DataToRaw(string s, int n) { var outStr = ""; if (s.Substring(0, 1) == "[") { outStr = s.Substring(1, s.Length - 2); } else if (s.Substring(0, 1) == "\"") { outStr = Accessory.ConvertStringToHex(s.Substring(1, s.Length - 2), Settings.Default.CodePage); } else { return(""); } if (outStr.Length > n * 3) { outStr = outStr.Substring(0, n * 3); } while (outStr.Length < n * 3) { outStr += "00 "; } return(outStr); }
private void Button_WRITE_Click(object sender, EventArgs e) { if (textBox_command.Text + textBox_param.Text != "") { string outStr; if (checkBox_hexCommand.Checked) { outStr = textBox_command.Text; } else { outStr = Accessory.ConvertStringToHex(textBox_command.Text); } if (checkBox_hexParam.Checked) { outStr += textBox_param.Text; } else { outStr += Accessory.ConvertStringToHex(textBox_param.Text); } if (outStr != "") { _logger.AddText(Accessory.ConvertHexToString(outStr), (byte)DataDirection.Sent, DateTime.Now); textBox_command.AutoCompleteCustomSource.Add(textBox_command.Text); textBox_param.AutoCompleteCustomSource.Add(textBox_param.Text); var outStream = Accessory.ConvertHexToByteArray(outStr); WriteTCP(outStream); } } Timer1_Tick(this, EventArgs.Empty); }
private void Button_Send_Click(object sender, EventArgs e) { byte[] buff = { }; if (textBox_command.Text + textBox_command.Text != "") { var sendStrHex = ""; if (checkBox_hexCommand.Checked) { sendStrHex = textBox_command.Text; } else { sendStrHex = Accessory.ConvertStringToHex(textBox_command.Text); } if (checkBox_hexParam.Checked) { sendStrHex += textBox_param.Text; } else { sendStrHex += Accessory.ConvertStringToHex(textBox_param.Text); } if (sendStrHex != "") { LptOpen(comboBox_portname1.SelectedItem.ToString()); if (!_isConnected) { MessageBox.Show("Error opening port " + comboBox_portname1.SelectedItem); comboBox_portname1.Enabled = true; } else { if (checkBox_hexTerminal.Checked) { SetText(">> " + sendStrHex + "\r\n"); } else { SetText(">> " + Accessory.ConvertHexToString(sendStrHex) + "\r\n"); } textBox_command.AutoCompleteCustomSource.Add(textBox_command.Text); textBox_param.AutoCompleteCustomSource.Add(textBox_param.Text); try { _lptPort.Write(Accessory.ConvertHexToByteArray(sendStrHex), 0, sendStrHex.Length / 3); } catch (Exception ex) { MessageBox.Show("Error sending to port " + comboBox_portname1.SelectedItem + ": " + ex.Message); } } } } }
private void CheckBox_hexParam_CheckedChanged(object sender, EventArgs e) { if (checkBox_hexParam.Checked) { textBox_param.Text = Accessory.ConvertStringToHex(textBox_param.Text); } else { textBox_param.Text = Accessory.ConvertHexToString(textBox_param.Text); } }
// !!! incorrect layout public static string PrefDataToRaw(string s, int n) { if (s.Length > n - 2) { s = s.Substring(0, n - 2); } var outStr = NumberToRaw(s.Length.ToString(), 2); outStr += Accessory.ConvertStringToHex(s, Settings.Default.CodePage); return(outStr); }
private void checkBox_hexCommand_CheckedChanged(object sender, EventArgs e) { if (checkBox_hexCommand.Checked == true) { textBox_command.Text = Accessory.ConvertStringToHex(textBox_command.Text); } else { textBox_command.Text = Accessory.ConvertHexToString(textBox_command.Text); } }
public static string StringToRaw(string s, int n) { //while (s.Length < n) s += "\0"; //return Accessory.ConvertStringToHex(s, CustomFiscalControl.Properties.Settings.Default.CodePage).Substring(0, n * 3); var outStr = Accessory.ConvertStringToHex(s.Substring(1, s.Length - 2), Settings.Default.CodePage); if (outStr.Length > n * 3) { outStr = outStr.Substring(0, n * 3); } while (outStr.Length < n * 3) { outStr += "00 "; } return(outStr); }
private void Button_WRITE_Click(object sender, EventArgs e) { if (Selected_Printer != null) { if (textBox_command.Text + textBox_param.Text != "") { string outStr; if (checkBox_hexCommand.Checked) { outStr = textBox_command.Text; } else { outStr = Accessory.ConvertStringToHex(textBox_command.Text); } if (checkBox_hexParam.Checked) { outStr += textBox_param.Text; } else { outStr += Accessory.ConvertStringToHex(textBox_param.Text); } if (outStr != "") { timer1.Enabled = false; _logger.AddText(Accessory.ConvertHexToString(outStr), (byte)DataDirection.Sent, DateTime.Now); textBox_command.AutoCompleteCustomSource.Add(textBox_command.Text); textBox_param.AutoCompleteCustomSource.Add(textBox_param.Text); if (Selected_Printer.GenericWrite(Accessory.ConvertHexToByteArray(outStr))) { ReadUSB(); } else { _logger.AddText("Write failure", (byte)DataDirection.Error, DateTime.Now, TextLogger.TextLogger.TextFormat.PlainText); } timer1.Enabled = true; } } } else { Button_CLOSE_Click(this, EventArgs.Empty); } }
private void button_Send_Click(object sender, EventArgs e) { if (textBox_command.Text != "" || textBox_param.Text != "") { string outStr = ""; string sendStrHex = ""; if (checkBox_hexCommand.Checked == true) { sendStrHex = textBox_command.Text; } else { sendStrHex = Accessory.ConvertStringToHex(textBox_command.Text); } if (checkBox_hexParam.Checked == true) { sendStrHex += textBox_param.Text; } else { sendStrHex += Accessory.ConvertStringToHex(textBox_param.Text); } try { serialPort1.Write(Accessory.ConvertHexToByteArray(sendStrHex), 0, sendStrHex.Length / 3); } catch (Exception ex) { MessageBox.Show("Error sending to port " + serialPort1.PortName + ": " + ex.Message); } if (checkBox_hexTerminal.Checked == true) { outStr = sendStrHex; } else { outStr = Accessory.ConvertHexToString(sendStrHex); } collectBuffer(outStr, Port1DataOut); } }
private void button_Send_Click(object sender, EventArgs e) { if (comboBox_Printer.Items.Count > 0 && comboBox_Printer.SelectedItem.ToString() != "") { if (textBox_command.Text + textBox_param.Text != "") { string outStr; if (checkBox_hexCommand.Checked) { outStr = textBox_command.Text; } else { outStr = Accessory.ConvertStringToHex(textBox_command.Text); } if (checkBox_hexParam.Checked) { outStr += textBox_param.Text; } else { outStr += Accessory.ConvertStringToHex(textBox_param.Text); } if (outStr != "") { if (checkBox_hexTerminal.Checked) { collectBuffer(outStr, Port1DataOut); } else { collectBuffer(Accessory.ConvertHexToString(outStr), Port1DataOut); } textBox_command.AutoCompleteCustomSource.Add(textBox_command.Text); textBox_param.AutoCompleteCustomSource.Add(textBox_param.Text); RawPrinterSender.SendRAWToPrinter(comboBox_Printer.SelectedItem.ToString(), Accessory.ConvertHexToByteArray(outStr)); } } } }
private static string ReplaceUnprintable(string text, bool leaveCrLf = true) { var str = new StringBuilder(); for (var i = 0; i < text.Length; i++) { var c = text[i]; if (char.IsControl(c) && !(leaveCrLf && (c == '\r' || c == '\n' || c == '\t'))) { str.Append("<0x" + Accessory.ConvertStringToHex(c.ToString()).Trim() + ">"); if (c == '\n') { str.Append("\n"); } } else { str.Append(c); } } return(str.ToString()); }
// !!! incorrect layout public static string TLVDataToRaw(string s, int n) { if (!(s.Contains('[') && s.Contains(']'))) { return(""); } if (s.Length < 3) { return(""); } var outStr = ""; var tlvType = -1; int.TryParse(s.Substring(0, s.IndexOf(']')).Replace("[", ""), out tlvType); s = s.Substring(s.IndexOf(']') + 1); if (n > s.Length) { n = s.Length; } outStr = ErrorToRaw(n.ToString(), 2); outStr += Accessory.ConvertStringToHex(s, Settings.Default.CodePage).Substring(0, n * 3); return(outStr); }
public bool AddText(string text, byte channel, DateTime logTime, TextFormat textFormat, TimeFormat timeFormat = TimeFormat.Default, DateFormat dateFormat = DateFormat.Default) { if (text == null || text.Length <= 0) { return(true); } var tmpStr = new StringBuilder(); var continueString = false; if (channel != _prevChannel) { _prevChannel = channel; } else if (LineTimeLimit > 0) { var t = (int)logTime.Subtract(_lastEvent).TotalMilliseconds; if (t <= LineTimeLimit) { continueString = true; } _lastEvent = logTime; } if (!continueString) { tmpStr.Append(Environment.NewLine); if (logTime != DateTime.MinValue) { if (dateFormat == DateFormat.Default) { dateFormat = DefaultDateFormat; } if (dateFormat == DateFormat.LongDate) { tmpStr.Append(logTime.ToLongDateString() + " "); } else if (dateFormat == DateFormat.ShortDate) { tmpStr.Append(logTime.ToShortDateString() + " "); } if (timeFormat == TimeFormat.Default) { timeFormat = DefaultTimeFormat; } if (timeFormat == TimeFormat.LongTime) { tmpStr.Append(logTime.ToLongTimeString() + "." + logTime.Millisecond.ToString("D3") + " "); } else if (timeFormat == TimeFormat.ShortTime) { tmpStr.Append(logTime.ToShortTimeString() + " "); } } if (Channels.ContainsKey(channel)) { if (!string.IsNullOrEmpty(Channels[channel])) { tmpStr.Append(Channels[channel] + " "); } } } if (textFormat == TextFormat.Default) { textFormat = DefaultTextFormat; } if (FilterZeroChar) { text = Accessory.FilterZeroChar(text); } if (textFormat == TextFormat.PlainText) { tmpStr.Append(text); } else if (textFormat == TextFormat.Hex) { tmpStr.Append(Accessory.ConvertStringToHex(text)); } else if (textFormat == TextFormat.AutoReplaceHex) { tmpStr.Append(ReplaceUnprintable(text)); } return(AddTextToBuffer(tmpStr.ToString())); }