Jump to content

_CommGetLineStates() , RS232 DCD line read ,


Recommended Posts

I`m doing school project about flowmeter connected to computer.

The main idea is: Read DCD status from  RS232(com1) port. 

If DCD = 1 than

$myexample = $myexample + 1

endif

Next> i will show "myexample" in msgbox.

The problem is that i get no read from _CommGetLineStates().

#include 'CommMG.au3'

;Internal for the Serial UDF
Global $sportSetError = ''

;COM Vars
Global $CMPort = 1               ; Port
Global $CmBoBaud = 9600            ; Baud
Global $CmboDataBits =  8        ; Data Bits
Global $CmBoParity = "none"        ; Parity
Global $CmBoStop = 1            ; Stop
Global $setflow = 2                ; Flow

;Start up communication with the device

;$DTRMode 0 = turns on the DTR line when the port is opened and leaves it on
; 1 = enables DTR handshaking
; 2 = disables the DTR line when the device is opened and leaves it disabled.



_CommSetPort($CMPort, $sportSetError, $CmBoBaud, $CmboDataBits, $CmBoParity, $CmBoStop, $setflow)

_CommSetDTR(1) ;that work nice
sleep(1000)
_CommSetDTR(0)
sleep(1000)

_CommGetLineStates()

>Exit code: 0    Time: 2.462

 

circuit.gif

http://www.linuxfocus.org/English/January2001/article186.shtml  <<using this setup.

I`ve checked that i got read in REALTERM and green light on DCD(1) line  when i push the button.

My english is not realy poetic but i hope this Topic will help som1 understand "simple serial comunication".

 

Link to comment
Share on other sites

;===================================================================================
;
; Function Name:  _CommGetLIneStates()
; Description:    Gets the states of 4 signals
; Parameters:     none
; Returns;   on success
;               returns an array with 4 elements giving the state of the lines CTS, DSR, Ring Indicator and DCD
;               in that order. Value True = ON, value False = OFF
;           on failure
;            returns -1 and @error set to 1
;====================================================================================
Func _CommGetLineStates()
    Local $vDllAns
    Local $iL, $aStates[4]

    If Not $fPortOpen Then
        SetError(1)
        Return -1
    EndIf


    $vDllAns = DllCall($hDll, 'int', 'GetLineStates')

    If @error <> 0 Then
        SetError(1)
        Return -1
    EndIf
    mgdebugCW($vDllAns[0] & @CRLF)
    For $iL = 0 To 3
        $aStates[$iL] = BitAND($vDllAns[0], 2 ^ $iL) <> 0
    Next
    Return $aStates

EndFunc   ;==>_CommGetLineStates

How to get 4th element from $aStates? I realy want to see it.

#include 'CommMG.au3'

#include <Array.au3>

;Internal for the Serial UDF
Global $sportSetError = ''

Local $bStates[6]

;COM Vars
Global $CMPort = 1               ; Port
Global $CmBoBaud = 9600            ; Baud
Global $CmboDataBits =  8        ; Data Bits
Global $CmBoParity = "none"        ; Parity
Global $CmBoStop = 1            ; Stop
Global $setflow = 2                ; Flow

;Start up communication with the device

;$DTRMode 0 = turns on the DTR line when the port is opened and leaves it on
; 1 = enables DTR handshaking
; 2 = disables the DTR line when the device is opened and leaves it disabled.



_CommSetPort($CMPort, $sportSetError, $CmBoBaud, $CmboDataBits, $CmBoParity, $CmBoStop, $setflow)

;_CommSetDTR(1) ;that work nice
;sleep(100)
;_CommSetDTR(0)
;sleep(100)
 $bStates = _CommGetLineStates()



;MsgBox(0, "4", $aStates[4])
Local $tablica[3] = ["jeden", "dwa", "trzy"]
;_ArrayDisplay($tablica)
_ArrayDisplay($bStates)
Edited by polaski
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...