Last active
July 31, 2018 07:06
-
-
Save basinilya/16fd6137ca6809268e869ae3ea634890 to your computer and use it in GitHub Desktop.
hub4com mscomm32 problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' Usage: cscript comread.vbs n | |
| ' | |
| ' Unless the proper license is installed, the script will fail to create | |
| ' MSCOMMLib.MSComm with "Class is not licensed for use". | |
| ' | |
| ' The required Design-time license is known to be installed with: | |
| ' - Visual Studio 6 component "ActiveX" | |
| ' - TBD | |
| Option Explicit | |
| Dim ErrNumber | |
| Dim CommPort | |
| Dim MSComm1 | |
| Dim CommSpeed | |
| Dim CommFormat | |
| CommSpeed = "300" | |
| CommFormat = ",E,8,2" | |
| On Error Resume Next | |
| CommPort = WScript.Arguments(0) | |
| ErrNumber = Err.number | |
| On Error GoTo 0 | |
| if ErrNumber <> 0 then | |
| Err.Raise vbObjectError + 10, "comread" , "Usage: cscript comread.vbs n" | |
| end if | |
| On Error Resume Next | |
| const comEvSend = 1 | |
| const comEvReceive = 2 | |
| const comEvCTS = 3 | |
| const comEvDSR = 4 | |
| const comEvCD = 5 | |
| const comEvRing = 6 | |
| const comEvEOF = 7 | |
| const comEventBreak = 1001 | |
| const comEventCTSTO = 1002 | |
| const comEventDSRTO = 1003 | |
| const comEventFrame = 1004 | |
| const comEventOverrun = 1006 | |
| const comEventCDTO = 1007 | |
| const comEventRxOver = 1008 | |
| const comEventRxParity = 1009 | |
| const comEventTxFull = 1010 | |
| const comEventDCB = 1011 | |
| const comInputModeText = 0 | |
| const comInputModeBinary = 1 | |
| On Error Goto 0 | |
| sub printconst(name) | |
| WScript.Echo "const " & name & " = " & Eval(name) | |
| end sub | |
| if false then | |
| printconst "comEvSend" | |
| end if | |
| sub MSComm1_OnComm | |
| dim i | |
| dim sCopy | |
| Select Case MSComm1.CommEvent | |
| Case comEventBreak ' A Break was received. | |
| Wscript.Echo "event: " & "comEventBreak" | |
| Case comEventFrame ' Framing Error | |
| Wscript.Echo "event: " & "comEventFrame" | |
| Case comEventOverrun ' Data Lost. | |
| Wscript.Echo "event: " & "comEventOverrun" | |
| Case comEventRxOver ' Receive buffer overflow. | |
| Wscript.Echo "event: " & "comEventRxOver" | |
| Case comEventRxParity ' Parity Error. | |
| Wscript.Echo "event: " & "comEventRxParity" | |
| Case comEventTxFull ' Transmit buffer full. | |
| Wscript.Echo "event: " & "comEventTxFull" | |
| Case comEventDCB ' Unexpected error retrieving DCB] | |
| Wscript.Echo "event: " & "comEventDCB" | |
| Case comEvCTS | |
| Wscript.Echo "event: " & "comEvCTS" | |
| Case comEvReceive ' Received RThreshold # of chars. | |
| Wscript.Echo "event: " & "comEvReceive" | |
| sCopy = MSComm1.Input | |
| For i = 1 to Len(sCopy) | |
| Wscript.Echo Right("0" & Hex(Asc(Mid(sCopy, i, 1))), 2) | |
| Next | |
| Case comEvDSR | |
| Wscript.Echo "event: " & "comEvDSR" | |
| Case comEvCD | |
| Wscript.Echo "event: " & "comEvCD" | |
| Case else | |
| Wscript.Echo "event: " & MSComm1.CommEvent | |
| End Select | |
| end sub | |
| Set MSComm1 = WScript.CreateObject("MSCOMMLib.MSComm", "MSComm1_") | |
| With MSComm1 | |
| .CommPort = CommPort | |
| .Settings = CommSpeed + CommFormat | |
| .RThreshold = 1 ' enables comEvReceive event | |
| .InputLen = 0 | |
| .PortOpen = True | |
| End With | |
| Wscript.Echo "Waiting for events ..." | |
| Do | |
| WScript.Sleep 5 | |
| Loop |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" ?> | |
| <job id="Constants importer"> | |
| <reference object = "MSCOMMLib.MSComm"/> | |
| <script language="VBScript" src="comread.vbs"> | |
| </script> | |
| </job> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment