Jump to content

Serial Port /COM Port UDF


martin
 Share

Recommended Posts

Is there a COM1 on the motherboard? If so does my script work with that?

What is COM3? Is it on an expansion card or is it a USB to rs232 for example?

What is the script that gives the message "parameter incorrect..."?

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

Com 1 and 3 are integrated to the motherboard, the error was while using your example script and also with mine:

;Include the Serial UDF
#include 'CommMG.au3'
 
;Internal for the Serial UDF
Global $sportSetError = ''
 
;COM Vars
Global $CMPort = 7                ; 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 device
_CommSetPort($CMPort, $sportSetError, $CmBoBaud, $CmboDataBits, $CmBoParity, $CmBoStop, $setflow)

;Send Command

_CommSendstring("1",0)

Link to comment
Share on other sites

You said the error was using COM3 but your code shows COM7. Maybe that is not significant.

You have COM1,3 7 and maybe more. What COM ports do work?

I have never had the message "incorrect parameter.." and there is no such message in my example script,, udf or dll so I am lost at the moment. If you try to open a port which doesn't exist, say COM93, then the $sportError in your example will be "port does not exist".

When you run my example script the window title gives the dll version. What does it say?

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

Yeah sorry about that, I modified the code to test once more after changing the COM3 to COM7 under its properties to further investigate, currently COM1 and COM2 are used by the pc on other devices from Com4 and onward no devices exist there since I set the Sparkfun Pro Micro 5V/16MHz back to COM3, using the Arduino IDE the system uses and can configure the hardware through COM3, but is not responding while using your or my script, the dll shows V2.79.

Running your script to a non existing COM does gives me the "Port does not exist" message but while running mine I get the following error:

Can´t perform the operation on a closed port

port = COM93

channel number = 1

Link to comment
Share on other sites

I think I need to see the script you are using. I have W8, W7 and XP pcs I can try it on.

If you don't want to show it here you can pm me.

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

The code is exactly the one you can see in my comments above, the only thing that changes is the port used based on the pc I test, example: since the Sparkfun Pro Micro 5V/16MHz was detected as COM 9 in my win 7 pc it work fine when I set the COM port as COM9, when I test it in a xp pc the Sparkfun Pro Micro 5V/16MHz was installed on COM 3 so I change the code to use "3", when I tried in another xp pc it got installed on COM7 so I change the COM port to "7"and it did not work, literally my code is too simple I just need to send "1" over the COM port all the magic happens after the Sparkfun Pro Micro 5V/16MHz reads "1" in the COM port where is attached to.

;Include the Serial UDF
#include 'CommMG.au3'
 
;Internal for the Serial UDF
Global $sportSetError = ''
 
;COM Vars
Global $CMPort = 7                ; 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 device
_CommSetPort($CMPort, $sportSetError, $CmBoBaud, $CmboDataBits, $CmBoParity, $CmBoStop, $setflow)

;Send Command

_CommSendstring("1",0)

Link to comment
Share on other sites

You are using _CommSendString without checking that you have opened the port succesfully. I expect that the port isn't found or is already in use. Try using this which tells you the problem. You should always check the return value of functions becuase they tell you something. To have a problem and not check even then is just daft because it could tell you the answer quicker than anyone on any forum could do.

;Include the Serial UDF
#include 'CommMG.au3'

;Internal for the Serial UDF
Global $sportSetError = ''

;COM Vars
Global $CMPort = 19 ; 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 device
$OpenResult = _CommSetPort($CMPort, $sportSetError, $CmBoBaud, $CmboDataBits, $CmBoParity, $CmBoStop, $setflow)
If $OpenResult = 0 Then ;if the function failed we need to see why
    Switch @error
        Case 1
            ConsoleWrite('dll call failed' & @LF)
        Case 2
            ConsoleWrite('dll was not open and could not be opened' & @LF)
        Case -1
            ConsoleWrite('baud rate error' & @LF)
        Case -2
            ConsoleWrite('stop bit error' & @LF)
        Case -4
            ConsoleWrite('data bits error' & @LF)
        Case -8
            ConsoleWrite('Port = 0 not allowed' & @LF)
        Case -16
            ConsoleWrite('Port COM' & $CMPort & ' not found' & @LF)
        Case -32
            ConsoleWrite('Port access denied (in use?)' & @LF)
        Case -64
            ConsoleWrite('some error which I cannot explain!' & @LF)
    EndSwitch

    ;Send Command

Else
    _CommSendstring("1", 0)
EndIf
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

Thanks for the feedback, I know the CommSendString is not the best approach but I wanted to leave the possibility open in case I wanted to send more complex commands in the future and not to debug too much later.

I did check the return values but everything did look good to me, so I started to post here to get a better idea of things since I am still too green on Autoit to understand everything properly, I did tried with your test code and believe or not still got the same error.

The parameter is not correct

port = COM3

channel number = 1

I know that the port is working properly since I used it with another program to send the serial commands manually, but automating with Autoit on win XP  is the one to be seen tricky in here, since again on Win 7 everything works as expected.

Link to comment
Share on other sites

OK, I hadn't realized, or rather remembered, that send string could produce an error message like that.
I don't see what is wrong so can you try modifying what you send a bit.

Try _commsendstring('1' & @CR, 0)

And also try something like Sending 'aa' and see what happens.

The problem with sendstring crashing used to happen with a very early version of the DLL, so make sure the one you are using isn't many years out of date.

 

I've made a version of the dll which I'd like you to try. I don't know if it will make a difference but it might.commg.zip

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

There must be a reason but I don't know what it is. Many people have used the dll and udf. There have been 2,000 plus downloads so I assume a few hundred people have used it and I don't think I've had this problem except on one of the very earliest versions. Is there anything different about your installation? Is it a 64bit OS? What language?

Would it be an option for me to remotely access and control the PC which has the problem? I realize that is an extreme suggestion and it would be quite understandable if you didn't want that, but I thought I'd ask because I've run out of ideas.

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

I was thinking the same, that a remote access might help here, the problem is with a regular XP Pro so no 64 bits on that one, the computer is pretty much empty, only has Auto it and  lego nxt software, since its a pc currently used only for those 2 programs as a pseudo-developer test platform for my home experiments, since the heavy development and testing is done on a win 7 64 bit laptop. So let me know via private message so we can schedule

Link to comment
Share on other sites

  • 4 weeks later...

Hi Martin,

As I mentioned earlier I am using CommMG.au3 V2.90 to communicate with RFXtrx for controlling light switches. This works fine, but occasionally I get the error: Access denied getting ipcount. This error is given in a pop-up window with title: Autoit3 and an OK button. At this point program execution is interrupted. This message occurs at the use of: _CommReadByte(0). Is it possible not to give this error in a pop up window, but in the @ERROR status? In that case I can catch the error and restart the connection with RFXtrx.

Link to comment
Share on other sites

grashopper,

what version dll are you using? Version 2.81 removed those messages (or should have). If you are using an earlier version you can download the latest from the fiirst post in this thread.

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

For future reference the udf has a function _CommGetVersion to get the version of the dll or the version of the UDF depending on a parameter.

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...

serghei002,

if data is being received then it is shown in the edit box. If you want to stop the edit box showing what has been received then you could simply send the recieved data to a hidden edit and only copy lines to the shown edited when allowed.

There would be something different needed if you want to stop data being sent to you so if tat's what you want then you would need to play with the hardware handshaking lines.

25th Oct 2013 - Edited typos

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

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...