Receive data from barcode scanner by ethernet (not handheld)

Hello everyone,
this is my first message in the forum.

I need some help... I need to receive data from a barcode scanner by his ethernet port. It's a Datalogic DS2400N.
The scanner reads a barcode every few seconds/minutes and I need Navision to wait for each data...
I've been searching in a lot of barcode post around then forum and I tried to do this with ComCom but there’s no way to receive data.

My code...
OnRun()

IF ISCLEAR(ComCom) THEN
  IF NOT CREATE(ComCom) THEN
    ERROR('Error al crear Comunication Component...');

IF ISCLEAR(SBA) THEN
  IF NOT CREATE(SBA) THEN
    ERROR('Error al crear Socket Bus Adapter...');


ComCom.AddBusAdapter(SBA, 0);

SBA.OpenSocket(51238,'191.0.1.61');   // The ip address/port of the barcode scanner...

// When I run the codeunit I see this message...
MESSAGE('Socket abierto 191.0.1.61:51238');

ComCom::MessageReceived@1(VAR InMessage:Automation "''.IDISPATCH")

  MESSAGE('Mensaje recibido...');

  InMsg:= InMessage;

  inS:= InMsg.GetStream();

  WHILE NOT inS.EOS DO BEGIN
    inS.READ(ltEtiqueta);
    MESSAGE(ltEtiqueta);
  END;

  InMsg.CommitMessage();


I don't know if this is enough or I need to do something else.... I run the codeunit but I don't receive any message when the scanner reads a barcode.
Is ComCom the correct option or do I need another??.... ADCS, Business Notification Server, NAS (actually I use NAS for other things),...

I'm a bit lost... :(
Can someone please help me????

Thanks a lot!!!

Answers

  • AKAK Member Posts: 226
    Don't know anything about ComCom, but the event in the codeunit can only fire as long as the codeunit is runing, so you need a loop inside it. Is this the case? "I run the codeunit" is a bit unclear.
  • MAOFMAOF Member Posts: 4
    Thanks for your answer AK!!

    "I run the codeunit" means I push Run button once and there is no loop inside.
    I thought was enough to execute OnRun code once, because ComCom would be waiting to the event, but it seems I was wrong...

    If I use a loop, the second time I try to open the socket I get an error...

    Can you show me a little bit example???

    Thank you.
  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    edited 2017-11-30
    ComCom::MessageReceived is an event fired by the ComCom2 component. The ComCom2 automation must be loaded into the client memory to be able to fire events.

    Your codeunit simple opens the connections and quits, leaving the connection open (connection is owned by NAV process) but without the actual receiver of your message once codeunit the execution finishes. Next time you try runing your codeunit the port number is already taken by open (and orphaned) connection.

    What you need to do is to mark the codeunit as a Single Instance. Once run it will be kept in client's memory for as long as the client process lives. Each message send remote peer will fire the ComCom::MessageReceived

    Remember that the NAV code is not re-entrant. If a message comes while the code is executed the event might be fired returning control to the ComCom::MessageReceived function leaving the system unstable. This usually ends, sooner or later, with the client crash.

    If you have any means to disable / pause remote peer while received message is processed use it, if not make the event handler short and fast - for example write and commit a single record with received data to a buffer table and leave it to be processed by another client/nas session

    Slawek



    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • MAOFMAOF Member Posts: 4
    Thank you Slawek!!

    What do you mean to load ComCom2 into the client memory? How can I do that...?

    The codeunit is mark as a Single instance.
    The ComCom Automation::'Navision Communication Component version 2'.CommunicationComponent, is mark WithEvents = Yes.
    So I can't understand why it doesn't work...

    I've tried with Hyperterminal and receive the data from de scanner by the ip/port so I don't know what happen.

    Any suggest??
  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    MAOF wrote: »
    What do you mean to load ComCom2 into the client memory? How can I do that...?
    CREATE(ComCom) creates an object instance in memory.

    It needs to be declared as global variable, otherwise it will only exists when the function where it has been declared is executed (even if it is a local var in OnRun trigger).


    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • MAOFMAOF Member Posts: 4
    At the first post you can see my code and the instruction
    CREATE(ComCom)
    
    And Yes, the variable is declare as a global.

    Every minute, the scanner reads four or five labels.... So I can´t understand why this readings doesn't fire the event ComCom::MessageReceived.

    Please help.... I believe I'm very near to get the solve but it must miss some detail...
  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    edited 2017-12-01
    MAOF wrote: »
    At the first post you can see my code and the instruction
    CREATE(ComCom)
    
    My point was that if the codeunit was not marked as Single Instance CREATE(ComCom) does create an instance of ComCom2 object but the instance is destroyed/removed from memory immediately after the execution finishes.

    In your case all looks good.

    Try setting ReceiveTimeout property on SBA components.


    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
Sign In or Register to comment.