Sign in to follow this  
Followers 0
rcmaehlisafucktard

...

4 posts in this topic

#1 ·  Posted (edited)

Posted Image Edited by Dildo

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You have opened the file to write Unicode characters but you are only dealing with single byte characters. You need to open the file in the default ascii mode, so use

FileOpen($sPath,2) ; not 32 + 2

EDIT: I meant to have said "two byte" not "single byte".

Edited by martin

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.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Use these lines instead:

Global $tData = DllStructCreate("byte[109];")
...
            FileWrite($hFile, ChrW($sTemp))

I know this looks weird.

But this is not the whole story: if you happen to have UTF-16 characters > 0xFF, you're going to write their two bytes as separate characters, giving even more junk.

BTW since we're talking UTF-16, why not have a plain AutoIt string in the first place?

If not possible, then I'd go for a more 16-bit oriented version:

#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include 
#NoTrayIcon
Global $hFile, $iWritten, $sTemp
; This code emulates using _WinAPI_ReadFile to fill a Dllstruct
Global $aData[54] = [0x0000, 0x004A, 0x0050, 0x0054, 0x0058, 0x0054, 0x0032, 0x006E, 0x003E, 0x0068, 0x0057, 0x0066, 0x007A, 0x0020, 0x005D, 0x006E, 0x0071, 0x007A, 0x006A, 0x0081, 0x0020, 0x000A, 0x004C, 0x004F, 0x004C, 0x0096, 0x0020, 0x0055, 0x008C, 0x0020, 0x0081, 0x00CC, 0x006E, 0x0066, 0x0068, 0x0020, 0x00ED, 0x00B0, 0x00A4, 0x00F3, 0x00AA, 0x00EA, 0x00B8, 0x00CA, 0x00EB, 0x00AF, 0x00A8, 0x0020, 0x000A, 0x00B9, 0x00C8, 0x0067, 0x0059, 0x0000]
Global $tData = DllStructCreate("ushort[" & UBound($aData) & "];")
For $i = 0 To UBound($aData) - 1
    DllStructSetData($tData, 1, $aData[$i], $i + 1)
Next
; This code confirms that the data in the DllStruct matches the data read from the original BIN file.
;~ $hFile = _WinAPI_CreateFile(@ScriptDir & "Test.bin", 1, 4)
;~ _WinAPI_WriteFile($hFile, DllStructGetPtr($tData), 109, $iWritten)
;~ _WinAPI_CloseHandle($hFile)
; Open a text file and write all non-null characters. Line Feeds will be converted to "n".
$hFile = FileOpen(@ScriptDir & "Testbin.txt", 34)
For $i = 1 To UBound($aData) - 1
    $sTemp = DllStructGetData($tData, 1, $i)
    Switch $sTemp
  Case 0x0000
   ContinueLoop
        Case 0x000A
            FileWrite($hFile, "n")
        Case Else
            FileWrite($hFile, ChrW($sTemp))
    EndSwitch
Next
FileClose($hFile)
; This code will create a text file that is the expected Output of the above code.
;~ Global $sTest = "0xFFFE4A00500054005800540032006E003E006800570066007A0020005D006E0071007A006A00810020005C006E004C004F004C009600200055008C0020008100CC006E00660068002000ED00B000A400F300AA00EA00B800CA00EB00AF00A80020005C006E00B900C80067005900"
;~ $hFile = FileOpen("Expected Output.txt", 18)
;~ FileWrite($hFile, $sTest)
;~ FileClose($hFile)
Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

The output file is supposed to be Unicode (UTF-16 Little Endian) and the commented code at the bottom of my script proves the problem has nothing to do with encoding.

OK, then if you want the output to be Unicode you should not be dealing with 2-byte chars Dildo.


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.

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