Jump to content

Controlling Turbosoft's TTWin with DLL


 Share

Recommended Posts

Hi Guys,

I'm quite new to using DLL's through autoit and I'm struggling to get a grip on how to achieve my goal.

My objective is to control certain aspects of TTWin (a telnet client) which I use for my P.O.S. at work.

The plan is to capture a serial input from a hand held barcode scanner and send data directly to TTwin when certain criteria are met (ie the cursor is ready for the part #)

I have been able to control TTwin successfully using VB6 but I would very much like to get a handle on how I can do this with autoit.

The code that I use in VB6 is:-

NoSessions = ttGetSessionCount()
;MsgBox (NoSessions)
hndl = ttGetSessionByTitle("HO1 Commercial System")
;MsgBox (hndl)
CursPosi = ttGetCursorPosn(hndl, RowPos, ColPos)
MsgBox (CursPosi & ", " & RowPos & ", " & ColPos)

    If NoSessions = 0 Then
        MsgBox "No TTWin sessions active!"
    Else
        hndl = ttGetSessionByTitle("HO1 Commercial System")
        If hndl = 0 Then
            MsgBox "Could not attach to TTWin - HO1 Commercial System"
            End
        End If

This refers to a module (Twdecl32.bas) which declares DLL calls:-

' Session access
Declare Function ttGetSessionByTitle Lib "TWCDLL.DLL" (ByVal Title As String) As Long
Declare Function ttOpenSessionByTitle Lib "TWCDLL.DLL" (ByVal Title As String) As Long
Declare Function ttGetSessionByID Lib "TWCDLL.DLL" (ByVal IDString As String) As Long
Declare Function ttOpenSessionByID Lib "TWCDLL.DLL" (ByVal IDString As String) As Long
Declare Function ttGetSessionCount Lib "TWCDLL.DLL" () As Long
Declare Function ttGetSessionEntry Lib "TWCDLL.DLL" (ByVal Session As Long, Buffer As SessionEntry) As Long
Declare Function ttCloseSession Lib "TWCDLL.DLL" (ByVal HSess As Long) As Long
Declare Function ttOpenSessionByCounter Lib "TWCDLL.DLL" (ByVal n As Long) As Long
 
' Session files
Declare Function ttCfgNew Lib "TWCDLL.DLL" (ByVal HSess As Long) As Long
Declare Function ttCfgOpen Lib "TWCDLL.DLL" (ByVal HSess As Long, ByVal Filename As String) As Long
Declare Function ttCfgSave Lib "TWCDLL.DLL" (ByVal HSess As Long) As Long
Declare Function ttCfgSaveAs Lib "TWCDLL.DLL" (ByVal HSess As Long, ByVal Filename As String) As Long
' Window manipulation
Declare Function ttSetWindowStyle Lib "TWCDLL.DLL" (ByVal HSess As Long, ByVal Style As Long) As Long
Declare Function ttShowModuleLabels Lib "TWCDLL.DLL" (ByVal HSess As Long, ByVal State As Long) As Long
Declare Function ttShowStatus Lib "TWCDLL.DLL" (ByVal HSess As Long, ByVal State As Long) As Long
Declare Function ttShowButtons Lib "TWCDLL.DLL" (ByVal HSess As Long, ByVal State As Long) As Long
Declare Function ttShowMenu Lib "TWCDLL.DLL" (ByVal HSess As Long, ByVal State As Long) As Long
Declare Function ttSetMenuMode Lib "TWCDLL.DLL" (ByVal HSess As Long, ByVal State As Long, ByVal InSystemMenu As Long) As Long

So I have been trying to do the same using code like:-

$dll = DllOpen("TWCDLL.DLL")
Dim $Ret
$ret = DllCall($dll, "int", "ttGetSessionCount")
ConsoleWrite("$ret: " & $ret[0] & @CRLF)

Which does work correctly, but I'm completely lost as to how to do the more complexed calls.

Dim $TitleName,$TitleVar,$TitleBuff
$TitleName = DllCall($dll, "int", "ttGetTitle", "Hsess", "1", "Title", $TitleVar, "unsigned", $TitleBuff)
ConsoleWrite("$TitleName: " & $TitleName & @CRLF)
ConsoleWrite("$TitleVar: " & $TitleVar & @CRLF)
ConsoleWrite("$TitleBuff: " & $TitleBuff & @CRLF)

This code above doesn't work, and is probably no where near the correct syntax.

The calls that I need to achieve for this project are:-

ttGetSessionByTitle

ttGetCursorPosn

ttEmKeys

ttDispReadText

There is nothing in the scripting manual on 'ttGetSessionByTitle' but I have included snippets for the others'

ttGetCursorPosn ()

Description gets the row and column values for the current cursor position.

Visual Basic ttGetCursorPosn

(ByVal HSess As Long,

Row As Long,

Col As Long)

As Long

C language int ttGetCursorPosn

(HSess HSess,

int FAR *Row,

int FAR *Col);

Parameters The row and column values are assigned to Row and Col

respectively. The top row and leftmost column both return a

value of 1.

ttEmKeys ()

Description Sends a sequence of keystrokes to the host as if typed at a

keyboard.

Declaration Sub EmKeys (ByVal Text$ As String)

Visual Basic ttEmKeys (ByVal HSess As Long,

ByVal Text As String,

ByVal Length As Long)

As Long

C language int ttEmKeys (

HSess HSess,

LPCSTR Text,

unsigned Length);

Parameters Text % is the sequence of keystrokes sent to the host.

Return value The function returns the following values:

Value Meaning

0 The function succeeded.

< 0 The function failed.

ttDispReadText ()

Description Reads a given length character string from the screen.

Declaration Sub DispReadText (Text$ As String, ByVal Row% As

Integer, ByVal Col% As Integer, ByVal Length% As Integer)

Visual Basic ttDispReadText

(ByVal HSess As Long,

ByVal Text As String,

ByVal Row As Long,

ByVal Col As Long,

ByVal Length As Long)

As Long

C language int ttDispReadText

(HSess HSess,

LPSTR Text,

int Row,

int Col,

int Length);

Parameters Text$ is a string array holding the read character string.

Row% is the starting line of the character string read.

Col% is the starting column of the character string read.

Note: Screen coordinates have an origin of (1,1) at the top left

of the screen.

Length% is the length of the sting to be read, in characters.

Return value The function returns the following values:

Value Meaning

0 The function succeeded.

< 0 The function failed.

-

I hope this is enough to go on; I really appreciate any hints, examples, help that any one can offer.

Cheers

Link to comment
Share on other sites

From the AutoIt DllCall reference:

$return[0] = function return value

$return[1] = param1

$return[2] = param2

AutoIt makes byref parameters available in the array DllCall returns, the original variables passed are unmodified. Edited by Unsigned

.

Link to comment
Share on other sites

Thanks unsigned,

I have tried this:-

Dim $TitleName,$TitleVar,$TitleBuff
$TitleVar = "Title"
$TitleName = DllCall($dll, "long", "ttGetTitle", "HANDLE", 1, "str", "Title", "int", "Buffsize")
;ConsoleWrite("$TitleName: " & $TitleName & @CRLF)
ConsoleWrite("$TitleName[0]: " & $TitleName[0] & @CRLF)
ConsoleWrite("$TitleName[1]: " & $TitleName[1] & @CRLF)
ConsoleWrite("$TitleName[2]: " & $TitleName[2] & @CRLF)

Am I getting closer. I don't get the correct results, instead I see:-

$TitleName[0]: 0

$TitleName[1]: 0x00000001

$TitleName[2]: Title

The title should be "HO1 Commercial System"

Any help is appreciated

Cheers

Link to comment
Share on other sites

And what's the syntax of ttGetTitle? I don't see it anywhere in your original post.

Your DllCall syntax is incorrect though, try this:

$TitleName = DllCall($dll, "long", "ttGetTitle", "HANDLE", 1, "str", "", "int", 65536)

Your "int" parameter is supposed to be the buffer size, not the string "Buffsize" :graduated:

The AutoIt "str" type allocates a minimum of 65536 bytes (64kb), so that should presumably be in your last parameter.

Again, if you post the full syntax I can probably help you more specifically.

Edited by Unsigned

.

Link to comment
Share on other sites

Sorry about the code displayed incorrectly, for the life of me I can't work out how to edit it. Perhaps I haven't been a member long enough or made enough posts.

The info from the TTwin manual is:-

ttGetTitle$ ()

Description Gets the title of the current TTWIN session.

Declaration Function GetTitle$ As String

Function GetTitle As Variant

Visual Basic ttGetTitle

(ByVal HSess As Long,

ByVal Title As String,

ByVal BuffSize As Long)

As Long

C language int ttGetTitle

(HSess HSess,

LPSTR Title,

unsigned BuffSize);

Remarks The title contents, without the "TTWIN - " prefix, are

returned.

The title is set using ttSetTitle.

Parameter Title is the title of the session.

BuffSize is the size of Title.

Return value Returns the title of the current TTWIN session.

Return value The function returns the following values:

Menu Configure > Title

Example

Title$ = GetTitle$

The title contents, less the "TTWIN - " prefix, is returned via

the string variable Title$.

Value Meaning

0 The function succeeded.

< 0 The function failed.

Whilst I don't need the 'ttGetTitle' for my project I am using it currently as I have a known reult to expect.

Let me know if you would like me to re-post the VB6 info (or perhaps help me edit the post if there's some sort of trick to it...) and I'll re-attempt it

Cheers

Link to comment
Share on other sites

No worries,

I found that the calls wont work unless you have called the 'ttGetSessionByTitle' even if I didn't use the data retuned. As this doesn't effect my project I wont be investigating this.

$dll = DllOpen("TWCDLL.DLL")
;Get session count
Dim $Ret
$ret = DllCall($dll, "int", "ttGetSessionCount")
ConsoleWrite("$ret[0]: " & $ret[0] & @CRLF)
;Get handle/HSess # based on Title
dim $hndl
$SessTitle = "HO1 Commercial System"
$hndl = DllCall($dll, "int", "ttGetSessionByTitle",  "str" , $sesstitle)
ConsoleWrite("$hndl[0]: " & $hndl[0] & @CRLF)
;Get's title name (useful if multiple sessions open)
Dim $TitleName
$TitleName = DllCall($dll, "long", "ttGetTitle", "HANDLE", $hndl[0], "str", "", "int", 4096)
ConsoleWrite("$TitleName[2]: " & $TitleName[2] & @CRLF)
;Returns the cursors X & Y poition in Ascii format (hence the 'asc')
dim $res
$res = DllCall($dll, "int", "ttGetCursorPosn", "HANDLE", $hndl[0], "str", "", "str", "")
ConsoleWrite("X - asc($res[2]): " & asc($res[2]) & @CRLF)
ConsoleWrite("Y - asc($res[3]): " & asc($res[3]) & @CRLF)
;Returns the screen size in Ascii format (hence the 'asc')
dim $ScreenSize
$ScreenSize = DllCall($dll, "int", "ttGetScreenSize", "HANDLE", $hndl[0], "str", "", "str","")
ConsoleWrite("$ScreenSize[2]: " & asc($ScreenSize[2]) & @CRLF)
ConsoleWrite("$ScreenSize[3]: " & asc($ScreenSize[3]) & @CRLF)
;Returns a string of text from ttwin based on X,Y and length
dim $rc, $Xpos, $Ypos, $rdLgth
$Xpos=0
$Ypos=4
$rdLgth=25
$rc = dllcall($dll, "int", "ttDispReadText", "HANDLE", $hndl[0], "str","","int", $Xpos, "int", $Ypos, "int", $rdLgth)
ConsoleWrite("$rc[2]: " & $rc[2] & @CRLF)
;sends keys to ttwin at current cursor location
dim $emkeys, $alen
$emkeys = "p570a" & @CR ;Keys to send
$alen = StringLen($emkeys)
dim $emRes
$emRes  = DllCall($dll, "int", "ttEmKeys", "HANDLE", $hndl[0], "str", $emkeys , "int", $alen)
ConsoleWrite("$emRes[0]: " & $emRes[0] & @CRLF)
DllClose($dll)

I hope that this helps if anyone else is using ttwin, please feel free to contact me if I can be of any other assistance

Cheers

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