Highlighted
Absent Member.
Absent Member.
496 views

[archive] Mscomm32

[Migrated content. Thread originally posted on 01 August 2005]

Urgent...

Can anyone send me an example of coding a com-port. I want to be able to catch the weight of a weigh scale.

For the moment, I'm testing with a scanner but that must be the same I guess.

If I send data from the scanner to the com-port, I notice there is data to be received, but I'm stuck in what to do for reading that data.


      *
       OPEN-COMPOORT-Clicked.
           PERFORM OPEN-POORT00 THRU OPEN-POORT99.
       OPEN-POORT00.
           MODIFY MSCOM, @RThreshold = 1.
     
           MODIFY MSCOM, @InputLen = 1.
     
           INITIALIZE SA-STRING.
           STRING WBAUDRATE           DELIMITED BY SPACES
                  ","                 DELIMITED BY SIZE
                  "N"                 DELIMITED BY SIZE
                  ","                 DELIMITED BY SIZE
                  "8"                 DELIMITED BY SIZE
                  ","                 DELIMITED BY SIZE
                  "1"                 DELIMITED BY SIZE
                  INTO SA-STRING
           END-STRING.
     
           INSPECT SA-STRING REPLACING TRAILING SPACES BY LOW-VALUES.
           MODIFY MSCOM, @Settings = SA-STRING.
     
           MODIFY MSCOM, @CommPort = COMPOORT-IDX.
           MODIFY MSCOM, @PortOpen = "True".
       OPEN-POORT99.
      *
           
      *
       MSCOM-Ev-OnComm.
           PERFORM RECEIVE00 THRU RECEIVE99.
       RECEIVE00.
           DISPLAY MESSAGE BOX "Trying to receive data - one moment..."
           INQUIRE MSCOM, @InBufferCount IN WCHAR-IN-BUFFER.
           DISPLAY CHAR-IN-BUFFER-EF.
           INQUIRE MSCOM, @Input IN HANDLE-OF-INPUT-STRING.
           CALL "C$GETVARIANT" USING HANDLE-OF-INPUT-STRING,
                                     INPUT-STRING.
           DISPLAY INPUT-EF.
       RECEIVE99.
      *
0 Likes
3 Replies
Highlighted
Absent Member.
Absent Member.

RE: [archive] Mscomm32

Do not display message box, that will freeze all of your cobol app. Use an accept statement that excepts on events.

Also, even though mscomm32 is an "invisible" component, it must be created with a display statement.

Don't use C$Getvariant, the runtime deals with any conversion required, just put it to a cobol var directly.

Here is a vb example from Microsoft website on how to use the control:

PUBLIC ComForm
   ComForm = CREATEOBJECT('Form')
   ComForm.AddObject("Testcom","Olecontrol","MSCOMMLib.MSComm")
   ComForm.Testcom.CommPort = 2 && Use Comm2, The second Serial Port.
   ComForm.Testcom.Settings = "14400,N,8,1"  && 14.4 Kbaud, No Parity,
                                             && 8 data Bits, 1 Stop Bit
   ComForm.Testcom.PortOpen = .T.
   ComForm.Testcom.Output = "ATDT555-1234" + chr(13) && Dialing the number
   * The chr(13) is needed to complete the modem command sequence
   ComForm.Testcom.PortOpen = .F.

With ACUCOBOL-GT it should be something along the line of:

PROCEDURE DIVISION
   DISPLAY MSCOMM handle in TestCom
                 EVENT PROCEDURE CommEvents.
  Modify TestCom CommPort = 2 | COM2.
  Modify TestCom Settings = "14400,N,8,1".
  Modify TestCom PortOpen = 1.
  ACCEPT OMITTED UNTIL EXIT-SET | Make a loop terminate it from within your even procedure

...
CommEvents.
    | Check your events here
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Mscomm32

Txs Gisle, but this doesn't bring me any further.

ACCEPT OMITTED .... ?

What do I have to accept until exit-set ?
Do you mean by exit-set : until EOF is sent ?
Isn't it possible to send a complete example ?
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Mscomm32

To process events, you must have an accept statement running, that is why the accept statement. It is not complete, you have to embedd the processing of the event as well, as such allow the ACCEPT statement to except when the communications control is finished, as you point out.

I am sorry, but I don't have the time to make a full example for you, may be some time, but not today.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.