AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Serial ( COM ) Port Console Script
Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8, 9  Next
 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
gwarble
Guest





PostPosted: Fri Apr 10, 2009 3:53 am    Post subject: use for CNC communications Reply with quote

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
Back to top
aobrien



Joined: 14 Feb 2008
Posts: 70
Location: Santa Clara, CA

PostPosted: Tue Apr 21, 2009 3:45 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
gwarble
Guest





PostPosted: Tue Apr 28, 2009 2:10 am    Post subject: Reply with quote

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
Back to top
OrelseIamfired



Joined: 13 Mar 2006
Posts: 65
Location: Ottawa, Canada

PostPosted: Thu Apr 30, 2009 4:35 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
OrelseIamfired



Joined: 13 Mar 2006
Posts: 65
Location: Ottawa, Canada

PostPosted: Mon May 04, 2009 5:19 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Rabiator



Joined: 17 Apr 2005
Posts: 289
Location: Sauerland

PostPosted: Mon May 04, 2009 8:26 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
OrelseIamfired



Joined: 13 Mar 2006
Posts: 65
Location: Ottawa, Canada

PostPosted: Mon May 04, 2009 9:20 pm    Post subject: Reply with quote

Hi Rabiator,

Thank you for clarifying this for me.

_/ Louis
Back to top
View user's profile Send private message
WankaUSR



Joined: 14 Aug 2007
Posts: 86

PostPosted: Mon Jun 22, 2009 11:32 am    Post subject: Reply with quote

can this script be used to read data from usb too?
Back to top
View user's profile Send private message Visit poster's website
wiseley



Joined: 22 Apr 2009
Posts: 29

PostPosted: Mon Jun 22, 2009 2:39 pm    Post subject: Reply with quote

no
Back to top
View user's profile Send private message
guest3
Guest





PostPosted: Thu Jul 02, 2009 1:23 pm    Post subject: Reply with quote

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.
Back to top
aobrien



Joined: 14 Feb 2008
Posts: 70
Location: Santa Clara, CA

PostPosted: Thu Jul 02, 2009 8:41 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
trenton_xavier



Joined: 16 Jun 2008
Posts: 82
Location: Pittsburgh, Pennsylvania, USA

PostPosted: Mon Aug 03, 2009 10:24 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message AIM Address
aobrien



Joined: 14 Feb 2008
Posts: 70
Location: Santa Clara, CA

PostPosted: Tue Aug 11, 2009 4:59 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Golericas
Guest





PostPosted: Tue Dec 15, 2009 2:28 pm    Post subject: Reply with quote

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? Very Happy

Thank you! --Golericas
Back to top
trenton_xavier



Joined: 16 Jun 2008
Posts: 82
Location: Pittsburgh, Pennsylvania, USA

PostPosted: Wed Dec 16, 2009 12:40 pm    Post subject: Reply with quote

@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...
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8, 9  Next
Page 5 of 9

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group