I'm trying to write a string to a serial port, then send a command to tell the printer to return it's status in real time, if OK then send the next string.
I know how to create the form, create a serial port and write my string:
serialPort.Write("ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMN\n");
// send command to read status
// if status = 4, warn user & close port, if not...
// send next string
serialPort.Write("ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMN\n");
Where I'm having trouble is sending & receiving the real time status.
The command is:
Transmit real-time status
ASCII DLE EOTn [a]
Hex 10 04 n [a]
Decimal 16 4 n [a]
TM-T90, TM-T88IV, TM-U220 : 1 ≤ n ≤ 4, n = 7
TM-L90: 1 ≤ n ≤ 4, n = 8, a = 3 (when n = 8) (TM-L90 with Peeler)
1 ≤ n ≤ 4 (TM-L90 without Peeler)
n a Function
1 -- Transmit printer status
2 -- Transmit offline status
3 -- Transmit error status
4 -- Transmit roll paper sensor status
7 1 Transmit ink status A
2 Transmit ink status B
8 3 Transmit peeler status
All I care about is where n = 4 (Transmit roll paper sensor status)
If n returns 4, stop and close port with message to user that paper is low.
I will be using the same program for a 4 printers listed, like I said all I care about is if the status changes from 0 to 4.
I hope someone can help. Thank you.
Related
The "SerialPort" below is from OpenNETCF.IO.Ports.
Does this first pass/semi-edicated guess make sense for printing to a belt printer (Zebra QL220); that is, is it a decent starting point?
using (SerialPort serialPort = new SerialPort())
{
string someString = "Bla";
//serialPort.BaudRate = // I don't know what to put here yet, assuming this is needed
//serialPort.DataBits = // " "
//serialPort.Parity = // " "
//serialPort.StopBits = // " "
serialPort.PortName = "COM1"; // Is this what it wants?
serialPort.Open();
Thread.Sleep(2500); // I don't know why this is needed, or is it?
serialPort.Write(" ! U1 setvar \"device.languages\" \"line_print\"\r\n");
serialPort.Write(" ! U SETLP 5 1 46\r\nPAGE-WIDTH 480\r\nSETBOLD 2\r\nPRINT\r\n");
serialPort.Write(" ! U1 CENTER\r\n"+someString"\r\n! U1 SETBOLD 0\r\n");
serialPort.Write(" ! U1 CENTER\r\n");
serialPort.Write(" ! U1 SETLP 0 2 24");
serialPort.Close();
}
You might say, "Why don't you just try it and see?" but at present, at least, it's a long involved process to do that, because I can't run my app in my XP Mode VM on either deployment "Device" or Emulator (see How can I run my Windows CE project from within Visual Studio (2003)? if interested); what I need to do is copy the binary to the handheld to test any modified code; so, I'd rather be somewhat sure that it will work in some fashion before going through that rigamarole.
Yes, that is roughly what you want to do. You'll need to check the printer docos on what comm settings are required. It is typically 19200,N,8,1. With some printers, you need to pace how quickly you send the data. It is possible to send data so quickly that you exceed the serial data buffer on the printer. I recall, for example, having to add a small delay every 512 bytes sent or the tail end of a print stream would be lost. Not sure of the printer model though, so it is just something to keep an eye out for.
I am saving some of the rendered html of a web site by overriding the Render method and using HtmlAgilityPack. Here is the code:
protected override void Render(HtmlTextWriter writer)
{
using (HtmlTextWriter htmlwriter = new HtmlTextWriter(new StringWriter()))
{
base.Render(htmlwriter);
string output= htmlwriter.InnerWriter.ToString();
var doc = new HtmlDocument();
doc.LoadHtml(output);
doc.Save(currDir + "\\" + reportDir + "\\dashboardTable.html");
}
}
However, some process does not let go of the saved file and I am unable to delete it from the server. Does anyone know of an HtmlAgilityPack issue that would cause this?
Any advice is appreciated.
Regards.
EDIT:
I have tried both of the methods suggested. I can't tell if they are the solution yet because my app is frozen on the server due to the files I can't delete. However, when I use these solutions on my own machine, the rendered HTML does not save as an HTML table anymore but rather like this:
INCIDENT MANAGEMENT
Jul '12 F'12
Trend F'12 2011
(avg)
Severe Incidents (Sev1/2): 3 2.1 4.16
Severe Avoidable Incidents (Sev1/2): 1 1.3 1.91
Incidents (Sev3): 669 482 460.92
Incidents (Sev4) - No business Impact: 1012 808 793
Proactive Tickets Opened: 15 19.3 14
Proactive Tickets Resolved/Closed: 14 17.3 11
CHANGE MANAGEMENT
Total Planned Changes: 531 560 583.58
Change Success Rate (%): 99.5 99.4 99
Non-Remedial Urgent Changes: 6 11 47.08
PROBLEM MANAGEMENT
New PIRs: 2 1.4 2
Closed PIRs: 0 2 3
Overdue Action items: 2 3.2 0
COMPLIANCE MEASUREMENTS
Jul Trend Jun
Total Number of Perimeter Devices: 250 258
Perimeter Devices - Non Compliant: 36 31
Total Number of Internal Devices: 6676 6632
Internal Devices - Non Compliant: 173 160
Unauthorized Perimeter Changes: 0 0
Unauthorized Internal Changes 0 0
LEGEND
ISP LINKS
July June Trend
SOC CPO DRP SOC CPO DRP
40% 34% 74% 39% 35% 74%
BELL MPLS HEAD ENDS
July June Trend
SOC CPO SOC CPO
8% 5% 7% 10% 8% 5.5% 7% 10%
ENTERPRISE NETWORK (# of issues called out)
July June Trend
CORE FW/DMZ CORE FW/DMZ
1 0 1 0
US & INTL (# of issues called out)
July June Trend
US Intl US Intl
2 2 2 3
LINE OF BUSINESS BELL WAN MPLS
<> 50%-65% >65% <> 50%-65% >65% Trend
Retail: 2272 0 1 2269 4 0
Business Banking: 59 1 0 60 0 0
Wealth: 122 2 0 121 2 1
Corporate: 51 0 0 49 2 0
Remote ATM: 280 0 0 280 0 0
TOOLS
Version Currency Vulnerability Status Health Status
Key Messages:
where only the text data has been saved and all of the HTML and CSS is missing. If I just use doc.Save() I get an exact representation of the table as it displays on the website.
Try this instead. Maybe the Save method isn't closing the underlying stream.
using( FileStream stream = File.OpenWrite( currDir + "\\" + reportDir + "\\dashboardTable.html" ) ){
doc.Save(stream);
stream.Close();
}
Edit
Per #L.B's comments it appears that HtmlAgilityPack does use a using block as in my example so it will be ensuring that the stream gets closed.
Thus as I suggested at the end of my original answer this must be a server environment problem
Original Answer
This may be some sort of bug with HtmlAgilityPack - you may want to report it to the developers.
However to eliminate that possibility you may want to consider explicitly controlling the creation of the StreamWriter for the file so you are explicitly closing it yourself. Replace this line:
doc.Save(currDir + "\\" + reportDir + "\\dashboardTable.html");
With the following:
using (StreamWriter fileWriter = new StreamWriter(currDir + "\\" + reportDir + "\\dashboardTable.html"))
{
doc.Save(fileWriter);
fileWriter.Close();
}
If the issue still persists even with this change then that would suggest an issue with your server environment rather than an issue with HtmlAgilityPack. Btw to test if this change makes a difference you should start from a clean server environment rather than one where you are already having issues deleting the file in question.
I have a web site that displays a table along with some buttons, navigation tabs, etc. Using HtmlAgilityPack I would like to save only the node containing the table (a div) to a .html file. I have been experimenting with this code:
string dashboard = doc.DocumentNode.SelectSingleNode("//div[#id='Dashboard']").InnerHtml;
doc.LoadHtml(dashboard);
doc.Save(currDir + "\\dashboardOutputFile.html");
But this only preserves the text components of the table and none of its layout/display information. I have tried adding a Doctype declaration as well as enclosing html and body tags to the dashboard string but it has no effect.
Any advice is appreciated.
Regards.
EDIT:
I should be more explicit. I am capturing the html of my page by overriding the Render method:
protected override void Render(HtmlTextWriter writer)
{
using (HtmlTextWriter htmlwriter = new HtmlTextWriter(new StringWriter()))
{
base.Render(htmlwriter);
string renderedContent = htmlwriter.InnerWriter.ToString();
var doc = new HtmlDocument();
doc.LoadHtml(renderedContent);
try
{
string dashboard = doc.DocumentNode.SelectSingleNode("//div[#id='Dashboard']").InnerHtml;
dashboard = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><br><html xmlns=\"http://www.w3.org/1999/xhtml\"><head></head><body><div><br>" + dashboard + "<br></div></body></html>";
doc.LoadHtml(dashboard);
doc.Save(currDir + "\\dashboardOutputFile.html");
}
catch (NullReferenceException ex)
{
// Do nothing.
}
writer.Write(renderedContent);
}
}
To the best of my knowledge the string "dashboard" should contain a complete HTML page after this. However the resulting .html file displays like this:
INCIDENT MANAGEMENT
Jun '12 F'12
Trend F'12 2011
(avg)
Severe Incidents (Sev1/2): 2 2 4.16
Severe Avoidable Incidents (Sev1/2): 1 1.3 1.91
Incidents (Sev3): 600 459 460.92
Incidents (Sev4) - No business Impact: 869 782 793
Proactive Tickets Opened: 24 20 14
Proactive Tickets Resolved/Closed: 22 17.8 11
CHANGE MANAGEMENT
Total Planned Changes: 623 564 583.58
Change Success Rate (%): 99.9 99.4 99
Non-Remedial Urgent Changes: 5 11.4 47.08
PROBLEM MANAGEMENT
New PIRs: 1 1.4 2
Closed PIRs: 1 2.3 3
Overdue Action items: 2 3.4 0
COMPLIANCE MEASUREMENTS
Jun Trend May
Total Number of Perimeter Devices: 258 242
Perimeter Devices - Non Compliant: 31 7
Total Number of Internal Devices: 6632 6521
Internal Devices - Non Compliant: 160 38
Unauthorized Perimeter Changes: 0 0
Unauthorized Internal Changes 0 0
LEGEND
ISP LINKS
June May Trend
SOC CPO DRP SOC CPO DRP
39% 35% 74% 38% 35% 73%
BELL MPLS HEAD ENDS
June May Trend
SOC CPO SOC CPO
8% 5.5% 7% 10% 7.5% 5% 6% 10%
ENTERPRISE NETWORK (# of issues called out)
June May Trend
CORE FW/DMZ CORE FW/DMZ
1 0 1 0
US & INTL (# of issues called out)
June May Trend
US Intl US Intl
2 3 2 3
LINE OF BUSINESS BELL WAN MPLS
<> 50%-65% >65% <> 50%-65% >65% Trend
Retail: 2269 4 0 2271 2 0
Business Banking: 60 0 0 51 1 0
Wealth: 121 2 1 111 3 2
Corporate: 49 2 0 51 1 1
Remote ATM: 280 0 0 279 0 0
TOOLS
Version Currency Vulnerability Status Health Status
Key Messages:
Only the text of the table cells is being displayed. There is no table layout, no background colours, etc. Even when I copy the file into JSFiddle it displays like this. What am I missing to make this a complete HTML page?
There's probably a css file linked into the original html not being read in your downloaded page.
How can i access scanner details (eg. HP LaserJet 3055 ) in windows service (.net framework 4.0).by using mib tree ?
Anyone please tell me the OID for getting detail such as scanner_ADF_PageCount,TotalPagesJammed,etc for scanner.
I compare each oid with "1.3.6.1.4.1.11.2.3.9.4.2.1.2.2". But still it is not giving above detail.
1) scanner-accessory-adf-sheet-count - .1.3.6.1.4.1.11.2.3.9.4.2.1.2.2.1.20.0
2) hrprinterdetectederrorstate - .1.3.6.1.2.1.25.3.5.1.2 . It returns an octet string and you need to interpret it as
Condition Bit # hrDeviceStatus
lowPaper 0 warning(3)
noPaper 1 down(5)
lowToner 2 warning(3)
noToner 3 down(5)
doorOpen 4 down(5)
jammed 5 down(5)
offline 6 down(5)
serviceRequested 7 warning(3)
I got this information from HP-LASERJET-COMMON-MIB and you can download it from here. Browse through it for more details.
My router supports telnet sessions to configure my router, I want to make an application in c# that parses the console output into something useful.
edit: the lines are seperated with "\n\r" and there are no \t characters used, everything is spaced out
Example:
bridge configuration for "bridge" :
OBC : dest : Internal
Connection State: connected Retry: 10
Priority Tagging: Disabled
Port: OBC PortNr: 0 PortState: forwarding Interface: up
Multicast filter: disabled Dynamic VLAN : disabled
IGMP snooping : enabled
VLAN: Default VLAN: default Ingressfiltering: disabled Acceptvlanonly: disabled
VLAN: Priority: disabled IP Prec: disabled Priority: 0 Regeneration table: 0 1 2 3 4 5 6 7
RX bytes: 1978767922 frames: 21288686
TX bytes: 481256491 frames: 16224065 dropframes: 13671
ethport1 : dest : ethif1
Connection State: connected Retry: 10
Priority Tagging: NA (destination switch interface)
Port: ethport1 PortNr: 1 PortState: forwarding Interface: up
Multicast filter: disabled Dynamic VLAN : disabled
IGMP snooping : enabled
VLAN: Default VLAN: default Ingressfiltering: disabled Acceptvlanonly: disabled
VLAN: Priority: disabled IP Prec: disabled Priority: 0 Regeneration table: 0 1 2 3 4 5 6 7
RX bytes: 44045 frames: 0
TX bytes: 12618 frames: 0 dropframes: 0
Can somebody give me some hints?
My first thought was a regex, but I don't know how to do that on this scale.
"Into something useful" means to me that your first step is to create classes, structs, and enums that represent your data:
public class RouterEntry
{
public ConnectionState ConnectionState { get; }
public int Retry { get; }
...
public long BytesTX { get; }
}
Then, start thinking about how to parse the result strings. I would probably write a Deserialize(StringReader) method (or something along those lines) so that your object parses the data line by line.
You can also use string.Split with the SplitOptions overload to help you ignore any blank spaces.
So for example, if you use
Port: OBC PortNr: 0 PortState: forwarding Interface: up
as your input line, and
char[] delims = new char[] { ':', ' ' };
as your delimiters, then calling it like this
string[] tokens = line.Split(delims, StringSplitOptions.RemoveEmptyEntries);
would result in tokens containing
[Port, OBC, PortNr, 0, PortState, forwarding, Interface, up]
For the lines that have multiple "values" for a key (such as Regeneration table: 0 1 2 3... you'll just to take into account the fact that each of those values will be a separate string in the tokens array).
The key is that if you break your problem down one bit a time, it should become more manageable to solve.