Jump to content

Reading Binary Data


Recommended Posts

Hello, I'm trying to get binary data from COM port using Microsoft Comm Control.

Unfortunatelly, I can read only text string. When I set the MSComm property as $comInputModeBinary, I get nothing in Autoit variable ($A), when data length ($n) is returned OK.

Here is my code:

#include <GUIConstants.au3>

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

Global const $comInputModeText = 0

Global const $comInputModeBinary = 1

; == GUI generated with Koda ==);

### Koda GUI section start ###

$Form1 = GUICreate("Form", 418, 320, 192, 125)

$Edit1 = GUICtrlCreateEdit("", 16, 56, 369, 193)

GUICtrlSetData($Edit1, "")

$Button1 = GUICtrlCreateButton("Open", 16, 264, 75, 25, 0)

$Button2 = GUICtrlCreateButton("Close", 104, 264, 75, 25, 0)

$Button3 = GUICtrlCreateButton("Get", 192, 264, 75, 25, 0)

GUISetState(@SW_SHOW)

### Koda GUI section end ###

Dim $old

$Com = ObjCreate("MSCOMMLib.MSComm.1")

$SinkCom=ObjEvent($Com,"MSComm_")

$Com.CommPort = 1

$Com.InputLen = 0

$Com.InputMode = $comInputModeBinary

$Com.RThreshold = 1

$Com.Settings = "9600" & ",n,8,1"

$Com.PortOpen = True

$Com.Output = "ATI9" & @CR

While 1

$nMsg = GUIGetMsg()

Select

Case $nMsg = $GUI_EVENT_CLOSE

Exit

Case $nMsg = $button1

$Com.PortOpen = True

Case $nMsg = $button2

$Com.PortOpen = False

Case $nMsg = $button3

$Com.Output = "ATI9" & @CRLF

EndSelect

WEnd

Func MSComm_OnComm()

Switch $Com.CommEvent

Case $comEvReceive

$n = $Com.InBufferCount

$A = $Com.Input

$old = GUICtrlRead($Edit1)

GUICtrlSetData ( $Edit1, $old & @CRLF & $n & ": " & $A)

EndSwitch

EndFunc

Thanks in advance,

Il

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...