Com Port with mscomm32.ocx

frytachfrytach Member Posts: 8
edited 2010-02-04 in NAV Tips & Tricks
Need help with reading data (Barcodescanner) from a com port. I'm using the mscomm32.ocx. (Navision 370)

Example:
//init
MSComm.CommPort(4); //COM4
MSComm.Settings('9600,N,8,1'); //Parameter
MSComm.InputLen(0); //Sofort senden
MSComm.InBufferCount(0); //Init
MSComm.InputMode(0); //Textmode
MSComm.PortOpen(TRUE); //öffnen

//Read????
Result := MSComm.Input();

Doesn't work.
I tried the nfcomm.ocx before. Doesn't work either.
I have no experience with com port programming an would be thankful for any help (hints or examples).

The barcodescanner is working fine. No problems with hyperterminal.

Comments

  • kinekine Member Posts: 12,562
    I never used this way of communication with Barcode scanner. I created own external application, which take the data send from COM port and send them as keystroke to system. Or it work as Automation, which can read the data from scanner and signal that new data arrived is passed to NAV through sending one hotkey and catching that hotkey through menuitem with hotkey in NAV (I had no time to create working event in the automation).

    It means that primary function of the aplication is to use COM scanner as Keyboard scanner...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • frytachfrytach Member Posts: 8
    Hi, maybe it's possible to run in a loop and wait for an result of the scanner with a timeout or a max loop counter. But my try wasn't successful.

    Has someone written an OCX or Automation for this case. Or is there any existing codeexample for the nfcomm.ocx? My try with nfcomm.ocx looks like this:

    //init
    CLEAR(ComPort);
    ComPort.ComX := 3; //com4
    ComPort.BaudRate := 6; //9600bps;
    ComPort.Parity := 0; //None
    ComPort.DataBits := 4; //8 databits
    ComPort.DtrDsr := FALSE;
    ComPort.RtsCts := FALSE;
    ComPort.XonXoff := FALSE;
    ComPort.StopBits := 0; //1 Stopbit
    ComPort.SaveParam;

    Result := ComPort.ReceiveStr;
  • Revolution1210Revolution1210 Member Posts: 161
    As we can't use an event driven method using the mscomm32 directly, the next best thing is to use the Navision Timer automation controller (with events) and poll the InBufferCount

    In terms of initializing the mscomm32 control, you should be ok to leave most properties at their default values.

    However, you may find you need to play about with the following in order to get it working with your particular device/scenario:

    .InBufferSize
    .OutBufferSize
    .Settings

    I found the following settings worked in my particular case:
    CommCtrl.InBufferSize := 1024;
    CommCtrl.OutBufferSize := 512;
    CommCtrl.Settings = '9600,n,8,1';
    

    Open the COM port to communication:
    CommCtrl.CommPort := 1;
    CommCtrl.RThreshold := 1;
    CommCtrl.InputLen := 1;
    CommCtrl.PortOpen := TRUE;
    

    The code within the Timer event may look something like this
    IF CommCtrl.InBufferCount > 0 THEN BEGIN
    
      CommCtrl.RThreshold := 0; // Switch off receive event
    
      Buffer := CommCtrl.Input; 
    
    END;
    
    CommCtrl.RThreshold := 1;  // Switch on receive event
    
    Ian

    www.NextEqualZero.com
    A technical eye on Dynamics NAV
  • frytachfrytach Member Posts: 8
    =D> Super, so funktioniert es. Danke
  • krikikriki Member, Moderator Posts: 9,094
    [Topic moved from 'NAV/Navision' forum to 'NAV Tips & Tricks' forum]
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • AdainAdain Member Posts: 1
    Thanks very much for that great entry.
Sign In or Register to comment.