Jump to content

Serial Port /COM Port UDF


martin
 Share

Recommended Posts

That's good. I'll try to update the dll in the next couple of days. Thanks for testing it.

There is no licence with my dll and udf. I make no claims about the fitness for purpose, I make no guarantees that it will even work. I don't guarantee to support it or correct any problems and anyone who uses them is taking a risk. However, it is my intention to support and develop it and I hope the history of this thread shows that.

I would like it if you

  • Acknowledge that I wrote it.
  • Don't make any changes without asking me to consider the change first.
  • Tell me of any problems that you think I might not be aware of.
  • Supply a link to my download or a link to this thread with the files if you distribute them.
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.
Link to comment
Share on other sites

  • 3 weeks later...

Hi all

is there any way to listen on 2 com ports in she same time? I want to listen 2 modems if any of them rings

You can have up to 50 ports open at the same time. Each port is associated with a channel number. By default the channel number is 1, so when you open a port that port is on channel 1. Note that the channel number is nothing to do with the port number unless to make it that way.

Top open another port you must use the _CommSwitch command to switch to another channel and then open whatever port you want. All communication is made with the channel last selected using the switch command.

To check what is happening on 2 ports or more you need something like the following pseudo code

for $n = 1 to $lastchannel

_CommSwitch($n)

$char = _CommReadChar()

If $char <> '' then do_something()

next

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.
Link to comment
Share on other sites

  • 4 weeks later...

Ok I'm a newb, I'm not understanding this... I need a weight scale to read to a GUI. The scale is on COM port (COM8, baud/speed 9600, mode n,8,1) Can someone please help me get this data to my GUI?

OMG, I do get it! Your example works great. I set the scale to send when the print button is pushed and now receive a reading from the scale and through string managment get my weight to send to database. I did have to add sleep(50) to retrieve a string. and I do still get an error when setting my port but doesn't seem to stop the data from being received.

Edited by Jaboowaki
Link to comment
Share on other sites

Figured I would ask while I am hunting. Is there a way with your _commsendstring to send an ALT+F2 (raw key codes / hex) to the device, this is necessary to enable the prompt for default reset. Thanks.

got it - can just send normally with the com open.

Is there a keen way to get VT100 menus to display correctly in the editbox?

Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

...

Is there a keen way to get VT100 menus to display correctly in the editbox?

Only with extra code. I don't know the VT100 protocol but I expect it is not very complicated though it might be quite lengthy. I would probably approach it something like this

$c = _CommReadChar
switch $c
  case chr(27)
      $c = _CommReadChar
      switch $c
         case '['
          etc
      endswitch
 Case Else
    Append($c, $Edit1)
EndSwitch
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.
Link to comment
Share on other sites

Thank you sir. As I was playing with all the cases I quickly realized it was easier to present the vt100 options as inputs on a GUI, and then _commsend the strings to navigate the menus (+ , - , etc...) and make the changes specified behind the scenes. Still some limitations, but my odds of getting that menu to display correctly are not of the betting variety.

Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

I can hardly get started.

I downloaded your zip file today and am trying to run the example. The set Port window reads the available ports OK but every time I hit the apply button I see a Setport error = window. The spot where I expect to see $sportSetError displayed is vacant.

The computer is running XP Pro, SP3, 32 bits.

Thank you for any help.

Link to comment
Share on other sites

just click ok. or comment out line 225. (unless it wasnt a blank message box and actually displaying an error code)

Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

Well it's the code which is pretty stupid. That line should have been something like

if $sportSetError <> '' then MsgBox(0,'Setport error = ',$sportSetError)

I'll change the example in the download.

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.
Link to comment
Share on other sites

dont know if this is just because of my settings but I had to adjust the commgetstring loop to prevent the window from flickering

$instr = ""
While 1

    $instr &=  _CommGetString()

    If $instr <> '' And $instr <> $Lastinstr Then;if we got something

        GUICtrlSetData($edit1,$instr)

    EndIf

$Lastinstr = $instr

WEnd

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

Hi boththose,

I don't like your code any more than I like my own! Every time $instr changes, maybe because just 1 character has been added, the whole of the text in the edit is replaced and I expect that's what is causing the flicker.

Maybe instead you could do something like this -

While 1
    $instr = _CommGetString()
    If $instr <> ''  Then; if we got something
        GUICtrlSetData($edit1, $instr,1); add the string to the text already in the edit
    EndIf
WEnd
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.
Link to comment
Share on other sites

that is perfect. Im glad it was at least understandable, making likeable scripts is still in the distance. The help file info on that last flag in GuiCtrlSetData is sketchy... am i seeing that 0 destroys and rewrites, whereas 1 appends to the end of the current string.

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

The help says that anything other than "" will append so I just put whatever I feel like at the time. I would expect that 0 would have the same effect as 1 but I haven't tried that.

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.
Link to comment
Share on other sites

fair enough, make that my reading comprehension that is sketchy.

that is my first encounter with: an empty string does one behavior, and all other strings do another, where the string itself has no bearing on the outcome.

Thanks for the OT.

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

  • 1 month later...

Hi Martin,

Can you please help me?

Brief explanantion I am using an Arduino that is set to look for <lamp on> text on its serial port, if it gets the correct text it pulses Pin13.

I am trying to use your commMG but having a problem, it seems to work on one PC but when I then try it on another PC it behaves differently.

Yet if I use a different Terminal program and send the text <lamp on> it will work on either PC, so I beleive its something to do with commMG ?

The code I am using in autoit is

;Include the Serial UDF
#include 'CommMG.au3'
;Internal for the Serial UDF
Global $sportSetError = ''
;COM Vars
Global $CMPort = 6   ; Port
Global $CmBoBaud = 9600   ; Baud
Global $CmboDataBits =  8  ; Data Bits
Global $CmBoParity = "none"  ; Parity
Global $CmBoStop = 1   ; Stop
Global $setflow = 2 ; Flow
;Start up communication with the Arduino
_CommSetPort($CMPort, $sportSetError, $CmBoBaud, $CmboDataBits, $CmBoParity, $CmBoStop, $setflow)

_CommSendstring("<lamp on>" )

Is there anything else I should be sending? I think somehow when the PC Boots up the Serial Port is in an unkown state and all commMG needs to do is reset it ?

Also if I use the other Term package that it does work with, then I come back to your commMG it works correctly? and it will stay working correctly until I reboot the PC and it will then not work?

Hope all this makes sense as I have been trying to work out whats wrong for 4 evenings now.

Regards

Gary

Link to comment
Share on other sites

Gary,

I'm sorry you're having this problem. Can you tell me what OS you have on the PC that is a problem and whether it's 32 or 64 bit?

Because I don't know the reason I will try to test on a similar OS.

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.
Link to comment
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
 Share

×
×
  • Create New...