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
"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.
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
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
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??
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).
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
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...
In your case all looks good.
Try setting ReceiveTimeout property on SBA components.
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03