A simple method of posting JSON data using the window.fetch() method and receiving a response. In this scenario it was an empty response set but with a status indicator, such as an integer 204 indicating that the API accepted was posted.
A Tuple is great way to pass multiple values from a method, for example…
C#
private Tuple<string,int,bool>getStatus(){string element1 ="";string element2 ="";bool isActive =false;... // Some processing to populate the variablesreturnTuple.Create(element1,element2,isActive);{
The returned Tuple can be captured and its contents used as below;
C#
Tuple<string,string,bool> returnedData =getStatus();if(returnedData.Item3)// display message boxes if true{MessageBox.Show(returnedData.item1);MessageBox.Show(returnedData.item2);}
This very simple example shows how to return a Tuple containing three values, but the elements of a Tuple are not just limited to strings, int’s and booleans. The opportunities are there to get as creative as you need.
There is a limit, however, of up to 8 Tuples within a Tuple (an octuple). The Microsoft reference page for further reading is here: Tuple Class (System)
Language: C# IDE: Visual Studio 2022 Summary: TCP/IP Client, RAW Printing
Sounds dramatic, but app does ‘intercept’ print jobs, converts them into a custom ZPL format and then relays to a designated printer.
Background: A third party software supplier used their own template designer tool to send barcoded labels to Zebra printers It was claimed the print jobs would be ZPL which they technically were, but but in a really poor way.
What it ultimately lead to is the Zebra printer driver rasterizing a barcode into an image. The tool seemingly used a font barcode (guessing 3of9), rather than properly utilising ZPL code to allow the print driver to use code 128 for a more compressed barcode. The resulting oversized barcode (as they were quite long) went off the end of the label and was virtually impossible to change in the tool, rendering the labels useless.
Requirement: Intercept print jobs from the third party system, extract the required data and format into genuine ZPL to be sent to the destination printer.
TCPListener and loops
The app listened for TCP messages using a TcpListener shown below. This was mimicking a printer, so the handshaking was different to the normal ENQ > ACK setup.
C#
// Create a ListenerTcpListener server =new TcpListener(IPAddress.Any,port);// Start Listeningserver.Start();// Accept a connection, when one is madeclient=server.AcceptTcpClient();// Do this while the connection is open..while(client.Connected){... // Logic of what to do when a connection is made}
Within the while loop shown above, a NetworkStream was created to collect any bytes sent to the listening port (see below).
C#
// Create a streamNetworkStream stream =client.GetStream();int i;// Read the intial streami=stream.Read(bytes,0,bytes.Length);while(i!=-1){... // Logic of what to do when data is received}
These two loops combined created the backbone of a never ending process of receiving data (the original print message), processing it, sending to the printer, then listening for the next set of data.
Printing
As mentioned, once the relevant bits of data had been extracted from the message, it was put together within newly formatted ZPL code and sent to the printer. The code itself was just a text file with placeholders that were replaced by loading the data and then replacing like this;
C#
// Read the lbl file into a variableZebraCode=File.ReadAllText("labels\\batchproduct.lbl");// Replace the placeholders with variables we extracted earlierZebraCode=ZebraCode.Replace("{barcode}",barcode);ZebraCode=ZebraCode.Replace("{hrbarcode}",hrBarcode);ZebraCode=ZebraCode.Replace("{product}",productName);
The resulting ZebraCode variable was then sent to the printer using the following line of code;
Note: Using ZPL code requires the ability to send RAW print commands to the printer. This was achieved by using the details found on this link here. Many thanks to whoever originally wrote this code, currently unknown, as the link contained within the original question on this request no longer works đ
Customisation Without Reprogramming
The app was made fairly maintenance free, by the labels being editable in a notepad application and the all important settings that were required to operate the app were all loaded on startup from a settings file.
This included the designated printer (identified by name), port that was the be listened to, the format of the label (there were only two options either 0 or 1) and the separator used by the incoming ZPL code. It could have done further by adding the label template locations to the settings file too, but maybe that’s for a further release…
Making up for the inadequacies of antiquated systems is something of a core part of my role. Thankfully we have a replacement centralised system in the pipeline so this kind of work might become less frequent in the future, I hope.
The current problem to hit my desk is a case of missing fields from HL7 messages. The previous receiving system didn’t seem to mind and had not been sent this segment for several years, yet everything worked fine. The new system, however, really has an issue with it.
In time-honoured fashion, it now falls to the old dog to learn new tricks – meaning the new system cannot be changed (or rather the supplier, who shall remain nameless, is so large it isn’t prepared for provide development time to fix the issue for just one customer), so the old system which has remained unaltered for around 15 years, must be changed instead.
This work requires some integration tasks, storage of data to reference and manipulation of HL7 messages on the fly. It should be fun if nothing else and a good opportunity to work with the TIE and it’s developer.
Kick-off meeting is in a few days time. Hopefully my sketched ideas should do the job.
One of the many project management techniques explored as part of my Software Engineering module was Agile – an âiterative & incrementalâ technique specifically designed to speed up the process of software development and deployment – to ensure value is delivered to customers and users as soon as possible.
One important point to understand is the difference between Agile (big A) and agile (little a).
The thoughts are that if you just take the Agile methodology and try to implement it rigidly, it will not always lead to a more efficient development process. In fact, it could result in a poorer efficiency or implementation process overall.
While the Agile methodology is far better suited to the task of software development than other methods, like PRINCE2, itâs still best if an agile approach is used. This means keeping an open minded approach, not feeling the process should be stuck to rigidly.
The Agile principles, written by the founders of the Agile movement are here: https://agilemanifesto.org
Today is the first blank page of a 365-page book. Write a good one.
Brad Paisley
First post of the new year for 2024, with a resolution to make these more regular. If youâre reading this site mid-2024 and the posts stopped – I failed – please ensure to give me a kick!
With the 1st of Jan being a Monday, it falls perfectly for me to take the on-call duties, fingers crossed for a system free of faults this week.
When storing passwords itâs important to ensure they’re not stored in plain text – this goes without saying these days, but there are still some systems that do this. Some hashing options such as md5 are easy to use, but is not recommended for use in any systems these days. The reason for this is that computing power has significantly improved since md5 was first introduced in 1991, which means brute force attacks are likely to succeed with ease.
The stock options when using PHP, however, keeps the hashing fairly simple, with the code below showing how to hash a password string.
An analyser kept loosing its connectivity to a server and it was not known why. One theory was the analyser (a Windows 10 device, heavily locked down to the point we couldn’t access the desktop) was performing some sort of power saving on the NIC after a period of inactivity.
Background: Once the analyser established a TCP/IP connection with the server, it kept the connection open, rather than an open->communicate->close process. This is seemingly a fairly fragile way to maintain communications especially when there are periods of non-communication (sometimes hours overnight) and the system didn’t perform any validation of an open connection before trying to send anything, which resulted in lots of error messages.
In order to rule out the power saving NIC issue I created a simple batch file script that pinged the analysers NIC every 60 seconds. This is a somewhat crude, yet simple way to keep the NIC from turning off as it shouldn’t have periods of idleness longer than 60 seconds.
As the script was going to be left running overnight, it was important to be able to monitor its progress, so additional lines were added to output the ping response to a text file that could be reviewed in the morning.
In the end, the issue was a firewall issue, but the script did help to rule out the analyser as the part of the equasion that was causing the problem.