AutoHotkey Community

It is currently May 26th, 2012, 5:34 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 121 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6, 7, 8, 9  Next
Author Message
PostPosted: April 10th, 2009, 4:53 am 
Hey

thanks for a great script aobrien

Is anyone using this to transfer data files reliably? as in 0% dropped characters/extra characters? I'm interested in using it for CNC machine program transfer, but can't risk a single character misplaced. In tests it seems good, but I need a more thorough file compare method i fear...

also, is simultaneous communication over two com ports possible?

thanks aobrien and all
- joel


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 21st, 2009, 4:45 am 
Offline

Joined: February 14th, 2008, 10:07 pm
Posts: 72
Location: Santa Clara, CA
Hi Joel,

I'm glad that you like the script.

Well, I am currently using a modified version of the COM subroutines [modified to receive the COM specific filehandle] to simultaneously control 5 different serial ports.

I have had some good luck and bad luck with serial port reliability. The system that I am working with at the moment seems to eat characters off of the end of the string being sent. Other systems work flawlessly.

One idea to test the integrity of the path is to set up a loop and just cycle a file between PCs "n" number of times and then when it is finished check that it has been unmodified. Also, I would build some sort of checksum into the file transfer so that you could be very confident that the file is identical to the original.

aobrien


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 28th, 2009, 3:10 am 
Thanks aobrien,

I have also had some success accessing multiple com ports, but haven't really pursued it much farther after also losing a couple leading and ending characters and getting worried.

I was never able to get it to replicate the problem reliably, but i like your idea of sending the same file back and forth n times and then checking it. I like to do the testing on the actual machines, but I'll probably set up the script to loop read/send, and then at the machine i can read/send/delete/read... manually a dozen or so times and see what happens...

a checksum would be difficult to handle with the limited processing capabilities on the machine controls (as far as a permanant solution) but on some of the newer machines might be possible...

thanks again

- joel


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 30th, 2009, 5:35 pm 
Offline

Joined: March 13th, 2006, 3:55 pm
Posts: 65
Location: Ottawa, Canada
Hi aobrien (or other AHK experts),

I tried your marvellous COM script, and I noticed something weird about the processing of Space characters; they do not get printed in Notepad. Look at the 'COM port receive' loop.

Code:
;########################################################################
;###### Serial Port Receive #############################################
;########################################################################
...
;COM port receive loop
Loop
{
...
        ASCII_Chr := Chr(Byte)
        ASCII = %ASCII%%ASCII_Chr%


If ASCII_Chr is a space, then nothing is appended to ASCII

If I use := instead of =, then the space is appended.

Code:
ASCII := ASCII ASCII_Chr

Does anyone else observe this?
_/ Louis


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 4th, 2009, 6:19 pm 
Offline

Joined: March 13th, 2006, 3:55 pm
Posts: 65
Location: Ottawa, Canada
To facilitate observing the 'disappearing space' character, I paste a test script here for someone to try.
Code:
;Initialise some variables.
ASCII =
ASCII2 =
ASCII_Chr := A_Space

; Append a space to the test variables using = and :=.
ASCII = %ASCII%%ASCII_Chr%
ASCII2 := ASCII2 ASCII_Chr

; Display the result.
; ASCII has nothing between the parentheses,
; whereas one can see the space in ASCII2.
MsgBox, ASCII is (%ASCII%)
. `nASCII2 is (%ASCII2%).
Exit

Would anyone know if this behaviour is by design?
_/ Louis


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 4th, 2009, 9:26 pm 
Offline

Joined: April 17th, 2005, 7:47 pm
Posts: 289
Location: Sauerland
OrelseIamfired wrote:
Would anyone know if this behaviour is by design?
It is. You have to set AutoTrim, Off. By default it is On.
Code:
AutoTrim, Off


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 4th, 2009, 10:20 pm 
Offline

Joined: March 13th, 2006, 3:55 pm
Posts: 65
Location: Ottawa, Canada
Hi Rabiator,

Thank you for clarifying this for me.

_/ Louis


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 22nd, 2009, 12:32 pm 
Offline

Joined: August 14th, 2007, 12:11 pm
Posts: 86
can this script be used to read data from usb too?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 22nd, 2009, 3:39 pm 
Offline

Joined: April 22nd, 2009, 6:04 am
Posts: 29
no


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 2nd, 2009, 2:23 pm 
Has anyone solved the problem of using a usb-serial adapter and higher com port? aobrien mentions about a "BuildCommDCB" error, which i've gotten. I know the fix; remapping the port to a lower number. It'd just be easier if you didn't have to do this.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 2nd, 2009, 9:41 pm 
Offline

Joined: February 14th, 2008, 10:07 pm
Posts: 72
Location: Santa Clara, CA
hi guest3,

I ran into that same problem again (not being able to use USB-Serial adaptors on COM10+) and still haven't found the solution. Sorry.

It is starting to become a biger problem for me because I now have 10 serial ports connected to my test PC. I have to reconfigure the ports depending on the type of test I want to run... serious PITA.

WankaUSR, USB? As in a USB flash drive? I wish! I don't know anything about probramming a USB driver, however, I suspect that it is about 1000 times more complex than this little script. You can, however, use USB-Serial adaptors... I use them all the time as long as the COM port number is 9 or less.

aobrien


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 3rd, 2009, 11:24 pm 
Offline

Joined: June 16th, 2008, 12:26 pm
Posts: 82
Location: Pittsburgh, Pennsylvania, USA
I solved the problem of the using USB-to-Serial adapters on COM10 and up.

The following instructions are modifying the original code from the second post(the one NOT using Port.dll).
I'm pretty sure this is the one that most ppl are using.

First, remove the COM_Port reference from the Script Variables section.

Code:
;########################################################################
;###### Script Variables ################################################
;########################################################################
COM_Settings = %COM_Port%:baud=%COM_Baud% parity=%COM_Parity% data=%COM_Data% stop=%COM_Stop% dtr=Off
to
Code:
;########################################################################
;###### Script Variables ################################################
;########################################################################
COM_Settings = baud=%COM_Baud% parity=%COM_Parity% data=%COM_Data% stop=%COM_Stop% dtr=Off



After reading through topics on MSDN, the COM port does not need to initialized in the BuildCommDCB; just in CreateFile. AFAIK, this is were the hold up was for aobrein and myself.


Next, I modified the Initialize_COM function as follows:
Code:
Initialize_COM(COM_Settings)
{
  Global COM_FileHandle
  Global COM_Port        ; <----Add this


Remove krisky68's format area:
Code:
  ;###### 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%
and replace with
Code:
  ;###### Format COM Port Number if necessary ######
  if (StrLen(COM_PORT) > 4)
   COM_Port_MOD := "\\.\" . COM_Port
  else
   COM_Port_MOD := COM_Port
  ;MsgBox, COM_Port=%COM_Port_MOD%



And then, under the Create COM File section, change:
Code:
      ,"Str" , COM_Port     ;File Name
to
Code:
       ,"Str" , COM_Port_MOD ;File Name



Removing krisky68 code was needed because the COM port no longer exists in COM_Settings. This is also why COM_Port was made global.

@aobrien:
hope this works for you too

ps. i was guest3 in the previous post


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 11th, 2009, 5:59 pm 
Offline

Joined: February 14th, 2008, 10:07 pm
Posts: 72
Location: Santa Clara, CA
AWESOME! trenton_xavier, you da'man!!!

I just tried your suggestion of removing the com# from the BuildCommDll DLL call and it allowed one of my USB-Serial adaptors to work at COM18. I tried again with the old code and it gave me "Failed Dll BuildCommDCB" error.

I didn't implement the change exactly as you suggested. I was able to implement your fix by moving krisky68's code up and adding only more one line of code to Initialize_COM().

Excellent work! Thanks so much!
aobrien


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 15th, 2009, 3:28 pm 
Hi, thank you for the great forum. I have a concept I would like to introduce, and wondering if any guru(s) know how to work this,

I have an application which binds to a COM port #. But, I would like to see the datastream. The way it is going so far, I am basically locked out from doing anything with the port while it is active.

Is this a no-win situation, or any ideas how I can make it work? :D

Thank you! --Golericas


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 16th, 2009, 1:40 pm 
Offline

Joined: June 16th, 2008, 12:26 pm
Posts: 82
Location: Pittsburgh, Pennsylvania, USA
@Golericas

I've been trying to do this as well and have been unable to(in AHK). It is possible and I use a program called PortMon from Sysinternals. It's free and works great. The trick to using it is to open PortMon and connect to the com port first, then open the program you want to 'snoop' on. If you try and connect after, it will lock you out.

PortMon @ Sysinternals: http://technet.microsoft.com/en-us/sysinternals/bb896644.aspx

Maybe [aobrien] will have some input...


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 121 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6, 7, 8, 9  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google Feedfetcher, XX0, Yahoo [Bot] and 14 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group