Andy Fong
Andy Fong

Reputation: 428

Image Transmit to Intermec PM4i printer and then Print

I'm using Fingerprint to upload and then print image with pcx format.

Step1 Upload image to printer using TCP port, I use command :

IMAGE LOAD "bigfoot.1",1746,""\r\n

The printer returns with message "OK". And then I send bytes data of bigfoot.1 to printer using socket.

Step 2 Print the image "bigfoot.1":

PRPOS 200,200
DIR 3
ALIGN 5
PRIMAGE "bigfoot.1"
PRINTFEED
RUN

The problem comes, the printer returns with message "Image not found". So I come up with the possibility of failure of upload. So I open the software PrintSet4 to check the image, the image already exists in TMP.Odd!!! At last, I used PrintSet4 to substitute my socket application to upload image, After add file and apply, I use the step2 print command to print image, It works fine! Here is the C# code to upload Image:

public void SendFile(string filePath, string CR_LF)
{
    FileInfo fi = new FileInfo(filePath);
    using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
    {
        byte[] byteFile = new byte[fs.Length];
        string cmd = "IMAGE LOAD \"" + fi.Name + "\"," + byteFile.Length.ToString() + ",\" \"" + CR_LF;
        ClientSocket.Send(encode.GetBytes(cmd));
        fs.Read(byteFile, 0, byteFile.Length);
        Thread.Sleep(1000);
        ClientSocket.Send(byteFile);
    }
}

Upvotes: 0

Views: 2450

Answers (1)

ChankieChanc
ChankieChanc

Reputation: 1

I have modified your code and used serial port.

public void SendFile(string filePath)
{
    SerialPort port = new SerialPort("COM3", 38400, Parity.None, 8, StopBits.One);
    port.Open();
    FileInfo fi = new FileInfo(filePath);
    using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
    {
        byte[] byteFile = new byte[fs.Length];
        // string cmd = "IMAGE LOAD \"" + fi.Name + "\"," + teFile.Length.ToString()+                     ",\"\"" + CR_LF;
        string cmd = "IMAGE LOAD " + "\"" + fi.Name + "\"" + "," + byteFile.Length.ToString() + "," + "\"S\"";

        port.WriteLine(cmd);
        fs.Read(byteFile, 0, byteFile.Length);
        port.Write(byteFile,0,byteFile.Count());
        int count = byteFile.Count();
        int length = byteFile.Length;
    }
}

So I noticed the problem was using CR_LF. Instead, I used port.WriteLine(cmd), which acts the same as adding a line separator. And it worked fine.

Upvotes: 0

Related Questions