Sign in to follow this  
Followers 0
Vision

ConsoleWrite to txt doc or excel document

7 posts in this topic

hi,

i trying something with this code, the data what incomine are written in the console, this works wonderful, so how i can write the directly to a txtfile oder excel file .xls ??

thanks in adavance

HotKeySet("{ESC}", "_Killit")

$NetComm = ObjCreate("NETCommOCX.NETComm");Create NETComm.ocx object

;Set object settings
With $NetComm
        .CommPort = 1               ;Set port number
        .Settings = "9600,N,8,1"    ;Set port settings
        .InputLen = 0               ;reads entire buffer
        .InputMode = 0              ;reads in text mode
        .HandShaking = 3           ;uses both RTS and Xon/Xoff handshaking
        .PortOpen = "True"          ;opens specified COM port
EndWith

While 1
    _GetData()
WEnd

Func _GetData()
    If $NetComm.InBufferCount > 0 Then      
        ConsoleWrite($NetComm.InputData)    
        Sleep(250)                          
    EndIf
EndFunc

Func _Killit()
    Exit
EndFunc

Share this post


Link to post
Share on other sites



Dim $filename = "nameonthefile.txt"
Dim $write = "This is the text I want to write, this is what you are going to write";;This could be Dim $write = $NetComm.InputData
Dim $filehandle = FileOpen($filename, 1)
FileWrite($filehandle, $write)
FileClose($filehandle)

Share this post


Link to post
Share on other sites

thanks for fast response, where i can find a review of the $NetComm variable?

or how i can send a defined value? like "1inc" to the rs232 port?

thanks and best regards

Share this post


Link to post
Share on other sites

I thought you asked for how to write a value to a file, and I posted how to do it :)

Dim $filename = "nameonthefile.txt"
Dim $write = "This is the text I want to write, this is what you are going to write"
Dim $filehandle = FileOpen($filename, 1)
FileWrite($filehandle, $write)
FileClose($filehandle)

Dim $filename = "nameonthefile.txt"

*The name of the file you want to write to

Dim $write = "This is the text I want to write, this is what you are going to write"

*What you are going to write to the file

Dim $filehandle = FileOpen($filename, 1)

*Opens the file

FileWrite($filehandle, $write)

*Writes to the file from the variable $write that was decleared

FileClose($filehandle)

*Closes the file (Kind of useless)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

yes thanks for explaining but thats not the problem^^

i will send "1inc" to the rs232 port via $NetComm

the read and write to the txt file works perfect

Edited by Vision

Share this post


Link to post
Share on other sites

HotKeySet("{ESC}", "_Killit")

$NetComm = ObjCreate("NETCommOCX.NETComm");Create NETComm.ocx object

;Set object settings
With $NetComm
        .CommPort = 1                ;Set port number
        .Settings = "9600,N,8,1"    ;Set port settings
        .InputLen = 0                ;reads entire buffer
        .InputMode = 0                ;reads in text mode
        .HandShaking = 3           ;uses both RTS and Xon/Xoff handshaking
        .PortOpen = "True"            ;opens specified COM port
EndWith

$file = FileOpen("output.txt", 1)

While 1
    If $NetComm.InBufferCount > 0 Then        
        FileWrite($file, $NetComm.InputData)
    EndIf
    Sleep(250)
WEnd

Func _Killit()
    FileClose($file)
    Exit
EndFunc

This will take everything from the line and just write it to the file. I don't know the object so I can't tell you how to send things.

Also, I removed your get data function by just putting it's code in the loop. It's more efficient this way.

Share this post


Link to post
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
Sign in to follow this  
Followers 0