Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Serial ( COM ) Port Console Script


  • Please log in to reply
136 replies to this topic
aobrien
  • Members
  • 77 posts
  • Last active: Mar 06 2014 04:42 AM
  • Joined: 14 Feb 2008
Hi A_Guest,

Yes, my post on "Sat Oct 18, 2008 3:19 am" will be the best starting point for you.

Your first line -- "COM Settings","9600","O","8","1" -- is taken care of in the "User Variables" section of the script.

The main problem you will have is knowing EXACTLY the data being sent out on the serial port. I have a feeling that the lines you posted don't tell the entire story. I have an idea on how you can work around this :)

Use my original script (in the 2nd post) and pretend that it (the script) is your Plasma TV. Use your bloated software to send the Power On command to my script. The script will record every byte that was received. Then you will know exactly what needs to be sent to the Plasma TV using the "message" line.

The trick is that my script (in the 2nd post) will need to be modified to show you the hex instead of the ASCII. To do this make the modification below.
[EDIT] corrected the contents of the code box below [/EDIT]
;[line 168]

    ;7/23/08 Modified this IF statement because Read_from_COM() now returns data instead of ASCII
    ;Set to 0 if you want to see the decimal data as received by the serial port.
    IF (1)
    {...


;[change it to this...]

    ;7/23/08 Modified this IF statement because Read_from_COM() now returns data instead of ASCII
    ;Set to 0 if you want to see the decimal data as received by the serial port.
    IF (0)
    {...



It is a little bit of work, but try it out and let me know how it turns out.

aobrien.

aobrien
  • Members
  • 77 posts
  • Last active: Mar 06 2014 04:42 AM
  • Joined: 14 Feb 2008
Hi Max,

Sorry for the non-working code. Also, sorry for the long delay... yahoo randomly sends the AHK notifications into the spam folder :evil:

I modified the code in my original reply to you. This time I did a quick sanity test on it and I was able to get it into the infinite loop. I found a couple of mistakes.

aobrien

A_Guest
  • Guests
  • Last active:
  • Joined: --
aobrien, thanks for answering

i did some test with your first suggestion and it didnt work. I also looked at the program i mentioned. It use all kinds of windows dlls it seems. I dont know if that is suggesting that it is more to it than meets the eye or if its for the programs UI or something else. Still, i would like to test your second seggestion but i need some help.

I downloaded the script from your 2nd post but i cant find the lines of code at ~155 or anywhere else in the script, youve been updating it?

Also, how do i setup so the script get what i send from the program? Could you elaborate this please

Terry K
  • Guests
  • Last active:
  • Joined: --
Thanks for writing and sharing this code.

I have used your code to read barcodes from a portable scanner. It works great on my office PC but does not work on other winXP machines. It acts like it is working, but no data appears in the notepad document. There are no error messages. Im having trouble figuring out why this might work on one WINXP pc but not on another. Any Ideas??

aobrien
  • Members
  • 77 posts
  • Last active: Mar 06 2014 04:42 AM
  • Joined: 14 Feb 2008
Hi Terry K,

If you post your code ([EDID]did you use it exactly as originally posted?[/EDIT]) then I can take a look at it. If not, then I usually use the MsgBox command to try and figure out what is happening in the script. Just place "MsgBox, some_var=%some_var%" (without the quotes and replace some_var with the variable name of interest) and it will display the message box along with the value of your variable.

Without seeing the code I would guess that placing this command right after read_from_com would be a good place to start.

aobrien

aobrien
  • Members
  • 77 posts
  • Last active: Mar 06 2014 04:42 AM
  • Joined: 14 Feb 2008
Hi A_Guest,

My appologies. You are right. I must have been looking at an older version of the script. I was sure that I was using the one on my second post... sigh... oh well. I corrected my (Mon Nov 17, 2008 7:33 am) post.

Also, Read_From_COM (by default) returns the ASCII equivalent of the HEX data that was received on the COM port. If the com port received 0x08 0x09 0x0A 0x0B 0x0C 0x0D 0x0E 0x0F 0x10 0X11... then

Read_From_COM would return the ASCII characters:
08090A0B0C0D0E0F1011...

Why don't you join the forum and we can take this off line.
aobrien

quatermass
  • Members
  • 220 posts
  • Last active: Dec 16 2013 09:00 PM
  • Joined: 14 Dec 2005
OK I can set COM port and baud rate, etc. how do I set up the Flow Control parameter?

I need to use "RTS/CTS" (Hardware control)

:D


I did find this snippet on this forum
at <!-- m -->http://www.autohotke...pic.php?t=10030<!-- m -->

typedef struct _DCB {
    DWORD DCBlength;      /* sizeof(DCB)                     */
    DWORD BaudRate;       /* Baudrate at which running       */
    DWORD fBinary: 1;     /* Binary Mode (skip EOF check)    */
    DWORD fParity: 1;     /* Enable parity checking          */
    DWORD fOutxCtsFlow:1; /* CTS handshaking on output       */
    DWORD fOutxDsrFlow:1; /* DSR handshaking on output       */
    DWORD fDtrControl:2;  /* DTR Flow control                */
    DWORD fDsrSensitivity:1; /* DSR Sensitivity              */
    DWORD fTXContinueOnXoff: 1; /* Continue TX when Xoff sent */
    DWORD fOutX: 1;       /* Enable output X-ON/X-OFF        */
    DWORD fInX: 1;        /* Enable input X-ON/X-OFF         */
    DWORD fErrorChar: 1;  /* Enable Err Replacement          */
    DWORD fNull: 1;       /* Enable Null stripping           */
    DWORD fRtsControl:2;  /* Rts Flow control                */
    DWORD fAbortOnError:1; /* Abort all reads and writes on Error */
    DWORD fDummy2:17;     /* Reserved                        */
    WORD wReserved;       /* Not currently used              */
    WORD XonLim;          /* Transmit X-ON threshold         */
    WORD XoffLim;         /* Transmit X-OFF threshold        */
    BYTE ByteSize;        /* Number of bits/byte, 4-8        */
    BYTE Parity;          /* 0-4=None,Odd,Even,Mark,Space    */
    BYTE StopBits;        /* 0,1,2 = 1, 1.5, 2               */
    char XonChar;         /* Tx and Rx X-ON character        */
    char XoffChar;        /* Tx and Rx X-OFF character       */
    char ErrorChar;       /* Error replacement char          */
    char EofChar;         /* End of Input character          */
    char EvtChar;         /* Received Event character        */
    WORD wReserved1;      /* Fill for now.                   */
} DCB, *LPDCB;

Flowcontrol
Xon/Xoff: 21393 -> 0101 0011 1001 0001
Hardware: 24725 -> 0110 0000 1001 0101
Off:      20625 -> 0101 0000 1001 0001
*/

But I don't know how to apply this alteration to the script.
Can someone point the way?

I guess I need to place one of these selectable numbers of the flowcontrol

ie 21393, 24725 or 20625 into the right part of the &DCB address?

before applying the state?

So if I understand it, I need to alter 4 bytes, 24 bytes after the address of &DCB?

This deep level of using AHK is new to me. Sorry.


I've been tinkering and came up with this:

; FLow Control preset variable masks
;############################
Flow_control_XonOff := 21393
Flow_control_Hardware := 24725
Flow_control_Off := 20625
;###### User Variables 
COM_Port     = COM1
COM_Baud     = 115200
COM_Parity   = N
COM_Data     = 8
COM_Stop     = 1
Console_Path =
Flow_Control := Flow_control_Hardware

Then in the Initialize_COM(COM_Settings) function I added a line which sets the flow control just before setting the Com state :

;###### Set COM State ######
;Sets the COM Port number, baud rate,...

; Sets flow control
  NumPut(Flow_Control,DCB,24,"Uint")

  SCS_Result := DllCall("SetCommState"
 

Would this work you think?
Stuart Halliday

twhyman
  • Members
  • 348 posts
  • Last active: Sep 17 2014 01:55 AM
  • Joined: 07 Dec 2005
Hi,

First of all great work on the COM functions! 8)

I have created a script that will "talk" with my LCD TV.

I have managed to make all the ASCII and HEX conversion needed to
Communicate with the TV.

Sending the commands works great thanks to the Write_to_COM function.

Everything i send and is acceptable by TV works.

My problem is that the getting the answer is a bit buggy:
Question:
ka 01 FF
Expected Answer:
a 01 OK00x

The problem that sometimes i get:
a 01 OK0
or
a 01 O

which is not the full answer, without the answer you cannot know in which state is the TV and you cannot make "decisions" based upon the answers :(.

i provided my full script below, it seems it a problem with the Read_from_COM loop, which is maybe too slow?

Hope you can help me, i tested the communication with the TV using Tera Term and i did not see any communication problems in getting the TV answers.

Thanks in advanced,
Twhyman

;#NoTrayIcon
Menu, Tray, MainWindow

/*
;### Check if vista media center is running
Process, Wait, ehshell.exe, 5
PID=%ErrorLevel%
If (PID!=0)
 Goto, Start_TV
Else
 ExitApp
*/

Start_TV:
;### User Variables (Change these to match you needs) ####
IniRead, COM_Port, %A_ScriptDir%\Tv_Control.ini, Settings, COM_Port ;, COM1
IniRead, COM_Baud, %A_ScriptDir%\Tv_Control.ini, Settings, COM_Baud ;, 9600
IniRead, COM_Parity, %A_ScriptDir%\Tv_Control.ini, Settings, COM_Parity ;,N
IniRead, COM_Data, %A_ScriptDir%\Tv_Control.ini, Settings, COM_Data ;,8
IniRead, COM_Stop, %A_ScriptDir%\Tv_Control.ini, Settings, COM_Stop ;,1

;### Script Variables (Don't touch these) ###
COM_Settings = %COM_Port%:baud=%COM_Baud% parity=%COM_Parity% data=%COM_Data% stop=%COM_Stop% dtr=Off

; Power Commands
Power_On:="ka 01 01"
Power_Off:="ka 01 00"
Power_Query:="ka 01 FF"

; set input Commands
AV1:="xb 01 20"
AV2:="xb 01 21"
Component01:="xb 01 40"
Component01:="xb 01 41"
RGB_PC:= "xb 01 60"
HDMI1:="xb 01 90"
HDMI1:="xb 01 91"
Input_Query:= "xb 01 FF"

; Set Volume Commnads
Vol:="kf 01 30"

; Open COM Port
Initialize_COM(COM_Settings)

Power_Query_Code:=TV_Code2Hex(Power_Query)
;msgbox, 1:%Power_Query%`n%Power_Query_Code%
Write_to_COM(Power_Query_Code)

;COM port receive loop
Loop
{
  Read_Data := Read_from_COM("0xFF")
  ;msgbox, Bytes_Received=%Bytes_Received%`nRead_Data=%Read_Data% ;Global variable that is set by Read_from_COM()

  ;0xFF in the above line basically sets the size of the read buffer.
  ;  Use StringLeft to collect only the data received by the COM port.
  ;  Bytes_Received is a global variable that is set during the Read_from_COM() routine.
  ;StringLeft, Read_Data, Read_Data, Bytes_Received ;5/22/08 This line was moved to Read_from_COM() subroutine.

  ;Process the data, if there is any.
  If (Bytes_Received > 0)
  {
    ;msgbox, Read_Data=%Read_Data%`n%Bytes_Received%

    ;Prevent interruption during execution of this loop.
    Critical, On

    ;7/23/08 Modified this IF statement because Read_from_COM() now returns data instead of ASCII
    ;Set to 0 if you want to see the decimal data as received by the serial port.
    IF (1)
    {
      ;Begin Data to ASCII conversion
      ASCII =
      Read_Data_Num_Bytes := StrLen(Read_Data) / 2 ;Read_from_COM() returns 2 characters for each byte

      Loop %Read_Data_Num_Bytes%
      {
        StringLeft, Byte, Read_Data, 2
        StringTrimLeft, Read_Data, Read_Data, 2

        Byte = 0x%Byte% ; Hex Conversion
     
        ;Byte := Byte + 0 ;Convert to Decimal       
        If (Byte="0x20")
         ASCII_Chr=#Space# ; unique string so i can add %A_Space% later
        Else
         ASCII_Chr := Chr(Byte)
        
        ASCII = %ASCII%%ASCII_Chr%
      }
      StringReplace, ASCII, ASCII, #Space#, %A_Space%, A ; add the space
      Quit_var = 1 ; done reading input exit
      ;End Data to ASCII conversion
    }
    Else ;Send the data that was received by the COM port-ASCII format
      msgbox, %Read_Data%

    Critical, Off
  }
   if Quit_var = 1
    Break
}

msgbox, 1:Power_Query_Result:%ASCII%
If (ASCII!="a 01 OK00x") ; this is the expected answer from the TV "OK"
 FileAppend, Cannot turn TV On - %ASCII%`n, Log.txt
Else
 FileAppend, TV turn On success - %ASCII%`n, Log.txt

; in order to debug my problem i am clearing all the loop related vars.
;listvars
;pause

Quit_var=
ASCII=
ASCII_Chr=
Read_Data= 
Read_Data_Num_Bytes=
Byte=
Bytes_Received=

;listvars
;pause

;Sleep,5000 ; Tried Using sleep in order to dealy the new Write_to_COM so maybe this will help grabbing the entire answer from the TV.

Input_Query_Code:=TV_Code2Hex(Input_Query)
;msgbox, 2:%RGB_PC%`n%RGB_PC_Input_Code%
Write_to_COM(Input_Query_Code)

;COM port receive loop
Loop
{
  Read_Data := Read_from_COM("0xFF")
  ;msgbox, Bytes_Received=%Bytes_Received%`nRead_Data=%Read_Data% ;Global variable that is set by Read_from_COM()

  ;0xFF in the above line basically sets the size of the read buffer.
  ;  Use StringLeft to collect only the data received by the COM port.
  ;  Bytes_Received is a global variable that is set during the Read_from_COM() routine.
  ;StringLeft, Read_Data, Read_Data, Bytes_Received ;5/22/08 This line was moved to Read_from_COM() subroutine.

  ;Process the data, if there is any.
  If (Bytes_Received > 0)
  {
    ;msgbox, Read_Data=%Read_Data%`n%Bytes_Received%

    ;Prevent interruption during execution of this loop.
    Critical, On

    ;7/23/08 Modified this IF statement because Read_from_COM() now returns data instead of ASCII
    ;Set to 0 if you want to see the decimal data as received by the serial port.
    IF (1)
    {
      ;Begin Data to ASCII conversion
      ASCII =
      Read_Data_Num_Bytes := StrLen(Read_Data) / 2 ;Read_from_COM() returns 2 characters for each byte

      Loop %Read_Data_Num_Bytes%
      {
        StringLeft, Byte, Read_Data, 2
        StringTrimLeft, Read_Data, Read_Data, 2

        Byte = 0x%Byte%
     
        ;Byte := Byte + 0 ;Convert to Decimal       
        If (Byte="0x20")
         ASCII_Chr=#Space#
        Else
         ASCII_Chr := Chr(Byte)
        
        ASCII = %ASCII%%ASCII_Chr%
      }
      StringReplace, ASCII, ASCII, #Space#, %A_Space%, A
      Quit_var = 1
      ;End Data to ASCII conversion
    }
    Else ;Send the data that was received by the COM port-ASCII format
      msgbox, %Read_Data%

    Critical, Off
  }
   if Quit_var = 1
    Break
}
;msgbox, 2:RGB_Query_Result:%ASCII%
If (ASCII!="b 01 OKFFx") ; ; this is the expected answer from the TV "OK"
 FileAppend, Cannot query inputs on tv - %ASCII%`n, Log.txt
Else
 FileAppend, Query inputs on tv success - %ASCII%`n, Log.txt


Close_COM(COM_FileHandle)
ExitApp

;########################################################################
;###### Subroutines (You don't really need to look below this line) #####
;########################################################################

;########################################################################
;###### Initialize COM Subroutine (Don't touch this routine) ############
;########################################################################
Initialize_COM(COM_Settings)
{
  Global COM_FileHandle

  ;###### Build COM DCB ######
  ;Creates the structure that contains the COM Port number, baud rate,...
  VarSetCapacity(DCB, 28)
  BCD_Result := DllCall("BuildCommDCB"
       ,"str" , COM_Settings ;lpDef
       ,"UInt", &DCB)        ;lpDCB
  If (BCD_Result <> 1)
  {
    MsgBox, There is a problem with Serial Port communication. `nFailed Dll BuildCommDCB, BCD_Result=%BCD_Result% `nThe Script Will Now Exit.
    Exit
  }

  ;###### Extract/Format the COM Port Number ######
  ;7/23/08 Thanks krisky68 for finding/solving the bug in which COM Ports greater than 9 didn't work.
  StringSplit, COM_Port_Temp, COM_Settings, `:
  COM_Port_Temp1_Len := StrLen(COM_Port_Temp1)  ;For COM Ports > 9 \\.\ needs to prepended to the COM Port name.
  If (COM_Port_Temp1_Len > 4)                   ;So the valid names are
    COM_Port = \\.\%COM_Port_Temp1%             ; ... COM8  COM9   \\.\COM10  \\.\COM11  \\.\COM12 and so on...
  Else                                          ;
    COM_Port = %COM_Port_Temp1%
  ;MsgBox, COM_Port=%COM_Port%

  ;###### Create COM File ######
  ;Creates the COM Port File Handle
  ;StringLeft, COM_Port, COM_Settings, 4  ; 7/23/08 This line is replaced by the "Extract/Format the COM Port Number" section above.
  COM_FileHandle := DllCall("CreateFile"
       ,"Str" , COM_Port     ;File Name         
       ,"UInt", 0xC0000000   ;Desired Access
       ,"UInt", 3            ;Safe Mode
       ,"UInt", 0            ;Security Attributes
       ,"UInt", 3            ;Creation Disposition
       ,"UInt", 0            ;Flags And Attributes
       ,"UInt", 0            ;Template File
       ,"Cdecl Int")
  If (COM_FileHandle < 1)
  {
    MsgBox, There is a problem with Serial Port communication. `nFailed Dll CreateFile, COM_FileHandle=%COM_FileHandle% `nThe Script Will Now Exit.
    Exit
  }

  ;###### Set COM State ######
  ;Sets the COM Port number, baud rate,...
  SCS_Result := DllCall("SetCommState"
       ,"UInt", COM_FileHandle ;File Handle
       ,"UInt", &DCB)          ;Pointer to DCB structure
  If (SCS_Result <> 1)
  {
    MsgBox, There is a problem with Serial Port communication. `nFailed Dll SetCommState, SCS_Result=%SCS_Result% `nThe Script Will Now Exit.
    Close_COM(COM_FileHandle)
    Exit
  }

  ;###### Create the SetCommTimeouts Structure ######
  ReadIntervalTimeout        = 0xffffffff
  ReadTotalTimeoutMultiplier = 0x00000000
  ReadTotalTimeoutConstant   = 0x00000000
  WriteTotalTimeoutMultiplier= 0x00000000
  WriteTotalTimeoutConstant  = 0x00000000

  VarSetCapacity(Data, 20, 0) ; 5 * sizeof(DWORD)
  NumPut(ReadIntervalTimeout,         Data,  0, "UInt")
  NumPut(ReadTotalTimeoutMultiplier,  Data,  4, "UInt")
  NumPut(ReadTotalTimeoutConstant,    Data,  8, "UInt")
  NumPut(WriteTotalTimeoutMultiplier, Data, 12, "UInt")
  NumPut(WriteTotalTimeoutConstant,   Data, 16, "UInt")

  ;###### Set the COM Timeouts ######
  SCT_result := DllCall("SetCommTimeouts"
     ,"UInt", COM_FileHandle ;File Handle
     ,"UInt", &Data)         ;Pointer to the data structure
  If (SCT_result <> 1)
  {
    MsgBox, There is a problem with Serial Port communication. `nFailed Dll SetCommState, SCT_result=%SCT_result% `nThe Script Will Now Exit.
    Close_COM(COM_FileHandle)
    Exit
  }

  Return %COM_FileHandle%
}

;########################################################################
;###### Close COM Subroutine (Don't touch this routine) #################
;########################################################################
Close_COM(COM_FileHandle)
{
  ;###### Close the COM File ######
  CH_result := DllCall("CloseHandle", "UInt", COM_FileHandle)
  If (CH_result <> 1)
    MsgBox, Failed Dll CloseHandle CH_result=%CH_result%

  Return
}

;########################################################################
;###### Write to COM Subroutines (Don't touch this routine) #############
;########################################################################
Write_to_COM(Message)
{
  Global COM_FileHandle
  Global COM_Port

  SetFormat, Integer, DEC

  ;Parse the Message. Byte0 is the number of bytes in the array.
  StringSplit, Byte, Message, `,
  Data_Length := Byte0
  ;msgbox, Data_Length=%Data_Length% b1=%Byte1% b2=%Byte2% b3=%Byte3% b4=%Byte4%

  ;Set the Data buffer size, prefill with 0xFF.
  VarSetCapacity(Data, Byte0, 0xFF)

  ;Write the Message into the Data buffer
  i=1
  Loop %Byte0%
  {
    NumPut(Byte%i%, Data, (i-1) , "UChar")
    ;msgbox, %i%
    i++
  }
  ;msgbox, Data string=%Data%

  ;###### Write the data to the COM Port ######
  WF_Result := DllCall("WriteFile"
       ,"UInt" , COM_FileHandle ;File Handle
       ,"UInt" , &Data          ;Pointer to string to send
       ,"UInt" , Data_Length    ;Data Length
       ,"UInt*", Bytes_Sent     ;Returns pointer to num bytes sent
       ,"Int"  , "NULL")
  If (WF_Result <> 1 or Bytes_Sent <> Data_Length)
    MsgBox, Failed Dll WriteFile to %COM_Port%, result=%WF_Result% `nData Length=%Data_Length% `nBytes_Sent=%Bytes_Sent%
}

;########################################################################
;###### Read from COM Subroutines (Don't touch this routine) ############
;########################################################################
Read_from_COM(Num_Bytes)
{
  Global COM_FileHandle
  Global COM_Port
  Global Bytes_Received
  SetFormat, Integer, HEX

  ;Set the Data buffer size, prefill with 0x55 = ASCII character "U"
  ;VarSetCapacity won't assign anything less than 3 bytes. Meaning: If you
  ;  tell it you want 1 or 2 byte size variable it will give you 3.
  Data_Length  := VarSetCapacity(Data, Num_Bytes, 0x55)
  ;msgbox, Data_Length=%Data_Length%

  ;###### Read the data from the COM Port ######
  ;msgbox, COM_FileHandle=%COM_FileHandle% `nNum_Bytes=%Num_Bytes%
  Read_Result := DllCall("ReadFile"
       ,"UInt" , COM_FileHandle   ; hFile
       ,"Str"  , Data             ; lpBuffer
       ,"Int"  , Num_Bytes        ; nNumberOfBytesToRead
       ,"UInt*", Bytes_Received   ; lpNumberOfBytesReceived
       ,"Int"  , 0)               ; lpOverlapped
  ;MsgBox, Read_Result=%Read_Result% `nBR=%Bytes_Received% ,`nData=%Data%
  If (Read_Result <> 1)
  {
    MsgBox, There is a problem with Serial Port communication. `nFailed Dll ReadFile on %COM_Port%, result=%Read_Result% - The Script Will Now Exit.
    Close_COM(COM_FileHandle)
    Exit
  }

  i = 0
  Data_HEX =
  Loop %Bytes_Received%
  {
    ;First byte into the Rx FIFO ends up at position 0

    Data_HEX_Temp := NumGet(Data, i, "UChar") ;Convert to HEX byte-by-byte
    StringTrimLeft, Data_HEX_Temp, Data_HEX_Temp, 2 ;Remove the 0x (added by the above line) from the front

    ;If there is only 1 character then add the leading "0'
    Length := StrLen(Data_HEX_Temp)
    If (Length =1)
      Data_HEX_Temp = 0%Data_HEX_Temp%

    i++

    ;Put it all together
    Data_HEX := Data_HEX . Data_HEX_Temp
  }
  ;MsgBox, Read_Result=%Read_Result% `nBR=%Bytes_Received% ,`nData_HEX=%Data_HEX%

  SetFormat, Integer, DEC
  Data := Data_HEX

  Return Data

}

;########################################################################
;###### Convert ASCII TV Code into HEX and Adds CR at the End############
;########################################################################
TV_Code2Hex(Code)
{
  ASCII_DATA=%Code%
  Loop, 8
  {
    StringLeft, String_Chr, ASCII_DATA, 1
    StringTrimLeft, ASCII_DATA, ASCII_DATA, 1
    
    ASCII_Code:=Asc(String_Chr)
    HEX:=ToBase(ASCII_Code, "16")
  
    Complete=%Complete%0x%Hex%,

    If (ASCII_DATA="")
    {
      StringTrimRight, Complete, Complete,1
      Complete=%Complete%,0xD ; add CR at the END
      Break
    }
  }
 Return %Complete%
}

ToBase(n,b) { ; n >= 0, 1 < b <= 36
;http://www.autohotkey.com/forum/viewtopic.php?t=17350#109769
;by Laszlo
   Return (n < b ? "" : ToBase(n//b,b)) . ((d:=mod(n,b)) < 10 ? d : Chr(d+55))
}

(\__/) This is Bunny.
(='.'=) Cut, copy, and paste bunny onto your sig.
(")_(") Help Bunny gain World Domination.

twhyman
  • Members
  • 348 posts
  • Last active: Sep 17 2014 01:55 AM
  • Joined: 07 Dec 2005
Can anyone help?

It seems that aobrien the creator of the functions is MIA :D
(\__/) This is Bunny.
(='.'=) Cut, copy, and paste bunny onto your sig.
(")_(") Help Bunny gain World Domination.

quatermass
  • Members
  • 220 posts
  • Last active: Dec 16 2013 09:00 PM
  • Joined: 14 Dec 2005
Looks like we're on our own here... :shock:
Stuart Halliday

twhyman
  • Members
  • 348 posts
  • Last active: Sep 17 2014 01:55 AM
  • Joined: 07 Dec 2005
quatermass, do you have any problems with the function?
(\__/) This is Bunny.
(='.'=) Cut, copy, and paste bunny onto your sig.
(")_(") Help Bunny gain World Domination.

quatermass
  • Members
  • 220 posts
  • Last active: Dec 16 2013 09:00 PM
  • Joined: 14 Dec 2005
Yes, the Read function doesn't return any bytes.
Stuart Halliday

twhyman
  • Members
  • 348 posts
  • Last active: Sep 17 2014 01:55 AM
  • Joined: 07 Dec 2005
Whats kind of device are you connecting to?
(\__/) This is Bunny.
(='.'=) Cut, copy, and paste bunny onto your sig.
(")_(") Help Bunny gain World Domination.

quatermass
  • Members
  • 220 posts
  • Last active: Dec 16 2013 09:00 PM
  • Joined: 14 Dec 2005
A 56K modem built-in to the Laptop.

I tested it is working via HyperTerm and via the free Serial Port monitoring program.


I use <!-- m -->http://www.serial-port-monitor.com/<!-- m -->
Stuart Halliday

aobrien
  • Members
  • 77 posts
  • Last active: Mar 06 2014 04:42 AM
  • Joined: 14 Feb 2008
Hi twhyman,

Sorry that I have been non-responsive. I don't check my personal email on a regular basis... but I will always check (sooner or later) to see if people need help.

I think that I may have found your problem. First, I would like you to un comment line 55. This will tell you exactly what you are getting from Read_from_COM().
msgbox, Bytes_Received=%Bytes_Received%`nRead_Data=%Read_Data% ;Global variable that is set by Read_from_COM()

The problem is that the script is quite fast - much so compared to the serial port. What I think is happening is that you exit the infinite loop after you have received one batch of data... but that batch of data was received [via Read_from_COM()] before all of the data has been sent by the TV. I notice that you essentially set Quit_var = 1 whenever you enter the If (Bytes_Received > 0) block.

I think the best way to correct the problem is to keep track of the total number of bytes received and then exit only after you receive the correct number of bytes.

Also, I believe that most serial ports have a receive buffer. I don't know how big, but I suspect it is around 16 bytes. So you have to be careful not to let the buffer overflow or you will loose the data and never be able to get it back.

Good luck and let us know how it turns out :)
aobrien