Jump to content

Serial Port Foot Switch COM1


ajit
 Share

Recommended Posts

$oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")

Global $com = ObjCreate("NETCommOCX.NETComm")
$com2 = ObjEvent($com, "_NETComEvents_")

Global const $comEvSend = 1 
Global const $comEvReceive = 2
Global const $comEvCTS = 3
Global const $comEvDSR = 4
Global const $comEvCD = 5
Global const $comEvRing = 6
Global const $comEvEOF = 7


With $com
    .CommPort = 1
    .PortOpen = True
    .Settings = "9600,N,8,1"
    .InBufferCount = 0  
    

EndWith


While 1
    Sleep(100)
    $evt = $com.CommEvent()
     Switch $evt
         Case $comEvRing  ; Change in the Ring Indicator.
            MsgBox(0, "", "Ring Line")
        
        Case $comEvCD  ; Change in the CD line.
            MsgBox(0, "", "CD Line")
        
        Case $comEvCTS  ; Change in the CTS line.
            MsgBox(0, "", "CTS Line")
            
        Case $comEvDSR  ; Change in the DSR line.
            MsgBox(0, "", "DSR Line")
               
        Case $comEvReceive  ; Received RThreshold # of chars.
            MsgBox(0, "", "Recieve")
         
        Case $comEvSend  ; There are SThreshold number of characters in the transmit buffer.
            MsgBox(0, "", "Send")
            
        Case $comEvEof  ; An EOF charater was found in the input stream
            MsgBox(0, "", "EOF")
         
    Endswitch
WEnd
Exit

Func MyErrFunc()
; Set @ERROR to 1 and return control to the program following the trapped error
    SetError(1)
    MsgBox(0, "Error", "Error communicating with modem on COM" );& $com.CommPort)
    Exit
EndFunc;==>MyErrFunc

Hi:

I have a foot switch(three pedals) (serial port, COM 1), the output (pin voltage) of which I want to use in my script.

Using the above code, I can read CTS, DSR, and CD line but it does not work the way I would like it to.

I want to read the output from the switch when it is pressed, but the script reads it when I leave the switch after pressing it. It is true for CTS, DSR, and CD lines.

Someone help me please.

Ajit

Edited by ajit
Link to comment
Share on other sites

$oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")

Global $com = ObjCreate("NETCommOCX.NETComm")
$com2 = ObjEvent($com, "_NETComEvents_")

Global const $comEvSend = 1 
Global const $comEvReceive = 2
Global const $comEvCTS = 3
Global const $comEvDSR = 4
Global const $comEvCD = 5
Global const $comEvRing = 6
Global const $comEvEOF = 7


With $com
 .CommPort = 1
 .PortOpen = True
 .Settings = "9600,N,8,1"
 .InBufferCount = 0 
    

EndWith


While 1
 Sleep(100)
    $evt = $com.CommEvent()
 Switch $evt
     Case $comEvRing ; Change in the Ring Indicator.
 MsgBox(0, "", "Ring Line")
 
        Case $comEvCD ; Change in the CD line.
 MsgBox(0, "", "CD Line")
        
        Case $comEvCTS ; Change in the CTS line.
 MsgBox(0, "", "CTS Line")
            
 Case $comEvDSR ; Change in the DSR line.
            MsgBox(0, "", "DSR Line")
         
 Case $comEvReceive ; Received RThreshold # of chars.
            MsgBox(0, "", "Recieve")
     
 Case $comEvSend ; There are SThreshold number of characters in the transmit buffer.
 MsgBox(0, "", "Send")
            
 Case $comEvEof ; An EOF charater was found in the input stream
 MsgBox(0, "", "EOF")
     
    Endswitch
WEnd
Exit

Func MyErrFunc()
; Set @ERROR to 1 and return control to the program following the trapped error
 SetError(1)
 MsgBox(0, "Error", "Error communicating with modem on COM" );& $com.CommPort)
 Exit
EndFunc;==>MyErrFunc

Hi:

I have a foot switch(three pedals) (serial port, COM 1), the output (pin voltage) of which I want to use in my script.

Using the above code, I can read CTS, DSR, and CD line but it does not work the way I would like it to.

I want to read the output from the switch when it is pressed, but the script reads it when I leave the switch after pressing it. It is true for CTS, DSR, and CD lines.

Someone help me please.

Ajit

My recommendation is to get a 3-button serial mouse, connect the swicthes to that and then you can read the data sent to the serial port. It will be much easier and you would be able to test using hyperterminal for example. I see Amazon are selling them for $19 and they are probably available a lot cheaper.
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

@martin:

Thanks martin, I thought the code almost worked, may be I was wrong.

I understand very little about serial communication and much less about COM objects.

Thanks again

Regards

Ajit

Oh, don't take my post as any comment on your code because I didn't look at it. I just thought that trying to use the control lines was a difficult method and I know nothing about NETCommOCX.

If you only detect when the switch is released why not connect the switches differently to invert the signal from them?

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
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...