What are you looking for?
HP PCL Hewlett-Packard graphics language
PCL is a common standard for sending data to printers. PCL commands are compact escape sequence codes that are embedded in a print job data stream. The commands always begin with an ASCII escape character (ASCII char '27', hexadecimal '1B'). These commands control printer functions like the carriage position and form feed, and also set up the printer to handle incoming text or image data. Some PCL commands associated with raster (image) data are the following:
Chr(27) & "*r1A" ' Start raster graphics Chr(27) & "*b1M" ' Set unencoded compression mode Chr(27) & "*b80W" ' Raster data header - 80 pixels of data in row Chr(27) & "*b2m8W" ' TIFF compression mode, next 8 bytes describe row Chr(27) & "*rbC" ' End raster graphics
Some of these commands are valid only after the 'Start raster graphics' command is received, while some others are only valid outside raster data mode.
To help you convert PCL to a Picture in a PictureBox an example class, clsPclToBMP, is provided within the example. The PCL example demonstrates the commands and code snippets to extract raster image data from PCL byte data, determine the image height and width, and write the raster data to a PictureBox. Both unencoded PCL raster image data and TIFF (Tagged Image File Format) compression encoding is handled. The example includes several different instruments to demonstrate how to return the binary data from the instrument. Use the Visual Basic object browser for a description of each method and property for the PCL converter. Be sure to use the correct GPIB address to prevent a long timeout or hang-up of the IO interface.
PCL Conversion Class Example
The first example uses the PCL conversion class for an instrument like the Keysight 54645D oscilloscope. This is one of several instruments that supports PCL as an output. Some instruments support both low and high resolution raster images. The Keysight 54645D sends unencoded PCL image data, whereas an Keysight 54622D oscilloscope encodes the data with TIFF compression.
As in the HPGL2 example, the Read method from VISA COM is used to read the data. Since you don't know how many bytes to expect, set the array of bytes larger than needed and set the 'count' of the Read Method to return the same amount. The Read method will fill the array until there is no more data, and then terminate.
Dim InstrAddress As String Dim pclData() As Byte Dim dataSize As Long Dim scope As VisaComLib.FormattedIO488 Dim io_mgr As KeysightRMLib.SRMCls Me.MousePointer = vbHourglass InstrAddress = "GPIB::7"
Set io_mgr = New KeysightRMLib.SRMCls Set scope = New VisaComLib.FormattedIO488 Set scope.IO = io_mgr.Open(InstrAddress) dataSize = 100000 ReDim pclData(dataSize)
scope.WriteString ":PRINT?" scope.IO.Timeout = 50000 pclData() = scope.IO.Read(dataSize) ReDim Preserve pclData(UBound(pclData))
Once the Read Method returns, you must convert the byte data to raster image data and plot the image data. This is a 4-step process using the clsPclToBMP class.
- Declare the clsPclToBMP class, pass it the PCL data and a PictureBox.
- Use the PCLtoRaster method to extract the raster image. This method ignores commands in the PCL data that are not essential for recreating a raster image, fills a raster byte array, and determines the image height and width.
- Decide whether to scale the raster data to fit within the current PictureBox size or use the image size to reset the PictureBox
- Use the fillPictureBox method to draw the data to the PictureBox This method resizes the PictureBox to the proper aspect ratio and makes it as large as possible inside its parent form. It next scans the raster byte data bit by bit and draws dots at the proper x and y location.
These four steps are illustrated below. rasterPBox is a PictureBox control placed on a form.
Set up the PCL converter.
1. Declare the PCL to BMP converter class
Dim myPCLConverter As clsPclToBMP Set myPCLConverter = New clsPclToBMP Set myPCLConverter.PictureBox = rasterPBox myPCLConverter.pclData = pclData()
2. Extract the raster image.
myPCLConverter.PCLtoRaster
3. Scale the image to fit the PictureBox if image is too large.
myPCLConverter.isPBoxScaled = True
4. Draw the data to the PictureBox.
myPCLConverter.fillPictureBox
Limitations of PCL Converter
The clsPCLToBMP class is not a complete implementation of the PCL commands. It was designed to convert PCL from instruments commonly available. PCL commands that are not recognized by the class are ignored. Compression modes attempted other than TIFF will raise a "Compression mode not supported" error.