Jump to content

MSCOMM inBufferCount issue


Recommended Posts

Hello. I'm wondering whether there is an easy answer to why the following only partly works.

$MsComm = ObjCreate("MSCOMMLib.MsComm.1")
$MsComm.CommPort = 1
$MsComm.Settings = "9600,N,8,1"
$MsComm.Handshaking = 0
$MsComm.InBufferSize = 1024
$MsComm.InputLen = 1
$MsComm.PortOpen = 1

While 1
    MsgBox(0,"Testing",_MsgIn())
    Sleep(2000)
WEnd
Func _MsgOut($str)
    $MsComm.OutBufferCount = 0
    $MsComm.InBufferCount = 0
    If $MsComm.PortOpen = True Then
        $MsComm.Output = $str
    EndIf
    $MsComm.InputLen = 0
EndFunc
Func _MsgIn()
    $TIMEOUT = 1000 ;1000
    $nTimeCtr = 0
    $sBuffer = ""
    Do
    $nTimeCtr += 1
    If $MsComm.InBufferCount > 0 Then
         $sBuffer = $sBuffer & $MsComm.Input
        EndIf
        Sleep(500)
    Until StringInStr($sBuffer,@CR) OR $nTimeCtr > $TIMEOUT
    If $nTimeCtr < $TIMEOUT Then
        $nI = StringInStr($sBuffer,@CR)
        Return StringLeft($sBuffer,$nI)
    Else
        Return "Error"
    EndIf
EndFunc

SORRY, THIS WILL BE IN CAPS AS IPHONE HAS THROWN A WOBBLY TOO!

FROM A WIN 7 PC, THIS LARGELY 'BORROWED' CODE (THANKS BY THE WAY) DOESN'T QUITE WORK. HAVING GOT AROUND MANY OBSTACLES, I CAN RUN THIS BUT IT FALLS OVER AT THE POINT WHERE THE INBUFFERCOUNT IS TESTED FOR > 0. IT NEVER BECOMES GREATER. I SAW MENTION OF USING A NULL CABLE BUT THIS WAS WRITTEN WITH 2 COM PORTS AVAILABLE WHICH I DON'T HAVE. I HAVE TRIED THE ALTERNATIVE NETCOMM... WRAPPED ACTIVEX BUT HAD THE SAME OUTCOME. THE AUTHOR (OF NETCOMM) SPECIFICALLY STATED THAT IN WIN 7 IT NEEDED ADMIN RIGHTS - THOUGH HE DIDN'T KNOW OF AUTOIT. I HAVE TO SAY THAT IN WIN 7, MY USUAL APPROACH IS TO RUN WITH ADMIN RIGHTS (AND FAST!).

IF ANYONE HAS A CLUE I'D BE V GRATEFUL.

MANY THANKS.

NB MY 'REAL' AIM IS TO FEED ASCII COMING INTO COM 1 FROM A DEVICE TO MY OWN AUTOIT WINDOW AND EVENTUALLY EXCEL 2000.

Link to comment
Share on other sites

Seems you borrowed the code from this So maybe the might be useful and help you with your problem.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Seems you borrowed the code from this So maybe the might be useful and help you with your problem.

Water I chose to start a new thread because the 'doner' thread seemed to have become diluted and I needed to clear the blackboard. Thanks for the alternative UDF idea but I have a problem here too again and that thread is unfortunately quite old to add to.

If you have experience in this subject in relation to Win 7 I'd be grateful for your input. Specifically (with your UDF idea) I get a vilolation of the array boundary after completing "stage 2" as written to the console in the latest example included in the thread. Actually I think this is simply that the array isn't an array i.e. the instantiation did not occur properly at all because of some earlier issue. My difficulty is that I don't know much about Com ports (though I wrote my own code in C years ago - long forgotten and probably doesn't travel well to here). My quest goes on but I feel that in order for me to progress I have to have some success to build on and I don't feel I've reached that point.

I'm all ears for any ideas - thanks a lot.

Link to comment
Share on other sites

Hi 2Tricky,

unfortunately I can't help you with this subject.

When I read your post I just remembered that there was an UDF for this kind of task.

But I think the UDF thread is quite active because the author (martin) just answered a few days ago. Maybe you can post the questions you have regarding the UDF there and I'm quite sure you'll get some answers.

Good luck!

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...