Navision/MsComm32 Integration

JackEohJackEoh Member Posts: 5
I need help communicating with a serial device using MsComm32.ocx
MsCom.InBufferSize := 1024;
MsCom.OutBufferSize := 512;
MsCom.Settings('9600,n,8,1');
MsCom.CommPort:=8;
MsCom.PortOpen(TRUE);

MsCom.RThreshold := 1;  
TimeOutCount := 100;
REPEAT 
SLEEP (1000);
TimeOutCount -= 1;
UNTIL (MsCom.InBufferCount >= 1) OR (TimeOutCount <= 0);

That is what I currently have to trigger the rest of the code. However, it does not seem to register the input at the moment.

The device in question is a PSC handheld Scanner. The scanner functionality sends a string through the serial port, and awaits a response (another string) then passes yet another string back containing the data.
Any help/tips/advice at all would be greatly appreciated!

Edit: The problem was with the setup of the comport. Because the device was using an RS232 port, a COM port could not just be opened. As we have created a solution through VB, I don't know the specifics, but there are a series of settings that use GUID's to set the COM port before it can be interfaced. This, apparently, would be possible in NAV.

Answers

  • kinekine Member Posts: 12,562
    For me it is easier to create own application in Visual Studio using the standard Serial port component. You can create small application which will change your scanner into "Keyboard" scanner. It means it just read the data from scanner and using SendKeys function will send them into active application. For this base functionality you need just few lines of code...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • 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
  • JackEohJackEoh Member Posts: 5
    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
    


    Thank you very much for the response
    However, I had already searched the forums and read that response, it's the InBufferCount I'm having issues with. It doesn't seem to be triggered when the handheld sends an output
  • kinekine Member Posts: 12,562
    Try to configure the scanner to send Enter character after the barcode. You can configure the scanner through special barcodes from the manual.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • JackEohJackEoh Member Posts: 5
    kine wrote:
    Try to configure the scanner to send Enter character after the barcode. You can configure the scanner through special barcodes from the manual.

    The scanner is using a different companys software, which we can't get access too. Therefore it cannot be modified. However, NAV doesn't seem to pick up any data from it at all. I do currently have a colleague writing an interface for it in VB, but it would be nice if I knew where I was going wrong really!
  • ta5ta5 Member Posts: 1,164
    Maybe a stupid question, but:
    Why not configure the scanner in order to send scanned data to the keyboard buffer? This way, the scanner works exactly as when the data would have been entered by keyboards.
    Regards
    Thomas
  • JackEohJackEoh Member Posts: 5
    ta5 wrote:
    Maybe a stupid question, but:
    Why not configure the scanner in order to send scanned data to the keyboard buffer? This way, the scanner works exactly as when the data would have been entered by keyboards.
    Regards
    Thomas

    It would be ideal, but I have to work with the current handheld spec, can't modify the handheld software!
Sign In or Register to comment.