Ferraz Outstanding Contributor.
Outstanding Contributor.
939 views

Send a tcp request to a identification document scanner

Hi,

I have to communicate with an ID document scanner to get the data that will be read by it. I have to send a request with certain parameters and receive the data through an xml file.

The parameters to send are the ones below

Send Request Parameters.jpg

I have an example in C # and, according to the debug I did, it seems to me that the instructions for the request are these:

System.Threading.Thread workingThread = new Thread(ScanWork);
workingThread.Start(parameters);

I still can not figure out how I get the answer but I'll try to figure it out.

In the meantime I ask for your help once more.

Best regards,

Alberto Ferraz

0 Likes
13 Replies
Micro Focus Expert
Micro Focus Expert

Re: Send a tcp request to a identification document scanner

The code you quote just runs a method named "ScanWork" in a separate thread. We have no way of knowing what that method does. What is your question?
0 Likes
Ferraz Outstanding Contributor.
Outstanding Contributor.

Re: Send a tcp request to a identification document scanner

Hi Michael,

The method "Scanwork" is below (the parameters.TCP are TCP)

/// <summary>
/// Method is processing request based on parameters.
/// </summary>
/// <param name="o">Parameters from the input form.</param>
public static void ScanWork(object o)
{
//Thread can only have object as parameter so we need to cast it to our class
if (!(o is ASInterfaceIntegration.DataManipulation.Parameters)) return;
ASInterfaceIntegration.DataManipulation.Parameters parameters = o as ASInterfaceIntegration.DataManipulation.Parameters;

if (parameters.TCP) // TCP request sent
{
DoWork.ScanTCP(parameters.RequestXml, parameters.Hostname, parameters.Port, parameters.AdditionalPort);
}
else // HTTP request sent
{
if (parameters.EnableJson) // JSON
{
// callback can contain any value
DoWork.ScanHTTP("callback=Test", parameters.TargetURL, parameters.Action, true);
}
else // XML
{
DoWork.ScanHTTP(parameters.RequestXml, parameters.TargetURL, parameters.Action, false);
}
}
}

My question is how do I do it?

Thanks

0 Likes
Micro Focus Expert
Micro Focus Expert

Re: Send a tcp request to a identification document scanner

Again, the most relevant code is not in this method, but in methods it invokes, which we can't see. (And pasting more source into posts would not be a very good way to show us.) The easiest way to accomplish what you want might simply be to build your sample C# code into an assembly with a suitable public interface, then invoke that from your COBOL code. Do you actually need it rewritten in COBOL?
0 Likes
Ferraz Outstanding Contributor.
Outstanding Contributor.

Re: Send a tcp request to a identification document scanner

Hi,

The C # code I have is from a demo application that the vendor the scanner has sent me. The demonstration is great because it also includes the screens of parameterization, selection, etc.

With the debug I made I "got" the instructions that are used to make the request but, as it refers, it is difficult to catch all the methods. The idea of ​​rewriting in cobol is because I have to integrate this process into an application.

In terms of the manual I do not have much information either. I have only the request data and the information layout to receive.

I'll try to see the vendor if I get a simpler program that has just the part that matters.

Best regards

Alberto Ferraz

 

0 Likes
Micro Focus Expert
Micro Focus Expert

Re: Send a tcp request to a identification document scanner

If the vendor doesn't have a simpler example, could you attach the C# file with the relevant code to a post? That would be easier to work with than code pasted into the body of a post.
0 Likes
Highlighted
Ferraz Outstanding Contributor.
Outstanding Contributor.

Re: Send a tcp request to a identification document scanner

Hi again,
While I have no response from the vendor attached attachment the program in C # which, I believe, has the main part of the code needed.

The required parameters are:

- RequestXml - XML ​​file that I send attached too

- Hostname - "127.0.0.1"

- Port - "56702"

- AdditionalPort - "0"

 

The other programs are to "build" the xml that is sent in the request and to set the necessary parameters.

I do not know if I can do something with what I send.

Thanks again.

Best regards,

Alberto Ferraz

0 Likes
Micro Focus Expert
Micro Focus Expert

Re: Send a tcp request to a identification document scanner

Well, there are some 600 lines of C# code there (and not particularly good code at that, in my humble opinion). When I have time I'll see about translating the relevant parts to managed COBOL, but I'm afraid that at the moment I have more pressing tasks that need my attention. I may be able to get to it later today, but it might have to wait for the weekend.
0 Likes
Ferraz Outstanding Contributor.
Outstanding Contributor.

Re: Send a tcp request to a identification document scanner

Hi,

I believe that it is not easy to translate that because, as he says, there are many lines and options. Still, there are priority issues.

Anyway, I'm checking to see if the supplier sends me what I asked for.

If you happen to be able to look at the situation, thank you.

Best regards,

Alberto Ferraz

0 Likes
Ferraz Outstanding Contributor.
Outstanding Contributor.

Re: Send a tcp request to a identification document scanner

Hi,

I received from the supplier this comment on what needs to be done.

I do not know if it simplifies the question.

1º - Open the TCP port locally on the computer (127.0.0.1)

2º - Send the request to port 56702 (file request_default.xml atached)

3º - Door is always open

4º - The scanner work and create the response xml file

5º - The XML result is returned in the same channel that is still open - file response_default.xml 

6º - To finish, after sending the XML, the channel is closed

 

Best regards,

Alberto Ferraz

 

0 Likes
Ferraz Outstanding Contributor.
Outstanding Contributor.

Re: Send a tcp request to a identification document scanner

Hi again,

I received from the vendor a smaller source and only with the instructions that need to be used.

I believe that with this simpler source it will be possible to analyze and "convert" to Cobol.

Attach the zip with the source (BasicTCP.zip).

I also attached a zip.file with the scanner emulator (FakeReader.zip). It is an application that is installed and to which the program will fetch the data.

I am waiting for your help again.

Best Regards

Alberto Ferraz

0 Likes
Micro Focus Expert
Micro Focus Expert

Re: Send a tcp request to a identification document scanner

Attached is a zip file containing the COBOL version of the BasicTcp project.
It compiles OK but I cannot test it here so you are on your own with that.

 

0 Likes
Ferraz Outstanding Contributor.
Outstanding Contributor.

Re: Send a tcp request to a identification document scanner

Good morning, Chris.

Thank you for the example you sent me and it is working perfectly. I've done the tests and the results are as expected.

Now I have only one situation of error here.

What happens is the following:

- I integrated FORM1 into my project which is in WPF;

- When I compile gives me three errors (two have to do with each other) - see attachment;

- The first one says that there is no member "DoEvents";

- The second has to do with the class "IMAGE".

I do not know if it has to do with FORM1 being in Windows Forms and my project being in WPF.

 

I ask once more for help.

 

Best regards,

Alberto Ferraz

0 Likes
Ferraz Outstanding Contributor.
Outstanding Contributor.

Re: Send a tcp request to a identification document scanner

Hi Chris,

I have managed to solve the errors that I sent in the previous post.

The first one replaced the "invoke type Application :: DoEvents" statement with "invoke type System.Windows.Forms.Application :: DoEvents".

The following error did the same: I replaced the "Image" variable with "System.Drawing.Image".

I was unable to convert the code to WPF because of the DOEVENTS statement. Apparently it does not exist with this format.

I will integrate windows.forms into my application and it will be solved.

Thanks again for the great help.

Best regards,

Alberto Ferraz

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.