Options

Send TCP Port a command

awarnawarn Member Posts: 261
edited 2008-03-04 in NAV Tips & Tricks
Hi,

I could not find an answer in the forum so I am hoping someone has come across it before.

I have to send data to a scale through a TCP Port. I will be sending an IP address, port number, and then a command as text.

Has anyone done this before?

I am thinking it should be as simple as decalring some variable, and then two lines of code like:

somevariable.open('192.168.1.15::52200');
somevariable.write('w.261.2' + formaT(weight));


Does anyone know how to open a TCP Port (I hope I am using the terminology proprely) and send this command?

Thanks,

-a

Comments

  • Options
    kinekine Member Posts: 12,562
    Look to the Communication Components for NAV. If you will find file "devguide.chm", you will find this example:
    The Navision Socket Bus Adapter - Sending a Document
    In this example, we use a codeunit to initialize the Navision Communication Component, establish contact to the Navision Socket Bus Adapter, open a socket server for the bus adapter and send the message.

    For the purpose of this example, we have defined the following variables:

    Variable Name
    Data Type
    Subtype
    Length

    CC2
    Automation
    'Navision Communication Component version 2'.CommunicationComponent


    SBA
    Automation
    'Navision Socket Bus Adapter'.SocketBusAdapter


    OutMsg
    Automation
    'Navision Communication Component version 2'.OutMessage


    OutS
    OutStream




    The socket server uses port 8079 on the local machine.

    Example
    OnRun()

    IF ISCLEAR(CC2) THEN
    CREATE(CC2);
    IF ISCLEAR(SBA) THEN
    CREATE(SBA);

    CC2.AddBusAdapter(SBA, 0);
    OutMsg:= CC2.CreateoutMessage('Sockets://localhost:8079');

    OutS:= OutMsg.GetStream();
    OutS.WRITE('First Text');
    OutS.WRITE('Second Text');
    OutS.WRITE('Third Text');

    OutMsg.Send(0);

    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    krikikriki Member, Moderator Posts: 9,096
    [Topic moved from Navision DOS forum to Navision Tips & Tricks forum]
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Options
    awarnawarn Member Posts: 261
    Thanks - but I do not see 'Navision Communication Component version 2' as one of the automation variables available to me.

    Where do I go to add it - is there a dll somewhere I can download?

    Thanks,

    -a
  • Options
    kinekine Member Posts: 12,562
    They are part of NAV Client installation, but are not included in the standard installation type. You need to run NAV install again and add the component "Commerce integration" or how it is named. After that, you will have these components available.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    awarnawarn Member Posts: 261
    Hi,

    Thanks, I just pulled these two dlls from the CD and registered them:
    NSComCom2.dll
    SocketBusAdapter.dll

    Can you verify that the syntax of the IP address would be something like the below?

    I am using 192.168.0.1 & port 52200 as examples, they would end up being parameters. Is the 'Sockets://' text necessary?

    OutMsg := CC2.CreateoutMessage('Sockets://192.168.0.1::52200');

    Thanks for all your help, this is helping me a lot!

    -a
  • Options
    kinekine Member Posts: 12,562
    1) Use just one colon between address and port
    2) The "sockets" is name of used protocol. (like http, ftp, skype etc.). I do not know, if the components supports another protocol than "tcp/ip sockets".
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
Sign In or Register to comment.